{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "template-sections-picker",
  "title": "Template Sections Picker",
  "description": "A pick list for the sections of a document template where required sections cannot be removed, with a numbered preview of the result. Use this when users assemble a report or contract from standard sections.",
  "registryDependencies": [
    "@tealmac/pick-list",
    "@tealmac/transfer-list"
  ],
  "files": [
    {
      "path": "registry/patterns/template-sections-picker/template-sections-picker.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 TemplateSectionsPickerProps {\n  /** Sections that can be used. Required ones carry `disabled: true`. */\n  sections: TransferItem[]\n  value?: string[]\n  defaultValue?: string[]\n  onValueChange?: (ids: string[]) => void\n}\n\n/**\n * Required sections start in the document and are disabled in the list, so\n * they cannot be moved back; the others are free to add, remove and reorder\n * around them. The preview is the outline of the document that will be made,\n * with a \"(required)\" note in text.\n */\nexport function TemplateSectionsPicker({\n  sections,\n  value,\n  defaultValue,\n  onValueChange,\n}: TemplateSectionsPickerProps) {\n  const required = React.useMemo(\n    () => sections.filter((s) => s.disabled).map((s) => s.id),\n    [sections]\n  )\n  const [inner, setInner] = React.useState(defaultValue ?? required)\n  const chosen = value ?? inner\n  const byId = new Map(sections.map((s) => [s.id, s]))\n  const set = (ids: string[]) => {\n    const withRequired = [...ids, ...required.filter((r) => !ids.includes(r))]\n    if (value === undefined) setInner(withRequired)\n    onValueChange?.(withRequired)\n  }\n  return (\n    <div className=\"grid w-full gap-4 lg:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]\">\n      <PickList\n        aria-label=\"Template sections\"\n        items={sections.map((s) =>\n          s.disabled ? { ...s, description: \"Required\" } : s\n        )}\n        titles={[\"Sections\", \"In the document\"]}\n        value={chosen}\n        onValueChange={set}\n      />\n      <section aria-labelledby=\"tsp-preview\" className=\"min-w-0\">\n        <h3 id=\"tsp-preview\" className=\"mb-1.5 text-sm font-semibold\">\n          Document outline\n        </h3>\n        {chosen.length > 0 ? (\n          <ol className=\"list-decimal space-y-1 rounded-md border py-3 ps-8 pe-3 text-sm\">\n            {chosen.map((id) => (\n              <li key={id}>\n                {byId.get(id)?.label ?? id}\n                {byId.get(id)?.disabled ? (\n                  <span className=\"text-muted-foreground\"> (required)</span>\n                ) : null}\n              </li>\n            ))}\n          </ol>\n        ) : (\n          <p className=\"text-muted-foreground rounded-md border px-3 py-6 text-center text-sm\">\n            No sections yet.\n          </p>\n        )}\n      </section>\n    </div>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}