{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "approval-chain-pick-list",
  "title": "Approval Chain Pick List",
  "description": "An ordered approver picker that leaves the requester out, needs at least one approver and numbers the steps. Use this when an approval workflow depends on who signs, and in what order.",
  "registryDependencies": [
    "@tealmac/pick-list",
    "@tealmac/transfer-list"
  ],
  "files": [
    {
      "path": "registry/patterns/approval-chain-pick-list/approval-chain-pick-list.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { PickList } from \"@/components/ui/pick-list\"\nimport type { TransferItem } from \"@/components/ui/transfer-list\"\n\nexport interface ApprovalChainPickListProps {\n  people: TransferItem[]\n  /** The person asking. They cannot approve their own request. */\n  requesterId: string\n  /** The most steps allowed. */\n  maxSteps?: number\n  value?: string[]\n  defaultValue?: string[]\n  onValueChange?: (ids: string[]) => void\n}\n\n/**\n * Order is the point: the first person approves first. The requester is shown\n * but disabled, so nobody wonders where they went. A line under the list says\n * whether the chain is valid, and it is the same text a screen reader hears\n * when it changes.\n */\nexport function ApprovalChainPickList({\n  people,\n  requesterId,\n  maxSteps = 4,\n  value,\n  defaultValue = [],\n  onValueChange,\n}: ApprovalChainPickListProps) {\n  const [inner, setInner] = React.useState(defaultValue)\n  const chain = value ?? inner\n  const items = React.useMemo(\n    () =>\n      people.map((p) =>\n        p.id === requesterId\n          ? { ...p, disabled: true, description: \"Requester\" }\n          : p\n      ),\n    [people, requesterId]\n  )\n  const names = chain.map((id) => people.find((p) => p.id === id)?.label ?? id)\n  const status =\n    chain.length === 0\n      ? \"Add at least one approver.\"\n      : chain.length > maxSteps\n        ? `Too many steps: the limit is ${maxSteps}.`\n        : `${names.join(\" then \")}.`\n  const invalid = chain.length === 0 || chain.length > maxSteps\n  return (\n    <div className=\"flex w-full flex-col gap-2\">\n      <PickList\n        aria-label=\"Approvers\"\n        items={items}\n        titles={[\"People\", \"Approves in this order\"]}\n        value={chain}\n        onValueChange={(next) => {\n          if (value === undefined) setInner(next)\n          onValueChange?.(next)\n        }}\n        searchable\n      />\n      <p\n        className={\n          invalid ? \"text-destructive text-sm\" : \"text-muted-foreground text-sm\"\n        }\n        role={invalid ? \"alert\" : \"status\"}\n        aria-live=\"polite\"\n      >\n        {status}\n      </p>\n    </div>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}