{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "openlmis-facility-types-page",
  "title": "Facility Types Page",
  "description": "Mock facility type administration with responsive columns, sorting, paging and create/edit forms.",
  "dependencies": [
    "@tanstack/react-form@^1",
    "@tanstack/react-table@^9",
    "lucide-react@^1",
    "zod@^4",
    "@base-ui/react@^1"
  ],
  "registryDependencies": [
    "button",
    "dropdown-menu",
    "field",
    "https://registry.soldevelo.com/r/openlmis-callout.json",
    "https://registry.soldevelo.com/r/openlmis-column-view-options.json",
    "https://registry.soldevelo.com/r/openlmis-data-table.json",
    "https://registry.soldevelo.com/r/openlmis-form-dialog.json",
    "https://registry.soldevelo.com/r/openlmis-form-fields.json",
    "https://registry.soldevelo.com/r/openlmis-list-toolbar.json",
    "https://registry.soldevelo.com/r/openlmis-status-badge.json",
    "https://registry.soldevelo.com/r/openlmis-workspace.json"
  ],
  "files": [
    {
      "path": "registry/templates/openlmis/facility-types-page/components/facility-type-columns.tsx",
      "content": "\"use client\"\n\nimport { createColumnHelper } from \"@tanstack/react-table\"\nimport { EllipsisIcon, PencilIcon } from \"lucide-react\"\n\nimport { Button } from \"@/components/ui/button\"\nimport {\n  DropdownMenu,\n  DropdownMenuContent,\n  DropdownMenuGroup,\n  DropdownMenuItem,\n  DropdownMenuTrigger,\n} from \"@/components/ui/dropdown-menu\"\nimport {\n  DataTableColumnHeader,\n  type DataTableFeatures,\n} from \"@/components/blocks/openlmis/data-table/data-table\"\nimport { useMenuOpensDialog } from \"@/components/blocks/openlmis/data-table/row-actions\"\nimport type { ResponsiveColumn } from \"@/components/blocks/openlmis/data-table/responsive-columns\"\nimport { StatusBadge } from \"@/components/openlmis/status-badge\"\n\nimport type { FacilityType } from \"@/components/openlmis/facility-types-page/facility-type-form\"\n\n/** The columns the View menu lists; code and name are left out, so they always show. */\nexport const FACILITY_TYPE_HIDEABLE_COLUMNS: (ResponsiveColumn & {\n  label: string\n})[] = [\n  { id: \"displayOrder\", label: \"Display Order\", hideBelow: \"lg\" },\n  { id: \"active\", label: \"Status\", hideBelow: \"md\" },\n]\n\nexport const FACILITY_TYPE_SORT_FIELDS = [\n  \"displayOrder\",\n  \"code\",\n  \"name\",\n  \"active\",\n] as const\n\nexport type FacilityTypeSortField = (typeof FACILITY_TYPE_SORT_FIELDS)[number]\n\nconst columnHelper = createColumnHelper<DataTableFeatures, FacilityType>()\n\nexport function createFacilityTypeColumns(onEdit: (id: string) => void) {\n  return columnHelper.columns([\n    columnHelper.accessor(\"code\", {\n      header: ({ column }) => (\n        <DataTableColumnHeader column={column} title=\"Code\" />\n      ),\n      cell: ({ getValue }) => (\n        <span className=\"flex\">\n          <span className=\"min-w-0 truncate font-medium\" dir=\"ltr\">\n            {getValue()}\n          </span>\n        </span>\n      ),\n      meta: { className: \"@xl/table:w-1/3\" },\n    }),\n    columnHelper.accessor(\"name\", {\n      header: ({ column }) => (\n        <DataTableColumnHeader column={column} title=\"Name\" />\n      ),\n      cell: ({ getValue }) =>\n        getValue() ? (\n          <span className=\"flex\">\n            <span className=\"min-w-0 truncate\" dir=\"auto\">\n              {getValue()}\n            </span>\n          </span>\n        ) : (\n          <span className=\"text-muted-foreground\">-</span>\n        ),\n    }),\n    columnHelper.accessor(\"displayOrder\", {\n      header: ({ column }) => (\n        <DataTableColumnHeader column={column} title=\"Display Order\" />\n      ),\n      cell: ({ getValue }) => (\n        <span className=\"tabular-nums\">{getValue() ?? \"-\"}</span>\n      ),\n      meta: { className: \"w-40\" },\n    }),\n    columnHelper.accessor(\"active\", {\n      header: ({ column }) => (\n        <DataTableColumnHeader column={column} title=\"Status\" />\n      ),\n      cell: ({ getValue }) =>\n        getValue() ? (\n          <StatusBadge tone=\"success\">Active</StatusBadge>\n        ) : (\n          <StatusBadge tone=\"destructive\">Inactive</StatusBadge>\n        ),\n      meta: { className: \"w-32\" },\n    }),\n    columnHelper.display({\n      id: \"actions\",\n      header: () => <span className=\"sr-only\">Actions</span>,\n      cell: ({ row }) => (\n        <FacilityTypeActions onEdit={onEdit} type={row.original} />\n      ),\n      meta: { className: \"w-16\" },\n    }),\n  ])\n}\n\nfunction FacilityTypeActions({\n  type,\n  onEdit,\n}: {\n  type: FacilityType\n  onEdit: (id: string) => void\n}) {\n  const menu = useMenuOpensDialog()\n\n  return (\n    <div className=\"flex justify-end\">\n      <DropdownMenu onOpenChange={menu.onOpenChange}>\n        <DropdownMenuTrigger\n          render={\n            <Button\n              aria-label={`Actions For ${type.name || type.code}`}\n              size=\"icon-sm\"\n              variant=\"ghost\"\n            />\n          }\n        >\n          <EllipsisIcon />\n        </DropdownMenuTrigger>\n        <DropdownMenuContent\n          align=\"end\"\n          className=\"w-auto\"\n          finalFocus={menu.finalFocus}\n        >\n          <DropdownMenuGroup>\n            <DropdownMenuItem onClick={menu.opensDialog(() => onEdit(type.id))}>\n              <PencilIcon />\n              Edit\n            </DropdownMenuItem>\n          </DropdownMenuGroup>\n        </DropdownMenuContent>\n      </DropdownMenu>\n    </div>\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/facility-types-page/facility-type-columns.tsx"
    },
    {
      "path": "registry/templates/openlmis/facility-types-page/components/facility-type-form-dialog/facility-type-form-dialog.tsx",
      "content": "\"use client\"\n\nimport { revalidateLogic } from \"@tanstack/react-form\"\nimport { type ReactNode, useEffect, useMemo, useRef } from \"react\"\n\nimport { FieldGroup } from \"@/components/ui/field\"\nimport {\n  FormDialog,\n  FormDialogBody,\n  FormDialogCancel,\n  FormDialogDescription,\n  FormDialogError,\n  FormDialogFooter,\n  FormDialogForm,\n  FormDialogHeader,\n  FormDialogLoadError,\n  FormDialogSubmit,\n  FormDialogTitle,\n} from \"@/components/openlmis/form-dialog/form-dialog\"\nimport { useDialogTarget } from \"@/components/openlmis/form-dialog/use-dialog-target\"\nimport { useAppForm } from \"@/components/openlmis/form-fields/form\"\nimport {\n  FieldSkeleton,\n  SkeletonLine,\n} from \"@/components/openlmis/form-fields/form-fields\"\n\nimport {\n  EMPTY_FACILITY_TYPE_FORM,\n  type FacilityType,\n  type FacilityTypeFormValues,\n  facilityTypeFormSchema,\n  type TakenFacilityType,\n  toFacilityTypeFormValues,\n} from \"@/components/openlmis/facility-types-page/facility-type-form\"\n\nconst NO_TYPES: readonly TakenFacilityType[] = []\n\n/** `new` to create a facility type, or the id of the type to edit. */\nexport type FacilityTypeFormDialogTarget = \"new\" | (string & {})\n\ntype FacilityTypeFormDialogProps = {\n  /** Opens the dialog while set. */\n  target: FacilityTypeFormDialogTarget | undefined\n  /** The type being edited; a skeleton shows until it is set. */\n  type?: FacilityType | undefined\n  /** Every type, so a code or name already taken is refused; add any the server refused. */\n  types?: readonly TakenFacilityType[]\n  /** The type to edit no longer exists. */\n  notFound?: boolean\n  /** Loading the type failed; shows the error with Try Again. */\n  onRetry?: (() => void) | undefined\n  /** Called with the values; save them, then clear `target` to close. */\n  onSubmit: (\n    values: FacilityTypeFormValues,\n    type: FacilityType | undefined\n  ) => void\n  /** Keeps the dialog open and shows a spinner while the type is saved. */\n  pending?: boolean\n  /** Shown above the fields, e.g. why the save failed. */\n  error?: ReactNode\n  onClose: () => void\n}\n\nexport function FacilityTypeFormDialog({\n  target,\n  type,\n  types = NO_TYPES,\n  notFound = false,\n  onRetry,\n  onSubmit,\n  pending = false,\n  error,\n  onClose,\n}: FacilityTypeFormDialogProps) {\n  const { shown, dialogProps } = useDialogTarget(target, onClose)\n  const isNew = shown === \"new\"\n  const title = isNew ? \"Create Facility Type\" : \"Edit Facility Type\"\n  const submitLabel = isNew ? \"Create\" : \"Save\"\n\n  return (\n    <FormDialog {...dialogProps(pending)}>\n      {shown &&\n        (isNew ? (\n          <FacilityTypeForm\n            error={error}\n            key=\"new\"\n            onSubmit={onSubmit}\n            pending={pending}\n            types={types}\n          />\n        ) : notFound ? (\n          <>\n            <FormDialogHeader>\n              <FormDialogTitle>{title}</FormDialogTitle>\n              <FormDialogDescription>\n                This facility type no longer exists.\n              </FormDialogDescription>\n            </FormDialogHeader>\n            <FormDialogFooter>\n              <FormDialogCancel>Close</FormDialogCancel>\n            </FormDialogFooter>\n          </>\n        ) : onRetry ? (\n          <FormDialogLoadError\n            errorTitle=\"Could Not Load Facility Type\"\n            onRetry={onRetry}\n            title={title}\n          />\n        ) : type === undefined ? (\n          <FacilityTypeFormSkeleton submitLabel={submitLabel} title={title} />\n        ) : (\n          <FacilityTypeForm\n            error={error}\n            // Keyed, so opening another type starts a fresh form.\n            key={type.id}\n            onSubmit={onSubmit}\n            pending={pending}\n            type={type}\n            types={types}\n          />\n        ))}\n    </FormDialog>\n  )\n}\n\ntype FacilityTypeFormProps = Pick<\n  FacilityTypeFormDialogProps,\n  \"type\" | \"onSubmit\" | \"error\"\n> & {\n  types: readonly TakenFacilityType[]\n  pending: boolean\n}\n\nfunction FacilityTypeForm({\n  type,\n  types,\n  onSubmit,\n  pending,\n  error,\n}: FacilityTypeFormProps) {\n  // Keyed on the values themselves, so an equal array passed inline does not rebuild or re-check.\n  const typesKey = JSON.stringify(types)\n  const editingId = type?.id\n  const schema = useMemo(\n    () =>\n      facilityTypeFormSchema(\n        JSON.parse(typesKey) as TakenFacilityType[],\n        editingId\n      ),\n    [typesKey, editingId]\n  )\n  const checkedKey = useRef(typesKey)\n\n  const form = useAppForm({\n    defaultValues: type\n      ? toFacilityTypeFormValues(type)\n      : EMPTY_FACILITY_TYPE_FORM,\n    // Quiet until the first submit, then each field re-checks as it is corrected.\n    validationLogic: revalidateLogic({\n      mode: \"submit\",\n      modeAfterSubmission: \"change\",\n    }),\n    validators: { onDynamic: schema },\n    onSubmit: ({ value }) => onSubmit(value, type),\n  })\n\n  // A code or name the server just refused shows its error at once, without another submit.\n  useEffect(() => {\n    if (checkedKey.current === typesKey) return\n    checkedKey.current = typesKey\n    void form.validate(\"change\")\n  }, [typesKey, form])\n\n  return (\n    <FormDialogForm onSubmit={form.handleSubmit}>\n      <FormDialogHeader>\n        <FormDialogTitle>\n          {type ? \"Edit Facility Type\" : \"Create Facility Type\"}\n        </FormDialogTitle>\n        <FormDialogDescription>\n          {type\n            ? \"Change the name, display order and settings of this type.\"\n            : \"Give the type a code, a name and its place in lists.\"}\n        </FormDialogDescription>\n      </FormDialogHeader>\n      <FormDialogBody>\n        <FieldGroup>\n          {error && (\n            <FormDialogError\n              description={error}\n              title=\"Could Not Save Facility Type\"\n            />\n          )}\n          <form.AppField name=\"code\">\n            {(field) => (\n              <field.TextField\n                autoComplete=\"off\"\n                description={\n                  type\n                    ? \"The code can't be changed once the type exists.\"\n                    : undefined\n                }\n                dir=\"ltr\"\n                disabled={Boolean(type)}\n                label=\"Facility Type Code\"\n                required\n              />\n            )}\n          </form.AppField>\n          <form.AppField name=\"name\">\n            {(field) => (\n              <field.TextField\n                autoComplete=\"off\"\n                label=\"Facility Type Name\"\n                required\n              />\n            )}\n          </form.AppField>\n          <form.AppField name=\"displayOrder\">\n            {(field) => (\n              <field.NumberField\n                description=\"Lists show facility types from the lowest number up.\"\n                label=\"Facility Type Display Order\"\n                required\n              />\n            )}\n          </form.AppField>\n          <form.AppField name=\"active\">\n            {(field) => (\n              <field.SwitchField\n                description=\"Facilities can be given this type.\"\n                label=\"Active\"\n              />\n            )}\n          </form.AppField>\n          <form.AppField name=\"primaryHealthCare\">\n            {(field) => (\n              <field.SwitchField\n                description=\"Facilities of this type give primary health care.\"\n                label=\"Primary Health Care\"\n              />\n            )}\n          </form.AppField>\n        </FieldGroup>\n      </FormDialogBody>\n      <FormDialogFooter>\n        <FormDialogCancel disabled={pending} />\n        <FormDialogSubmit pending={pending}>\n          {type ? \"Save\" : \"Create\"}\n        </FormDialogSubmit>\n      </FormDialogFooter>\n    </FormDialogForm>\n  )\n}\n\n/** A switch row whose value is still loading, laid out like `SwitchField`. */\nfunction SwitchSkeleton() {\n  return (\n    <div\n      aria-hidden\n      className=\"flex min-h-8 items-center justify-between gap-3\"\n    >\n      <SkeletonLine width=\"short\" />\n      {/* A plain element, since Skeleton owns its corner radius and a switch is round. */}\n      <div className=\"h-4.5 w-8 shrink-0 animate-pulse rounded-full bg-muted\" />\n    </div>\n  )\n}\n\n/** Laid out like the form, so nothing moves when the type arrives. */\nfunction FacilityTypeFormSkeleton({\n  title,\n  submitLabel,\n}: {\n  title: string\n  submitLabel: string\n}) {\n  return (\n    <>\n      <FormDialogHeader>\n        <FormDialogTitle>{title}</FormDialogTitle>\n        <SkeletonLine />\n      </FormDialogHeader>\n      <FormDialogBody>\n        <div aria-busy>\n          <FieldGroup>\n            <FieldSkeleton label=\"Facility Type Code\" required />\n            <FieldSkeleton label=\"Facility Type Name\" required />\n            <FieldSkeleton label=\"Facility Type Display Order\" required />\n            <SwitchSkeleton />\n            <SwitchSkeleton />\n          </FieldGroup>\n        </div>\n      </FormDialogBody>\n      <FormDialogFooter>\n        <FormDialogCancel />\n        <FormDialogSubmit disabled>{submitLabel}</FormDialogSubmit>\n      </FormDialogFooter>\n    </>\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/facility-types-page/facility-type-form-dialog.tsx"
    },
    {
      "path": "registry/templates/openlmis/facility-types-page/components/facility-type-form-dialog/facility-type-form.ts",
      "content": "import { z } from \"zod\"\n\n/** A facility type as the form reads and writes it; map your API's type onto it. */\nexport type FacilityType = {\n  id: string\n  code: string\n  name: string | null\n  displayOrder: number | null\n  active: boolean\n  primaryHealthCare: boolean\n}\n\nexport type TakenFacilityType = Pick<FacilityType, \"id\" | \"code\" | \"name\">\n\nconst MAX_WHOLE_NUMBER = 2_147_483_647\n\nconst same = (a: string | null, b: string) =>\n  a?.trim().toLowerCase() === b.trim().toLowerCase()\n\n/** Arabic-Indic and Persian digits read as their Latin ones, so any keyboard can type a number. */\nconst toLatinDigits = (text: string) =>\n  text.replace(/[٠-٩۰-۹]/g, (digit) => {\n    const code = digit.charCodeAt(0)\n    return String(code - (code >= 0x06f0 ? 0x06f0 : 0x0660))\n  })\n\nconst toWholeNumber = (text: string) => Number(toLatinDigits(text.trim()))\n\n/** Refuses a code or name another type has, ignoring case; `editingId` is the type being edited. */\nexport function facilityTypeFormSchema(\n  types: readonly TakenFacilityType[],\n  editingId?: string\n) {\n  const others = types.filter((type) => type.id !== editingId)\n  return z.object({\n    code: z\n      .string()\n      .trim()\n      .min(1, \"Enter a code.\")\n      .refine(\n        (code) => !others.some((type) => same(type.code, code)),\n        \"Another facility type already has this code.\"\n      ),\n    name: z\n      .string()\n      .trim()\n      .min(1, \"Enter a name.\")\n      .refine(\n        (name) => !others.some((type) => same(type.name, name)),\n        \"Another facility type already has this name.\"\n      ),\n    displayOrder: z.string().superRefine((value, context) => {\n      const text = toLatinDigits(value.trim())\n      if (!text)\n        context.addIssue({ code: \"custom\", message: \"Enter a display order.\" })\n      else if (!/^[0-9]+$/.test(text))\n        context.addIssue({\n          code: \"custom\",\n          message: \"Enter a whole number, such as 1 or 12.\",\n        })\n      else if (Number(text) > MAX_WHOLE_NUMBER)\n        context.addIssue({\n          code: \"custom\",\n          message: \"Enter a number no larger than 2147483647.\",\n        })\n    }),\n    active: z.boolean(),\n    primaryHealthCare: z.boolean(),\n  })\n}\n\nexport type FacilityTypeFormValues = z.infer<\n  ReturnType<typeof facilityTypeFormSchema>\n>\n\nexport const EMPTY_FACILITY_TYPE_FORM: FacilityTypeFormValues = {\n  code: \"\",\n  name: \"\",\n  displayOrder: \"1\",\n  active: true,\n  primaryHealthCare: false,\n}\n\nexport function toFacilityTypeFormValues(\n  type: FacilityType\n): FacilityTypeFormValues {\n  return {\n    code: type.code,\n    name: type.name ?? \"\",\n    displayOrder: type.displayOrder === null ? \"\" : String(type.displayOrder),\n    active: type.active,\n    primaryHealthCare: type.primaryHealthCare,\n  }\n}\n\n/** The saved type with the form's values; a saved type keeps its code. */\nexport function toFacilityType(\n  values: FacilityTypeFormValues,\n  saved?: FacilityType\n): Omit<FacilityType, \"id\"> {\n  return {\n    ...saved,\n    code: saved?.code ?? values.code.trim(),\n    name: values.name.trim(),\n    displayOrder: toWholeNumber(values.displayOrder),\n    active: values.active,\n    primaryHealthCare: values.primaryHealthCare,\n  }\n}",
      "type": "registry:lib",
      "target": "components/openlmis/facility-types-page/facility-type-form.ts"
    },
    {
      "path": "registry/templates/openlmis/facility-types-page/components/facility-types-page.tsx",
      "content": "\"use client\"\n\nimport {\n  type ColumnVisibilityState,\n  functionalUpdate,\n  type PaginationState,\n  type SortingState,\n  useTable,\n} from \"@tanstack/react-table\"\nimport { PlusIcon, ShapesIcon } from \"lucide-react\"\nimport { useCallback, useMemo, useRef, useState } from \"react\"\n\nimport { Button } from \"@/components/ui/button\"\nimport {\n  DataTable,\n  DataTableEmpty,\n  DataTablePagination,\n  dataTableFeatures,\n} from \"@/components/blocks/openlmis/data-table/data-table\"\nimport {\n  useColumnVisibility,\n  useContainerSize,\n} from \"@/components/blocks/openlmis/data-table/responsive-columns\"\nimport {\n  ListToolbar,\n  ListToolbarEnd,\n} from \"@/components/blocks/openlmis/list-toolbar\"\nimport {\n  Workspace,\n  WorkspaceContent,\n  WorkspaceDescription,\n  WorkspaceHeader,\n  WorkspaceHeading,\n  WorkspaceIcon,\n  WorkspaceTitle,\n} from \"@/components/blocks/openlmis/workspace\"\nimport { Callout } from \"@/components/openlmis/callout\"\nimport { ColumnViewOptions } from \"@/components/openlmis/column-view-options\"\n\nimport { MOCK_FACILITY_TYPES } from \"@/components/openlmis/facility-types-page/mock-facility-types\"\nimport {\n  createFacilityTypeColumns,\n  FACILITY_TYPE_HIDEABLE_COLUMNS,\n  type FacilityTypeSortField,\n} from \"@/components/openlmis/facility-types-page/facility-type-columns\"\nimport {\n  type FacilityType,\n  type FacilityTypeFormValues,\n  toFacilityType,\n} from \"@/components/openlmis/facility-types-page/facility-type-form\"\nimport {\n  FacilityTypeFormDialog,\n  type FacilityTypeFormDialogTarget,\n} from \"@/components/openlmis/facility-types-page/facility-type-form-dialog\"\n\nconst DEFAULT_SORT = { id: \"displayOrder\", desc: false }\nconst DEFAULT_SORTING: SortingState = [DEFAULT_SORT]\n\nconst getRowId = (type: FacilityType) => type.id\n\nconst byName = (a: FacilityType, b: FacilityType) =>\n  (a.name ?? \"\").localeCompare(b.name ?? \"\", undefined, {\n    sensitivity: \"base\",\n  })\n\n// A type with no display order sorts after those with one.\nconst order = (type: FacilityType) =>\n  type.displayOrder ?? Number.POSITIVE_INFINITY\n\nconst COMPARE: Record<\n  FacilityTypeSortField,\n  (a: FacilityType, b: FacilityType) => number\n> = {\n  displayOrder: (a, b) => order(a) - order(b),\n  name: byName,\n  code: (a, b) => a.code.localeCompare(b.code),\n  active: (a, b) => Number(b.active) - Number(a.active),\n}\n\ntype Notice = { title: string; description: string }\n\n/** The facility types list screen; mount it from any route, e.g. the `page.tsx` this template ships. */\nexport function FacilityTypesPage() {\n  const [types, setTypes] = useState(MOCK_FACILITY_TYPES)\n  const [sorting, setSorting] = useState(DEFAULT_SORTING)\n  const [pagination, setPagination] = useState<PaginationState>({\n    pageIndex: 0,\n    pageSize: 10,\n  })\n  const [target, setTarget] = useState<FacilityTypeFormDialogTarget>()\n  const [notice, setNotice] = useState<Notice>()\n  const nextId = useRef(MOCK_FACILITY_TYPES.length + 1)\n  const [measureContent, contentSize] = useContainerSize<HTMLDivElement>()\n  // Kept for the visit only; store it (e.g. in localStorage) to remember it across visits.\n  const columnChoices = useState<ColumnVisibilityState>({})\n  const columnView = useColumnVisibility(\n    FACILITY_TYPE_HIDEABLE_COLUMNS,\n    columnChoices,\n    contentSize\n  )\n\n  // Stable, so the columns built from it keep their identity between renders.\n  const openDialog = useCallback((next: FacilityTypeFormDialogTarget) => {\n    setNotice(undefined)\n    setTarget(next)\n  }, [])\n  const columns = useMemo(\n    () => createFacilityTypeColumns(openDialog),\n    [openDialog]\n  )\n\n  // Every type is in memory, so sorting and paging happen here.\n  const sorted = useMemo(() => {\n    const [sort = DEFAULT_SORT] = sorting\n    const compare = COMPARE[sort.id as FacilityTypeSortField]\n    // oxlint-disable-next-line unicorn/no-array-sort -- sorts a fresh copy; toSorted needs the ES2023 lib\n    return [...types].sort(\n      (a, b) => (sort.desc ? -compare(a, b) : compare(a, b)) || byName(a, b)\n    )\n  }, [types, sorting])\n  const lastPage = Math.max(\n    0,\n    Math.ceil(sorted.length / pagination.pageSize) - 1\n  )\n  const page = useMemo(\n    () => ({\n      ...pagination,\n      pageIndex: Math.min(pagination.pageIndex, lastPage),\n    }),\n    [pagination, lastPage]\n  )\n  const data = useMemo(\n    () =>\n      sorted.slice(\n        page.pageIndex * page.pageSize,\n        (page.pageIndex + 1) * page.pageSize\n      ),\n    [sorted, page]\n  )\n\n  const table = useTable({\n    features: dataTableFeatures,\n    columns,\n    data,\n    getRowId,\n    rowCount: sorted.length,\n    manualPagination: true,\n    manualSorting: true,\n    enableSortingRemoval: false,\n    state: {\n      pagination: page,\n      sorting,\n      columnVisibility: columnView.visibility,\n    },\n    onPaginationChange: (updater) =>\n      setPagination(functionalUpdate(updater, page)),\n    onSortingChange: (updater) => {\n      setSorting(functionalUpdate(updater, sorting))\n      setPagination((current) => ({ ...current, pageIndex: 0 }))\n    },\n  })\n\n  const editing = types.find((type) => type.id === target)\n\n  const save = (\n    values: FacilityTypeFormValues,\n    saved: FacilityType | undefined\n  ) => {\n    const type = toFacilityType(values, saved)\n    if (saved) {\n      setTypes((current) =>\n        current.map((item) =>\n          item.id === saved.id ? { ...type, id: saved.id } : item\n        )\n      )\n      setNotice({\n        title: \"Facility Type Saved\",\n        description: `Changes to ${type.name} are saved.`,\n      })\n    } else {\n      const id = `type-${nextId.current++}`\n      setTypes((current) => [...current, { ...type, id }])\n      setNotice({\n        title: \"Facility Type Created\",\n        description: `${type.name} is ready to give to facilities.`,\n      })\n    }\n    setTarget(undefined)\n  }\n\n  return (\n    <Workspace>\n      <WorkspaceHeader>\n        <WorkspaceHeading>\n          <WorkspaceIcon>\n            <ShapesIcon />\n          </WorkspaceIcon>\n          <WorkspaceTitle>Facility Types</WorkspaceTitle>\n          <WorkspaceDescription>\n            Group facilities by what they are, such as health centers or\n            district stores.\n          </WorkspaceDescription>\n        </WorkspaceHeading>\n      </WorkspaceHeader>\n      <WorkspaceContent>\n        {/* Measured, because the room for columns depends on a sidebar as well as the window. */}\n        <div\n          className=\"flex flex-col gap-4 @4xl/main:gap-6\"\n          ref={measureContent}\n        >\n          {notice && (\n            <Callout title={notice.title} tone=\"success\">\n              {notice.description}\n            </Callout>\n          )}\n          <ListToolbar>\n            <ListToolbarEnd>\n              <ColumnViewOptions\n                columns={FACILITY_TYPE_HIDEABLE_COLUMNS}\n                onReset={columnView.onReset}\n                onVisibilityChange={columnView.onVisibilityChange}\n                visibility={columnView.visibility}\n              />\n            </ListToolbarEnd>\n            <div className=\"w-full @2xl/toolbar:w-auto\">\n              <Button className=\"w-full\" onClick={() => openDialog(\"new\")}>\n                <PlusIcon data-icon=\"inline-start\" />\n                Add Facility Type\n              </Button>\n            </div>\n          </ListToolbar>\n          <DataTable\n            empty={\n              <DataTableEmpty\n                action={\n                  <Button onClick={() => openDialog(\"new\")}>\n                    <PlusIcon data-icon=\"inline-start\" />\n                    Add Facility Type\n                  </Button>\n                }\n                description=\"Facility types you add appear here.\"\n                icon={<ShapesIcon />}\n                title=\"No Facility Types Yet\"\n              />\n            }\n            footer={sorted.length > 0 && <DataTablePagination table={table} />}\n            table={table}\n          />\n        </div>\n      </WorkspaceContent>\n      <FacilityTypeFormDialog\n        onClose={() => setTarget(undefined)}\n        onSubmit={save}\n        target={target}\n        type={editing}\n        types={types}\n      />\n    </Workspace>\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/facility-types-page/facility-types-page.tsx"
    },
    {
      "path": "registry/templates/openlmis/facility-types-page/components/mock-facility-types.ts",
      "content": "// Mock facility types, so the page runs with no backend. Pass your own instead.\n\nimport type { FacilityType } from \"@/components/openlmis/facility-types-page/facility-type-form\"\n\nexport const MOCK_FACILITY_TYPES: FacilityType[] = [\n  {\n    id: \"type-health-center\",\n    code: \"health_center\",\n    name: \"Health Center\",\n    displayOrder: 1,\n    active: true,\n    primaryHealthCare: true,\n  },\n  {\n    id: \"type-district-hospital\",\n    code: \"district_hospital\",\n    name: \"District Hospital\",\n    displayOrder: 2,\n    active: true,\n    primaryHealthCare: false,\n  },\n  {\n    id: \"type-warehouse\",\n    code: \"warehouse\",\n    name: \"Warehouse\",\n    displayOrder: 3,\n    active: false,\n    primaryHealthCare: false,\n  },\n]",
      "type": "registry:lib",
      "target": "components/openlmis/facility-types-page/mock-facility-types.ts"
    },
    {
      "path": "registry/templates/openlmis/facility-types-page/page.tsx",
      "content": "import { FacilityTypesPage } from \"@/components/openlmis/facility-types-page/facility-types-page\"\n\n// A Next.js App Router route; in any other React app, render FacilityTypesPage from your own route.\nexport default function Page() {\n  return <FacilityTypesPage />\n}",
      "type": "registry:page",
      "target": "app/facility-types-page/page.tsx"
    }
  ],
  "cssVars": {
    "light": {
      "destructive": "oklch(0.577 0.245 27.325)",
      "destructive-foreground": "oklch(0.985 0 0)",
      "success": "oklch(0.596 0.145 163.225)",
      "success-foreground": "oklch(0.985 0 0)",
      "warning": "oklch(0.666 0.179 58.318)",
      "warning-foreground": "oklch(0.985 0 0)",
      "info": "oklch(0.55 0.13 237)",
      "info-foreground": "oklch(0.985 0 0)"
    },
    "dark": {
      "destructive": "oklch(0.704 0.191 22.216)",
      "destructive-foreground": "oklch(0.21 0.04 25)",
      "success": "oklch(0.696 0.17 162.48)",
      "success-foreground": "oklch(0.21 0.04 163)",
      "warning": "oklch(0.769 0.188 70.08)",
      "warning-foreground": "oklch(0.22 0.04 60)",
      "info": "oklch(0.7 0.14 237)",
      "info-foreground": "oklch(0.2 0.04 240)"
    }
  },
  "meta": {
    "project": "openlmis",
    "height": "411px"
  },
  "docs": "Requires a `base-*` style in components.json (the `shadcn init` default). Legacy `new-york`/`radix-*` styles install Radix primitives, which reject the `render` prop this item uses.",
  "categories": [
    "administration"
  ],
  "type": "registry:page"
}
