{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bulk-actions-01",
  "title": "Bulk Actions",
  "description": "An issue list with row checkboxes whose delete asks for more as the count grows: an undo window for one or two, a second click for a few, and the typed count for more.",
  "registryDependencies": [
    "@sureui/confirm-button",
    "@sureui/confirm-dialog",
    "button",
    "card",
    "checkbox"
  ],
  "files": [
    {
      "path": "components/blocks/bulk-actions-01/bulk-actions.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { Button } from \"@/components/ui/button\"\nimport { Card, CardContent, CardHeader, CardTitle } from \"@/components/ui/card\"\nimport { Checkbox } from \"@/components/ui/checkbox\"\nimport { ConfirmButton } from \"@/components/ui/sureui/confirm-button\"\nimport { ConfirmDialog } from \"@/components/ui/sureui/confirm-dialog\"\n\ntype Issue = {\n  id: string\n  key: string\n  title: string\n  status: \"Todo\" | \"In progress\" | \"Backlog\"\n}\n\ntype BulkActionsProps = {\n  initialIssues?: Issue[]\n  undoLimit?: number\n  typeLimit?: number\n  className?: string\n}\n\nconst sampleIssues: Issue[] = [\n  {\n    id: \"iss_1\",\n    key: \"ENG-412\",\n    title: \"Login form loses focus\",\n    status: \"Todo\",\n  },\n  {\n    id: \"iss_2\",\n    key: \"ENG-409\",\n    title: \"Retry failed webhook deliveries\",\n    status: \"In progress\",\n  },\n  {\n    id: \"iss_3\",\n    key: \"ENG-405\",\n    title: \"Dark mode chart colors\",\n    status: \"Todo\",\n  },\n  {\n    id: \"iss_4\",\n    key: \"ENG-398\",\n    title: \"Flaky checkout test on CI\",\n    status: \"Backlog\",\n  },\n  {\n    id: \"iss_5\",\n    key: \"ENG-391\",\n    title: \"Export invoices as CSV\",\n    status: \"Backlog\",\n  },\n  {\n    id: \"iss_6\",\n    key: \"ENG-387\",\n    title: \"Rename workspace from settings\",\n    status: \"Todo\",\n  },\n  {\n    id: \"iss_7\",\n    key: \"ENG-380\",\n    title: \"Slow search on large projects\",\n    status: \"In progress\",\n  },\n  {\n    id: \"iss_8\",\n    key: \"ENG-374\",\n    title: \"Empty state for new teams\",\n    status: \"Backlog\",\n  },\n]\n\nfunction issues(count: number) {\n  return `${count} ${count === 1 ? \"issue\" : \"issues\"}`\n}\n\nfunction isIdle(button: HTMLElement) {\n  return button.getAttribute(\"data-state\") === \"idle\"\n}\n\nfunction request() {\n  return Promise.resolve()\n}\n\nfunction BulkActions({\n  initialIssues = sampleIssues,\n  undoLimit = 2,\n  typeLimit = 5,\n  className,\n}: BulkActionsProps) {\n  const [rows, setRows] = React.useState(initialIssues)\n  const [selected, setSelected] = React.useState<string[]>([])\n  const [deleting, setDeleting] = React.useState(false)\n\n  const count = selected.length\n  const allSelected = rows.length > 0 && selected.length === rows.length\n  const shown = deleting\n    ? rows.filter((row) => !selected.includes(row.id))\n    : rows\n  const label = `Delete ${issues(count)}`\n\n  function toggle(id: string, on: boolean) {\n    setSelected((prev) =>\n      on ? [...prev, id] : prev.filter((other) => other !== id)\n    )\n  }\n\n  async function remove() {\n    await request()\n    setRows((prev) => prev.filter((row) => !selected.includes(row.id)))\n    setDeleting(false)\n    setSelected([])\n  }\n\n  let action: React.ReactNode\n  if (count <= undoLimit) {\n    action = (\n      <ConfirmButton\n        key=\"undo\"\n        undo\n        variant=\"destructive\"\n        size=\"sm\"\n        onClick={(event) => {\n          if (isIdle(event.currentTarget)) setDeleting(true)\n        }}\n        onCancel={() => setDeleting(false)}\n        onConfirm={remove}\n      >\n        {label}\n      </ConfirmButton>\n    )\n  } else if (count <= typeLimit) {\n    action = (\n      <ConfirmButton\n        key=\"click-again\"\n        gesture=\"click-again\"\n        variant=\"destructive\"\n        size=\"sm\"\n        confirmLabel=\"Click again\"\n        onConfirm={remove}\n      >\n        {label}\n      </ConfirmButton>\n    )\n  } else {\n    action = (\n      <ConfirmDialog\n        key=\"type\"\n        title={`Delete ${issues(count)}?`}\n        description=\"This deletes the selected issues. It can't be undone.\"\n        phrase={String(count)}\n        confirmLabel={label}\n        variant=\"destructive\"\n        onConfirm={remove}\n      >\n        <Button variant=\"destructive\" size=\"sm\">\n          {label}\n        </Button>\n      </ConfirmDialog>\n    )\n  }\n\n  return (\n    <Card className={cn(\"@container/issues w-full\", className)}>\n      <CardHeader>\n        <CardTitle>Open issues</CardTitle>\n      </CardHeader>\n      <CardContent className=\"grid gap-3\">\n        <div className=\"flex min-h-8 flex-wrap items-center gap-x-3 gap-y-2\">\n          <label className=\"flex items-center gap-3 text-muted-foreground\">\n            <Checkbox\n              checked={allSelected && !deleting}\n              indeterminate={selected.length > 0 && !allSelected && !deleting}\n              disabled={rows.length === 0 || deleting}\n              onCheckedChange={(on) =>\n                setSelected(on ? rows.map((row) => row.id) : [])\n              }\n            />\n            <span aria-live=\"polite\">\n              {deleting\n                ? `Deleted ${issues(count)}`\n                : count > 0\n                  ? `${count} selected`\n                  : \"Select all\"}\n            </span>\n          </label>\n          {count > 0 && (\n            <div className=\"ml-auto flex items-center gap-2\">\n              {!deleting && (\n                <Button\n                  variant=\"ghost\"\n                  size=\"sm\"\n                  onClick={() => setSelected([])}\n                >\n                  Clear\n                </Button>\n              )}\n              {action}\n            </div>\n          )}\n        </div>\n        {shown.length === 0 ? (\n          <p className=\"border-t pt-3 text-muted-foreground\">No open issues</p>\n        ) : (\n          <ul aria-label=\"Issues\" className=\"divide-y border-t\">\n            {shown.map((row) => (\n              <li key={row.id}>\n                <label className=\"flex items-center gap-3 py-2.5\">\n                  <Checkbox\n                    checked={selected.includes(row.id)}\n                    disabled={deleting}\n                    onCheckedChange={(on) => toggle(row.id, on)}\n                  />\n                  <span className=\"hidden w-16 shrink-0 font-mono text-xs text-muted-foreground @sm/issues:inline\">\n                    {row.key}\n                  </span>\n                  <span className=\"min-w-0 flex-1 truncate\">{row.title}</span>\n                  <span className=\"hidden shrink-0 text-muted-foreground @md/issues:inline\">\n                    {row.status}\n                  </span>\n                </label>\n              </li>\n            ))}\n          </ul>\n        )}\n      </CardContent>\n    </Card>\n  )\n}\n\nexport { BulkActions, type BulkActionsProps, type Issue }\n",
      "type": "registry:component",
      "target": "@components/bulk-actions.tsx"
    }
  ],
  "categories": [
    "block",
    "tables"
  ],
  "type": "registry:block"
}