{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "openlmis-facility-editor-page",
  "title": "Facility Editor Page",
  "description": "Mock facility editor with Information and Associated Programs tabs, managed fields, combined validation and discard confirmation.",
  "dependencies": [
    "@tanstack/react-form@^1",
    "lucide-react@^1",
    "zod@^4",
    "@base-ui/react@^1"
  ],
  "registryDependencies": [
    "alert",
    "badge",
    "button",
    "empty",
    "field",
    "skeleton",
    "spinner",
    "switch",
    "table",
    "tabs",
    "https://registry.soldevelo.com/r/openlmis-callout.json",
    "https://registry.soldevelo.com/r/openlmis-data-table.json",
    "https://registry.soldevelo.com/r/openlmis-date-picker.json",
    "https://registry.soldevelo.com/r/openlmis-discard-changes-dialog.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-page-breadcrumbs.json",
    "https://registry.soldevelo.com/r/openlmis-workspace.json",
    "https://registry.soldevelo.com/r/openlmis-workspace-tabs.json"
  ],
  "files": [
    {
      "path": "registry/templates/openlmis/facility-editor-page/components/facility-editor-page.tsx",
      "content": "\"use client\"\n\nimport { AlertCircleIcon, BuildingIcon } from \"lucide-react\"\nimport { useEffect, useMemo, useRef, useState } from \"react\"\n\nimport { Alert, AlertDescription, AlertTitle } from \"@/components/ui/alert\"\nimport { Badge } from \"@/components/ui/badge\"\nimport { Button } from \"@/components/ui/button\"\nimport { Spinner } from \"@/components/ui/spinner\"\nimport { TabsContent } from \"@/components/ui/tabs\"\nimport {\n  EMPTY_FACILITY,\n  type FacilityValues,\n} from \"@/components/openlmis/facility-editor-page/facility-form\"\nimport { FacilityGeneralForm } from \"@/components/openlmis/facility-editor-page/facility-general-form\"\nimport {\n  type FacilityProgram,\n  missingStartDate,\n} from \"@/components/openlmis/facility-editor-page/facility-program\"\nimport { FacilityPrograms } from \"@/components/openlmis/facility-editor-page/facility-programs\"\nimport {\n  Workspace,\n  WorkspaceContent,\n  WorkspaceDescription,\n  WorkspaceFooter,\n  WorkspaceHeader,\n  WorkspaceHeading,\n  WorkspaceIcon,\n  WorkspaceLayout,\n  WorkspaceTitle,\n} from \"@/components/blocks/openlmis/workspace\"\nimport { Callout } from \"@/components/openlmis/callout\"\nimport { DiscardChangesDialog } from \"@/components/openlmis/discard-changes-dialog\"\nimport { PageBreadcrumbs } from \"@/components/openlmis/page-breadcrumbs\"\nimport {\n  WorkspaceTabs,\n  WorkspaceTabsList,\n  WorkspaceTabsTrigger,\n} from \"@/components/openlmis/workspace-tabs\"\n\nimport {\n  MOCK_FACILITY,\n  MOCK_LOOKUPS,\n  MOCK_MANAGED_FACILITY,\n  MOCK_PROGRAMS,\n  MOCK_TAKEN_CODES,\n  type MockFacility,\n} from \"@/components/openlmis/facility-editor-page/mock-facility\"\n\nconst FORM_ID = \"facility-form\"\n\ntype FacilityTab = \"information\" | \"programs\"\n\ntype FacilityEditorPageProps = {\n  /** Start on a new, empty facility. */\n  adding?: boolean\n  /** Start on the facility managed by another system. */\n  managed?: boolean\n  /** Show the skeleton, as while the facility loads. */\n  loading?: boolean\n  /** Show Save as in progress. */\n  pending?: boolean\n  /** Mock outcome: every save fails. */\n  saveFails?: boolean\n  /** Mock outcome: the server refuses any changed code. */\n  refuseCodes?: boolean\n}\n\nconst NEW_FACILITY: MockFacility = {\n  values: EMPTY_FACILITY,\n  programs: [],\n  managedExternally: false,\n}\n\n/** Focuses the first invalid field on the open tab, waiting for it to render if needed. */\nfunction focusFirstError(container: HTMLElement) {\n  const selector = '[role=\"tabpanel\"]:not([hidden]) [aria-invalid=\"true\"]'\n  const focus = () => {\n    const field = container.querySelector<HTMLElement>(selector)\n    field?.focus()\n    return Boolean(field)\n  }\n  if (focus()) return () => {}\n  const observer = new MutationObserver(() => {\n    if (focus()) observer.disconnect()\n  })\n  observer.observe(container, {\n    attributes: true,\n    attributeFilter: [\"aria-invalid\", \"hidden\"],\n    childList: true,\n    subtree: true,\n  })\n  return () => observer.disconnect()\n}\n\nconst programChanges = (\n  rows: readonly FacilityProgram[],\n  saved: readonly FacilityProgram[]\n) => (JSON.stringify(rows) === JSON.stringify(saved) ? 0 : 1)\n\n/** Add or edit a facility on one page: its information, then the programs it supports. */\nexport function FacilityEditorPage({\n  adding: startAdding = false,\n  managed = false,\n  loading = false,\n  pending = false,\n  saveFails = false,\n  refuseCodes = false,\n}: FacilityEditorPageProps) {\n  const [adding, setAdding] = useState(startAdding)\n  const [saved, setSaved] = useState(\n    startAdding ? NEW_FACILITY : managed ? MOCK_MANAGED_FACILITY : MOCK_FACILITY\n  )\n  // Bumped to start the form again from `saved`, after a save or a discard.\n  const [revision, setRevision] = useState(0)\n  const [programs, setPrograms] = useState(saved.programs)\n  const [tab, setTab] = useState<FacilityTab>(\"information\")\n  const [infoChanges, setInfoChanges] = useState(0)\n  const [showProgramErrors, setShowProgramErrors] = useState(false)\n  const [refusedCodes, setRefusedCodes] = useState<string[]>([])\n  const [saveError, setSaveError] = useState(false)\n  const [notice, setNotice] = useState<{ title: string; description: string }>()\n  const [discarding, setDiscarding] = useState(false)\n  // Bumped to focus the first error once the tab holding it is open.\n  const [focusRequest, setFocusRequest] = useState(0)\n  const container = useRef<HTMLDivElement>(null)\n\n  const locked = saved.managedExternally\n  const name = saved.values.name || saved.values.code\n  const changes = infoChanges + programChanges(programs, saved.programs)\n  const takenCodes = useMemo(\n    () => [\n      ...MOCK_TAKEN_CODES.filter((code) => code !== saved.values.code),\n      ...refusedCodes,\n    ],\n    [saved.values.code, refusedCodes]\n  )\n\n  useEffect(() => {\n    if (focusRequest === 0 || !container.current) return\n    return focusFirstError(container.current)\n  }, [focusRequest])\n\n  const showErrors = (nextTab: FacilityTab) => {\n    setTab(nextTab)\n    setFocusRequest((current) => current + 1)\n  }\n\n  const start = (facility: MockFacility) => {\n    setSaved(facility)\n    setPrograms(facility.programs)\n    setRevision((current) => current + 1)\n    setTab(\"information\")\n    setInfoChanges(0)\n    setShowProgramErrors(false)\n    setRefusedCodes([])\n    setSaveError(false)\n    setNotice(undefined)\n  }\n\n  const save = (values: FacilityValues) => {\n    setSaveError(false)\n    if (programs.some(missingStartDate)) {\n      setShowProgramErrors(true)\n      showErrors(\"programs\")\n      return\n    }\n    if (saveFails) {\n      setSaveError(true)\n      return\n    }\n    if (refuseCodes && values.code !== saved.values.code) {\n      // The server refused the code, so the form now marks it as taken.\n      setRefusedCodes((codes) => [...codes, values.code])\n      showErrors(\"information\")\n      return\n    }\n    const next: MockFacility = {\n      ...saved,\n      values,\n      programs: programs.map((row) => ({ ...row, saved: true })),\n    }\n    start(next)\n    setAdding(false)\n    const savedName = values.name || values.code\n    setNotice(\n      adding\n        ? {\n            title: \"Facility Created\",\n            description: `${savedName} is ready to use.`,\n          }\n        : {\n            title: \"Facility Saved\",\n            description: `Changes to ${savedName} are saved.`,\n          }\n    )\n  }\n\n  const cancel = () => {\n    if (changes > 0) setDiscarding(true)\n    else start(saved)\n  }\n\n  return (\n    <WorkspaceLayout ref={container}>\n      <Workspace width=\"narrow\">\n        <PageBreadcrumbs\n          items={[\n            { label: \"Home\", href: \"#\" },\n            { label: \"Administration\" },\n            { label: \"Facilities\", href: \"#\" },\n            { label: adding ? \"Add Facility\" : \"Edit Facility\" },\n          ]}\n        />\n        <WorkspaceHeader>\n          <WorkspaceHeading>\n            <WorkspaceIcon>\n              <BuildingIcon />\n            </WorkspaceIcon>\n            <WorkspaceTitle>\n              {adding\n                ? \"Add Facility\"\n                : loading\n                  ? \"Edit Facility\"\n                  : `Edit ${name}`}\n            </WorkspaceTitle>\n            <WorkspaceDescription>\n              {adding\n                ? \"Set up a facility and the programs it supports.\"\n                : \"Change the facility's details and the programs it supports.\"}\n            </WorkspaceDescription>\n          </WorkspaceHeading>\n        </WorkspaceHeader>\n        <WorkspaceContent>\n          <div className=\"flex flex-col gap-4 lg:gap-6\" inert={pending}>\n            {notice && (\n              <Callout title={notice.title} tone=\"success\">\n                {notice.description}\n              </Callout>\n            )}\n            {locked && !loading && (\n              <Callout title=\"Managed By Another System\" tone=\"info\">\n                Its name, code, description, geographic zone and active status\n                come from another system, so they cannot be changed here.\n              </Callout>\n            )}\n            {saveError && (\n              <Alert variant=\"destructive\">\n                <AlertCircleIcon />\n                <AlertTitle>Could Not Save Facility</AlertTitle>\n                <AlertDescription>\n                  Something went wrong. Check your connection and try again.\n                </AlertDescription>\n              </Alert>\n            )}\n            <WorkspaceTabs\n              onValueChange={(value) => setTab(value as FacilityTab)}\n              value={tab}\n            >\n              <WorkspaceTabsList label=\"Facility Sections\">\n                <WorkspaceTabsTrigger value=\"information\">\n                  Facility Information\n                </WorkspaceTabsTrigger>\n                <WorkspaceTabsTrigger value=\"programs\">\n                  Associated Programs\n                  {!loading && (\n                    <Badge variant=\"secondary\">{programs.length}</Badge>\n                  )}\n                </WorkspaceTabsTrigger>\n              </WorkspaceTabsList>\n              {/* Kept mounted, so a hidden tab keeps its edits and Save checks both. */}\n              <TabsContent keepMounted value=\"information\">\n                <FacilityGeneralForm\n                  facility={loading ? undefined : saved.values}\n                  formId={FORM_ID}\n                  goLiveDateRequired={!adding}\n                  key={revision}\n                  locked={locked}\n                  lookups={MOCK_LOOKUPS}\n                  onChangesChange={setInfoChanges}\n                  onInvalid={() => {\n                    // Programs share the submit, so their errors show at once too.\n                    setShowProgramErrors(programs.some(missingStartDate))\n                    showErrors(\"information\")\n                  }}\n                  onSubmit={save}\n                  takenCodes={takenCodes}\n                />\n              </TabsContent>\n              <TabsContent keepMounted value=\"programs\">\n                <FacilityPrograms\n                  onRowsChange={setPrograms}\n                  programs={MOCK_PROGRAMS}\n                  rows={loading ? undefined : programs}\n                  showErrors={showProgramErrors}\n                />\n              </TabsContent>\n            </WorkspaceTabs>\n          </div>\n        </WorkspaceContent>\n      </Workspace>\n      <WorkspaceFooter width=\"narrow\">\n        <Button\n          disabled={pending || loading}\n          onClick={cancel}\n          size=\"lg\"\n          variant=\"outline\"\n        >\n          Cancel\n        </Button>\n        <Button\n          disabled={pending || loading}\n          focusableWhenDisabled={pending}\n          form={FORM_ID}\n          size=\"lg\"\n          type=\"submit\"\n        >\n          {pending && <Spinner data-icon=\"inline-start\" />}\n          {adding ? \"Create\" : \"Save\"}\n        </Button>\n      </WorkspaceFooter>\n      <DiscardChangesDialog\n        changes={changes}\n        onDiscard={() => {\n          setDiscarding(false)\n          start(saved)\n        }}\n        onKeepEditing={() => setDiscarding(false)}\n        open={discarding}\n        subject={adding ? \"the new facility\" : name}\n      />\n    </WorkspaceLayout>\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/facility-editor-page/facility-editor-page.tsx"
    },
    {
      "path": "registry/templates/openlmis/facility-editor-page/components/facility-form-dialog/facility-form-dialog.tsx",
      "content": "\"use client\"\n\nimport { revalidateLogic } from \"@tanstack/react-form\"\nimport { type ReactNode, useMemo } from \"react\"\n\nimport { FieldGroup } from \"@/components/ui/field\"\nimport {\n  EMPTY_FACILITY,\n  facilityFormSchema,\n  type FacilityValues,\n  toFacilityValues,\n} from \"@/components/openlmis/facility-editor-page/facility-form\"\nimport {\n  type FacilityLookups,\n  FacilityFormFields,\n} from \"@/components/openlmis/facility-editor-page/facility-form-fields\"\nimport { FacilityGeneralFormSkeleton } from \"@/components/openlmis/facility-editor-page/facility-general-form\"\nimport {\n  FormDialog,\n  FormDialogBody,\n  FormDialogCancel,\n  FormDialogDescription,\n  FormDialogError,\n  FormDialogFooter,\n  FormDialogForm,\n  FormDialogHeader,\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\"\n\ntype FacilityFormDialogProps = {\n  open: boolean\n  /** The types, zones and operators to pick from; skeletons show until set. */\n  lookups: FacilityLookups | undefined\n  /** Other facilities' codes, and any the server refused, turned down for the new one. */\n  takenCodes?: readonly string[]\n  /** Called with trimmed values; create the facility, then close. */\n  onSubmit: (values: FacilityValues) => void\n  /** Keeps the dialog open and spins Create while the save runs. */\n  pending?: boolean\n  /** Shown above the fields, e.g. why the create failed; what was typed stays. */\n  error?: ReactNode\n  onClose: () => void\n}\n\n/** Add Facility from a list: its details now, its programs later in the editor. */\nexport function FacilityFormDialog({\n  open,\n  pending = false,\n  onClose,\n  ...props\n}: FacilityFormDialogProps) {\n  const { shown, dialogProps } = useDialogTarget(open || undefined, onClose)\n\n  return (\n    <FormDialog {...dialogProps(pending)}>\n      {shown && <AddFacilityContent pending={pending} {...props} />}\n    </FormDialog>\n  )\n}\n\nfunction AddFacilityHeader() {\n  return (\n    <FormDialogHeader>\n      <FormDialogTitle>Add Facility</FormDialogTitle>\n      <FormDialogDescription>\n        Set up a facility; add the programs it supports once it is created.\n      </FormDialogDescription>\n    </FormDialogHeader>\n  )\n}\n\ntype ContentProps = Omit<FacilityFormDialogProps, \"open\" | \"onClose\"> & {\n  pending: boolean\n}\n\nfunction AddFacilityContent({ lookups, ...props }: ContentProps) {\n  if (!lookups) {\n    return (\n      <>\n        <AddFacilityHeader />\n        <FormDialogBody>\n          <FacilityGeneralFormSkeleton />\n        </FormDialogBody>\n        <FormDialogFooter>\n          <FormDialogCancel />\n          <FormDialogSubmit disabled>Create</FormDialogSubmit>\n        </FormDialogFooter>\n      </>\n    )\n  }\n  return <AddFacilityForm lookups={lookups} {...props} />\n}\n\nfunction AddFacilityForm({\n  lookups,\n  takenCodes,\n  onSubmit,\n  pending,\n  error,\n}: ContentProps & { lookups: FacilityLookups }) {\n  const schema = useMemo(() => facilityFormSchema({ takenCodes }), [takenCodes])\n  const form = useAppForm({\n    defaultValues: EMPTY_FACILITY,\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(toFacilityValues(value)),\n  })\n\n  return (\n    <FormDialogForm onSubmit={() => void form.handleSubmit()}>\n      <AddFacilityHeader />\n      <FormDialogBody>\n        <FieldGroup>\n          {error && (\n            <FormDialogError\n              description={error}\n              title=\"Could Not Save Facility\"\n            />\n          )}\n          <FacilityFormFields form={form} lookups={lookups} />\n        </FieldGroup>\n      </FormDialogBody>\n      <FormDialogFooter>\n        <FormDialogCancel disabled={pending} />\n        <FormDialogSubmit pending={pending}>Create</FormDialogSubmit>\n      </FormDialogFooter>\n    </FormDialogForm>\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/facility-editor-page/facility-form-dialog.tsx"
    },
    {
      "path": "registry/templates/openlmis/facility-editor-page/components/facility-general-form/facility-form-fields.tsx",
      "content": "\"use client\"\n\nimport { useMemo } from \"react\"\n\nimport { withForm } from \"@/components/openlmis/form-fields/form\"\n\nimport {\n  EMPTY_FACILITY,\n  type FacilityOption,\n  toFacilityItems,\n} from \"@/components/openlmis/facility-editor-page/facility-form\"\n\nexport type FacilityLookups = {\n  types: readonly FacilityOption[]\n  zones: readonly FacilityOption[]\n  operators: readonly FacilityOption[]\n}\n\ntype FacilityFormFieldsProps = {\n  lookups: FacilityLookups\n  /** Managed by another system: name, code, zone, description and Active cannot change. */\n  locked?: boolean\n  /** Every field read only, e.g. without the right to edit facilities. */\n  readOnly?: boolean\n  /** A saved facility must keep its operational date. */\n  goLiveDateRequired?: boolean\n}\n\n/** The facility's details in two columns once there is room, shared by Add Facility and the editor. */\nexport const FacilityFormFields = withForm({\n  defaultValues: EMPTY_FACILITY,\n  props: {} as FacilityFormFieldsProps,\n  render: function Render({\n    form,\n    lookups,\n    locked = false,\n    readOnly = false,\n    goLiveDateRequired = false,\n  }) {\n    const typeItems = useMemo(\n      () => toFacilityItems(lookups.types),\n      [lookups.types]\n    )\n    const zoneItems = useMemo(\n      () => toFacilityItems(lookups.zones),\n      [lookups.zones]\n    )\n    const operatorItems = useMemo(\n      () => toFacilityItems(lookups.operators),\n      [lookups.operators]\n    )\n    const fixed = locked || readOnly\n\n    return (\n      <div className=\"grid gap-x-6 gap-y-5 @3xl/main:grid-cols-2\">\n        <form.AppField name=\"name\">\n          {(field) => (\n            <field.TextField\n              autoComplete=\"off\"\n              dir=\"auto\"\n              disabled={fixed}\n              label=\"Facility Name\"\n              required\n            />\n          )}\n        </form.AppField>\n        <form.AppField name=\"code\">\n          {(field) => (\n            <field.TextField\n              autoComplete=\"off\"\n              dir=\"ltr\"\n              disabled={fixed}\n              label=\"Facility Code\"\n              required\n            />\n          )}\n        </form.AppField>\n        <form.AppField name=\"typeId\">\n          {(field) => (\n            <field.ComboboxField\n              clearLabel=\"Clear Facility Type\"\n              disabled={readOnly}\n              emptyMessage=\"No Matches\"\n              items={typeItems}\n              label=\"Facility Type\"\n              placeholder=\"Select A Type\"\n              required\n            />\n          )}\n        </form.AppField>\n        <form.AppField name=\"zoneId\">\n          {(field) => (\n            <field.ComboboxField\n              clearLabel=\"Clear Geographic Zone\"\n              disabled={fixed}\n              emptyMessage=\"No Matches\"\n              items={zoneItems}\n              label=\"Geographic Zone\"\n              limit={-1}\n              placeholder=\"Select A Zone\"\n              required\n            />\n          )}\n        </form.AppField>\n        <form.AppField name=\"goLiveDate\">\n          {(field) => (\n            <field.DateField\n              clearLabel=\"Clear Operational Date\"\n              description=\"This is used in reporting to record the date the facility becomes operational.\"\n              disabled={readOnly}\n              label=\"Operational Date\"\n              placeholder=\"Pick A Date\"\n              required={goLiveDateRequired}\n            />\n          )}\n        </form.AppField>\n        <form.AppField name=\"operatorId\">\n          {(field) => (\n            <field.ComboboxField\n              clearLabel=\"Clear Facility Operator\"\n              disabled={readOnly}\n              emptyMessage=\"No Matches\"\n              items={operatorItems}\n              label=\"Facility Operator\"\n              placeholder=\"Select An Operator\"\n            />\n          )}\n        </form.AppField>\n        <form.AppField name=\"description\">\n          {(field) => (\n            <field.TextareaField\n              dir=\"auto\"\n              disabled={fixed}\n              label=\"Description\"\n            />\n          )}\n        </form.AppField>\n        <div className=\"@3xl/main:col-start-1\">\n          <form.AppField name=\"active\">\n            {(field) => (\n              <field.SwitchField\n                description=\"This determines whether or not the facility can submit requisitions or receive deliveries.\"\n                disabled={fixed}\n                label=\"Active Facility\"\n              />\n            )}\n          </form.AppField>\n        </div>\n        <form.AppField name=\"enabled\">\n          {(field) => (\n            <field.SwitchField\n              description=\"On: the facility can operate. Off: the facility is permanently decommissioned.\"\n              disabled={readOnly}\n              label=\"Enabled\"\n            />\n          )}\n        </form.AppField>\n      </div>\n    )\n  },\n})",
      "type": "registry:component",
      "target": "components/openlmis/facility-editor-page/facility-form-fields.tsx"
    },
    {
      "path": "registry/templates/openlmis/facility-editor-page/components/facility-general-form/facility-form.ts",
      "content": "import { z } from \"zod\"\n\n/** A facility type, zone or operator: picked by id and shown by name. */\nexport type FacilityOption = {\n  id: string\n  name: string\n  /** Shown under the name in the list, e.g. a zone's level. */\n  description?: string\n}\n\n/** What the facility forms show and save; map your API's facility onto it. */\nexport type FacilityValues = {\n  name: string\n  code: string\n  typeId: string | null\n  zoneId: string | null\n  /** `yyyy-MM-dd`, or empty for none. */\n  goLiveDate: string\n  description: string\n  operatorId: string | null\n  active: boolean\n  enabled: boolean\n}\n\nexport const EMPTY_FACILITY: FacilityValues = {\n  name: \"\",\n  code: \"\",\n  typeId: null,\n  zoneId: null,\n  goLiveDate: \"\",\n  description: \"\",\n  operatorId: null,\n  active: true,\n  enabled: true,\n}\n\nconst requiredText = (message: string) =>\n  z.string().refine((value) => value.trim().length > 0, message)\n\nconst requiredChoice = (message: string) =>\n  z\n    .string()\n    .nullable()\n    .refine((value) => Boolean(value), message)\n\nconst comparableCode = (code: string) => code.trim().toLowerCase()\n\ntype FacilitySchemaOptions = {\n  /** Other facilities' codes, and any the server refused, turned down as this one's. */\n  takenCodes?: readonly string[]\n  /** A saved facility must keep an operational date. */\n  goLiveDateRequired?: boolean\n  /** Managed by another system: its name and code cannot change, so they are not checked. */\n  locked?: boolean\n}\n\nexport function facilityFormSchema({\n  takenCodes = [],\n  goLiveDateRequired = false,\n  locked = false,\n}: FacilitySchemaOptions = {}) {\n  const taken = new Set(takenCodes.map(comparableCode))\n  return z.object({\n    name: locked ? z.string() : requiredText(\"Enter a name.\"),\n    code: locked\n      ? z.string()\n      : requiredText(\"Enter a code.\").refine(\n          (code) => !taken.has(comparableCode(code)),\n          \"Another facility already has this code.\"\n        ),\n    typeId: requiredChoice(\"Choose a facility type.\"),\n    zoneId: requiredChoice(\"Choose a geographic zone.\"),\n    goLiveDate: goLiveDateRequired\n      ? requiredText(\"Choose an operational date.\")\n      : z.string(),\n    description: z.string(),\n    operatorId: z.string().nullable(),\n    active: z.boolean(),\n    enabled: z.boolean(),\n  })\n}\n\n/** The values as a save sends them: text trimmed. */\nexport const toFacilityValues = (values: FacilityValues): FacilityValues => ({\n  ...values,\n  name: values.name.trim(),\n  code: values.code.trim(),\n  description: values.description.trim(),\n})\n\n/** How many fields differ from the saved facility. */\nexport function facilityChanges(values: FacilityValues, saved: FacilityValues) {\n  return (Object.keys(saved) as (keyof FacilityValues)[]).filter((key) => {\n    const value = values[key]\n    const before = saved[key]\n    return typeof value === \"string\" && typeof before === \"string\"\n      ? value.trim() !== before.trim()\n      : value !== before\n  }).length\n}\n\n/** Options as a combobox lists them, by name. */\nexport const toFacilityItems = (options: readonly FacilityOption[]) =>\n  options\n    .map((option) => ({\n      value: option.id,\n      label: option.name,\n      ...(option.description && { description: option.description }),\n    }))\n    // oxlint-disable-next-line unicorn/no-array-sort -- sorts the new array without requiring ES2023\n    .sort((a, b) => a.label.localeCompare(b.label))",
      "type": "registry:lib",
      "target": "components/openlmis/facility-editor-page/facility-form.ts"
    },
    {
      "path": "registry/templates/openlmis/facility-editor-page/components/facility-general-form/facility-general-form.tsx",
      "content": "\"use client\"\n\nimport { revalidateLogic, useStore } from \"@tanstack/react-form\"\nimport { useEffect, useId, useMemo, useRef } from \"react\"\n\nimport { Field, FieldGroup, FieldLabel } from \"@/components/ui/field\"\nimport { useAppForm } from \"@/components/openlmis/form-fields/form\"\nimport { FieldSkeleton } from \"@/components/openlmis/form-fields/form-fields\"\n\nimport {\n  facilityChanges,\n  facilityFormSchema,\n  type FacilityValues,\n  toFacilityValues,\n} from \"@/components/openlmis/facility-editor-page/facility-form\"\nimport {\n  type FacilityLookups,\n  FacilityFormFields,\n} from \"@/components/openlmis/facility-editor-page/facility-form-fields\"\n\ntype FacilityGeneralFormProps = {\n  /** The facility's saved values, or `EMPTY_FACILITY` to add one; a skeleton shows until it is set. */\n  facility: FacilityValues | undefined\n  /** The types, zones and operators to pick from; their fields show skeletons until set. */\n  lookups: FacilityLookups | undefined\n  /** Other facilities' codes, and any the server refused, turned down as this one's. */\n  takenCodes?: readonly string[]\n  /** A saved facility must keep its operational date. */\n  goLiveDateRequired?: boolean\n  /** Managed by another system: name, code, zone, description and Active cannot change. */\n  locked?: boolean\n  readOnly?: boolean\n  /** The form's id, for a Save placed elsewhere, e.g. in a page's `WorkspaceFooter`. */\n  formId?: string\n  /** Called with trimmed values once every field is valid. */\n  onSubmit: (values: FacilityValues) => void\n  /** Called when a submit finds errors, e.g. to open the tab that holds them. */\n  onInvalid?: () => void\n  /** Tells the page how many fields are unsaved, e.g. to ask before leaving. */\n  onChangesChange?: (changes: number) => void\n}\n\n/** A facility's Information tab: name, code, type, zone, dates and status. */\nexport function FacilityGeneralForm({\n  facility,\n  lookups,\n  ...props\n}: FacilityGeneralFormProps) {\n  if (!facility || !lookups) {\n    return (\n      <FacilityGeneralFormSkeleton\n        goLiveDateRequired={props.goLiveDateRequired}\n      />\n    )\n  }\n  return <GeneralForm facility={facility} lookups={lookups} {...props} />\n}\n\nfunction GeneralForm({\n  facility,\n  lookups,\n  takenCodes,\n  goLiveDateRequired = false,\n  locked = false,\n  readOnly = false,\n  formId: givenFormId,\n  onSubmit,\n  onInvalid,\n  onChangesChange,\n}: FacilityGeneralFormProps & {\n  facility: FacilityValues\n  lookups: FacilityLookups\n}) {\n  const generatedFormId = useId()\n  const formId = givenFormId ?? generatedFormId\n  // Keyed on the codes, so an inline array does not re-run validation each render.\n  const takenKey = takenCodes?.join(\"\\n\") ?? \"\"\n  const schema = useMemo(\n    () =>\n      facilityFormSchema({\n        takenCodes: takenKey ? takenKey.split(\"\\n\") : [],\n        goLiveDateRequired,\n        locked,\n      }),\n    [takenKey, goLiveDateRequired, locked]\n  )\n\n  const form = useAppForm({\n    defaultValues: facility,\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(toFacilityValues(value)),\n    onSubmitInvalid: () => onInvalid?.(),\n  })\n  const changes = useStore(form.store, (state) =>\n    facilityChanges(state.values, facility)\n  )\n\n  // Starts again only when the values differ, so an equal new object keeps the draft.\n  const facilityKey = JSON.stringify(facility)\n  const resetKey = useRef(facilityKey)\n  useEffect(() => {\n    if (resetKey.current === facilityKey) return\n    resetKey.current = facilityKey\n    form.reset(facility)\n  }, [form, facility, facilityKey])\n  // A code the server refused shows its error at once, rather than on the next submit.\n  useEffect(() => {\n    if (form.state.submissionAttempts === 0) return\n    form.update({ ...form.options, validators: { onDynamic: schema } })\n    void form.validate(\"change\")\n  }, [form, schema])\n  useEffect(() => {\n    onChangesChange?.(changes)\n  }, [changes, onChangesChange])\n\n  return (\n    <form\n      id={formId}\n      noValidate\n      onSubmit={(event) => {\n        event.preventDefault()\n        void form.handleSubmit()\n      }}\n    >\n      <FieldGroup>\n        <FacilityFormFields\n          form={form}\n          goLiveDateRequired={goLiveDateRequired}\n          locked={locked}\n          lookups={lookups}\n          readOnly={readOnly}\n        />\n      </FieldGroup>\n    </form>\n  )\n}\n\nfunction SwitchRowSkeleton({ label }: { label: string }) {\n  return (\n    <Field orientation=\"horizontal\">\n      <div className=\"flex min-h-8 flex-1 items-center\">\n        <FieldLabel>{label}</FieldLabel>\n      </div>\n      {/* A plain element, since Skeleton owns its corner radius and the switch is round. */}\n      <div className=\"h-4.5 w-8 shrink-0 animate-pulse rounded-full bg-muted\" />\n    </Field>\n  )\n}\n\n/** The form as it will look, so nothing moves when the facility arrives. */\nexport function FacilityGeneralFormSkeleton({\n  goLiveDateRequired = false,\n}: {\n  goLiveDateRequired?: boolean\n}) {\n  return (\n    <div aria-busy>\n      <FieldGroup>\n        <div className=\"grid gap-x-6 gap-y-5 @3xl/main:grid-cols-2\">\n          <FieldSkeleton label=\"Facility Name\" required />\n          <FieldSkeleton label=\"Facility Code\" required />\n          <FieldSkeleton label=\"Facility Type\" required />\n          <FieldSkeleton label=\"Geographic Zone\" required />\n          <FieldSkeleton\n            label=\"Operational Date\"\n            required={goLiveDateRequired}\n          />\n          <FieldSkeleton label=\"Facility Operator\" />\n          <FieldSkeleton label=\"Description\" />\n          <div className=\"@3xl/main:col-start-1\">\n            <SwitchRowSkeleton label=\"Active Facility\" />\n          </div>\n          <SwitchRowSkeleton label=\"Enabled\" />\n        </div>\n      </FieldGroup>\n    </div>\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/facility-editor-page/facility-general-form.tsx"
    },
    {
      "path": "registry/templates/openlmis/facility-editor-page/components/facility-program-dialog/facility-program-dialog.tsx",
      "content": "\"use client\"\n\nimport { revalidateLogic } from \"@tanstack/react-form\"\nimport { useMemo, useState } from \"react\"\n\nimport { FieldGroup } from \"@/components/ui/field\"\nimport {\n  FormDialog,\n  FormDialogBody,\n  FormDialogCancel,\n  FormDialogDescription,\n  FormDialogFooter,\n  FormDialogForm,\n  FormDialogHeader,\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 { FieldSkeleton } from \"@/components/openlmis/form-fields/form-fields\"\n\nimport {\n  addProgramSchema,\n  availablePrograms,\n  EMPTY_ADD_PROGRAM,\n  type FacilityProgram,\n  type ProgramOption,\n  programName,\n  toFacilityProgram,\n} from \"@/components/openlmis/facility-editor-page/facility-program\"\n\ntype FacilityProgramDialogProps = {\n  open: boolean\n  /** The facility's rows, so only programs it does not support yet are offered. */\n  rows: readonly FacilityProgram[]\n  /** Every program; the form shows a skeleton until they are set. */\n  programs: readonly ProgramOption[] | undefined\n  /** Called with the new row; add it, then close. */\n  onAdd: (row: FacilityProgram) => void\n  onClose: () => void\n}\n\n/** Add Program: a program the facility supports, and the date it starts. */\nexport function FacilityProgramDialog({\n  open,\n  onClose,\n  ...props\n}: FacilityProgramDialogProps) {\n  const { shown, dialogProps } = useDialogTarget(open || undefined, onClose)\n\n  return (\n    <FormDialog {...dialogProps()}>\n      {shown && <AddProgramContent {...props} />}\n    </FormDialog>\n  )\n}\n\nfunction AddProgramHeader() {\n  return (\n    <FormDialogHeader>\n      <FormDialogTitle>Add Program</FormDialogTitle>\n      <FormDialogDescription>\n        Choose a program this facility supports, and the date it starts.\n      </FormDialogDescription>\n    </FormDialogHeader>\n  )\n}\n\nfunction AddProgramContent({\n  programs,\n  ...props\n}: Omit<FacilityProgramDialogProps, \"open\" | \"onClose\">) {\n  if (!programs) {\n    return (\n      <>\n        <AddProgramHeader />\n        <FormDialogBody>\n          <div aria-busy>\n            <FieldGroup>\n              <FieldSkeleton label=\"Program\" required />\n              <FieldSkeleton label=\"Start Date\" required />\n            </FieldGroup>\n          </div>\n        </FormDialogBody>\n        <FormDialogFooter>\n          <FormDialogCancel />\n          <FormDialogSubmit disabled>Add</FormDialogSubmit>\n        </FormDialogFooter>\n      </>\n    )\n  }\n  return <AddProgramForm programs={programs} {...props} />\n}\n\nfunction AddProgramForm({\n  rows,\n  programs,\n  onAdd,\n}: Omit<FacilityProgramDialogProps, \"open\" | \"onClose\" | \"programs\"> & {\n  programs: readonly ProgramOption[]\n}) {\n  // The choices as the dialog opened, so the program just added never drops out while it closes.\n  const [rowsAtOpen] = useState(rows)\n  const items = useMemo(\n    () =>\n      availablePrograms(programs, rowsAtOpen).map((program) => ({\n        value: program.id,\n        label: programName(program),\n      })),\n    [programs, rowsAtOpen]\n  )\n\n  const form = useAppForm({\n    defaultValues: EMPTY_ADD_PROGRAM,\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: addProgramSchema },\n    onSubmit: ({ value }) => {\n      const program = programs.find((item) => item.id === value.programId)\n      if (program) onAdd(toFacilityProgram(program, value.startDate))\n    },\n  })\n\n  return (\n    <FormDialogForm onSubmit={() => void form.handleSubmit()}>\n      <AddProgramHeader />\n      <FormDialogBody>\n        <FieldGroup>\n          <form.AppField name=\"programId\">\n            {(field) => (\n              <field.ComboboxField\n                clearLabel=\"Clear Program\"\n                emptyMessage=\"No Matches\"\n                items={items}\n                label=\"Program\"\n                placeholder=\"Select A Program\"\n                required\n              />\n            )}\n          </form.AppField>\n          <form.AppField name=\"startDate\">\n            {(field) => (\n              <field.DateField\n                description=\"The program start date determines the first date available for users to enter requisitions related to the program.\"\n                label=\"Start Date\"\n                placeholder=\"Pick A Date\"\n                required\n              />\n            )}\n          </form.AppField>\n        </FieldGroup>\n      </FormDialogBody>\n      <FormDialogFooter>\n        <FormDialogCancel />\n        <FormDialogSubmit>Add</FormDialogSubmit>\n      </FormDialogFooter>\n    </FormDialogForm>\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/facility-editor-page/facility-program-dialog.tsx"
    },
    {
      "path": "registry/templates/openlmis/facility-editor-page/components/facility-program-dialog/facility-program.ts",
      "content": "import { z } from \"zod\"\n\n/** A program a facility can support. */\nexport type ProgramOption = {\n  id: string\n  code: string\n  name: string | null\n}\n\n/** A program the facility supports, and how. */\nexport type FacilityProgram = ProgramOption & {\n  supportActive: boolean\n  supportLocallyFulfilled: boolean\n  /** `yyyy-MM-dd`, or empty when a legacy record has none. */\n  supportStartDate: string\n  /** Already stored: it cannot be removed here, and may lack a start date. */\n  saved: boolean\n}\n\n/** The name a program is shown by: its name, or its code when it has none. */\nexport const programName = (program: Pick<ProgramOption, \"code\" | \"name\">) =>\n  program.name || program.code\n\nexport const addProgramSchema = z.object({\n  programId: z\n    .string()\n    .nullable()\n    .refine((value) => Boolean(value), \"Choose a program.\"),\n  startDate: z\n    .string()\n    .refine((value) => value.length > 0, \"Choose a start date.\"),\n})\n\nexport type AddProgramValues = z.input<typeof addProgramSchema>\n\nexport const EMPTY_ADD_PROGRAM: AddProgramValues = {\n  programId: null,\n  startDate: \"\",\n}\n\n/** A new row for `program`: active, not locally fulfilled, from `startDate`. */\nexport const toFacilityProgram = (\n  program: ProgramOption,\n  startDate: string\n): FacilityProgram => ({\n  ...program,\n  supportActive: true,\n  supportLocallyFulfilled: false,\n  supportStartDate: startDate,\n  saved: false,\n})\n\n/** Programs the facility does not support yet, by name. */\nexport function availablePrograms(\n  programs: readonly ProgramOption[],\n  rows: readonly FacilityProgram[]\n) {\n  const added = new Set(rows.map((row) => row.id))\n  return (\n    programs\n      .filter((program) => !added.has(program.id))\n      // oxlint-disable-next-line unicorn/no-array-sort -- sorts the filtered array without requiring ES2023\n      .sort((a, b) => programName(a).localeCompare(programName(b)))\n  )\n}\n\n/** Legacy stored some programs without a start date; only a new row must have one. */\nexport const missingStartDate = (row: FacilityProgram) =>\n  !row.saved && !row.supportStartDate",
      "type": "registry:lib",
      "target": "components/openlmis/facility-editor-page/facility-program.ts"
    },
    {
      "path": "registry/templates/openlmis/facility-editor-page/components/facility-programs/facility-programs.tsx",
      "content": "\"use client\"\n\nimport { BuildingIcon, PlusIcon, Trash2Icon } from \"lucide-react\"\nimport { useId, useRef, useState } from \"react\"\n\nimport { Button } from \"@/components/ui/button\"\nimport {\n  Empty,\n  EmptyDescription,\n  EmptyHeader,\n  EmptyMedia,\n  EmptyTitle,\n} from \"@/components/ui/empty\"\nimport { FieldError } from \"@/components/ui/field\"\nimport { Skeleton } from \"@/components/ui/skeleton\"\nimport { Switch } from \"@/components/ui/switch\"\nimport {\n  Table,\n  TableBody,\n  TableCell,\n  TableHead,\n  TableHeader,\n  TableRow,\n} from \"@/components/ui/table\"\nimport { DataTableCard } from \"@/components/blocks/openlmis/data-table/data-table\"\nimport {\n  type FacilityProgram,\n  missingStartDate,\n  type ProgramOption,\n  programName,\n} from \"@/components/openlmis/facility-editor-page/facility-program\"\nimport { FacilityProgramDialog } from \"@/components/openlmis/facility-editor-page/facility-program-dialog\"\nimport { DatePicker } from \"@/components/openlmis/date-picker/date-picker\"\n\ntype FacilityProgramsProps = {\n  /** The facility's programs; a skeleton shows until they are set. */\n  rows: readonly FacilityProgram[] | undefined\n  /** Every program, offered by Add Program; its form shows a skeleton until set. */\n  programs: readonly ProgramOption[] | undefined\n  /** Called with the rows after any change; keep them until the page saves. */\n  onRowsChange: (rows: FacilityProgram[]) => void\n  /** Marks new rows that still need a start date, e.g. after a submit. */\n  showErrors?: boolean\n  /** Shows the programs without letting them change. */\n  readOnly?: boolean\n}\n\nconst HEADINGS = [\"Program\", \"Active\", \"Start Date\", \"Locally Fulfilled\"]\n\n/** The programs a facility supports: switch them on and off, date them, add new ones. */\nexport function FacilityPrograms({\n  rows,\n  programs,\n  onRowsChange,\n  showErrors = false,\n  readOnly = false,\n}: FacilityProgramsProps) {\n  const idPrefix = useId()\n  const table = useRef<HTMLDivElement>(null)\n  const addButton = useRef<HTMLButtonElement>(null)\n  const [adding, setAdding] = useState(false)\n\n  if (!rows) return <FacilityProgramsSkeleton readOnly={readOnly} />\n\n  const update = (index: number, change: Partial<FacilityProgram>) =>\n    onRowsChange(\n      rows.map((row, at) => (at === index ? { ...row, ...change } : row))\n    )\n  const remove = (index: number) => {\n    onRowsChange(rows.filter((_, at) => at !== index))\n    // The pressed button is gone, so the next row's takes the focus, or Add Program.\n    requestAnimationFrame(() => {\n      const buttons = table.current?.querySelectorAll<HTMLElement>(\n        \"[data-remove-program]\"\n      )\n      const next = buttons?.[Math.min(index, buttons.length - 1)]\n      ;(next ?? addButton.current)?.focus()\n    })\n  }\n\n  return (\n    <div className=\"flex flex-col gap-4\">\n      {!readOnly && (\n        <div className=\"flex justify-end\">\n          <Button\n            onClick={() => setAdding(true)}\n            ref={addButton}\n            variant=\"outline\"\n          >\n            <PlusIcon data-icon=\"inline-start\" />\n            Add Program\n          </Button>\n        </div>\n      )}\n      <FacilityProgramDialog\n        onAdd={(row) => {\n          onRowsChange([...rows, row])\n          setAdding(false)\n        }}\n        onClose={() => setAdding(false)}\n        open={adding}\n        programs={programs}\n        rows={rows}\n      />\n      <div ref={table}>\n        <DataTableCard>\n          {rows.length === 0 ? (\n            <Empty>\n              <EmptyHeader>\n                <EmptyMedia variant=\"icon\">\n                  <BuildingIcon />\n                </EmptyMedia>\n                <EmptyTitle>No Programs Yet</EmptyTitle>\n                <EmptyDescription>\n                  {readOnly\n                    ? \"This facility does not support any program yet.\"\n                    : \"Add the programs this facility supports.\"}\n                </EmptyDescription>\n              </EmptyHeader>\n            </Empty>\n          ) : (\n            <Table>\n              <ProgramsHeader />\n              <TableBody>\n                {rows.map((row, index) => (\n                  <ProgramRow\n                    id={`${idPrefix}-${row.id}`}\n                    invalid={showErrors && missingStartDate(row)}\n                    key={row.id}\n                    onChange={(change) => update(index, change)}\n                    onRemove={() => remove(index)}\n                    readOnly={readOnly}\n                    row={row}\n                  />\n                ))}\n              </TableBody>\n            </Table>\n          )}\n        </DataTableCard>\n      </div>\n    </div>\n  )\n}\n\nfunction ProgramsHeader() {\n  return (\n    <TableHeader>\n      <TableRow>\n        {HEADINGS.map((heading) => (\n          <TableHead key={heading}>{heading}</TableHead>\n        ))}\n        <TableHead>\n          <span className=\"sr-only\">Actions</span>\n        </TableHead>\n      </TableRow>\n    </TableHeader>\n  )\n}\n\ntype ProgramRowProps = {\n  row: FacilityProgram\n  id: string\n  invalid: boolean\n  readOnly: boolean\n  onChange: (change: Partial<FacilityProgram>) => void\n  onRemove: () => void\n}\n\nfunction ProgramRow({\n  row,\n  id,\n  invalid,\n  readOnly,\n  onChange,\n  onRemove,\n}: ProgramRowProps) {\n  const name = programName(row)\n\n  return (\n    <TableRow>\n      <TableCell>\n        <span className=\"font-medium whitespace-normal\" dir=\"auto\">\n          {name}\n        </span>\n      </TableCell>\n      <TableCell>\n        <Switch\n          aria-label={`${name} Active`}\n          checked={row.supportActive}\n          disabled={readOnly}\n          onCheckedChange={(checked) => onChange({ supportActive: checked })}\n        />\n      </TableCell>\n      <TableCell>\n        <div className=\"flex min-w-44 flex-col gap-1\">\n          <span className=\"sr-only\" id={`${id}-label`}>\n            {name} Start Date\n          </span>\n          <DatePicker\n            describedBy={invalid ? `${id}-error` : undefined}\n            disabled={readOnly}\n            id={`${id}-start`}\n            invalid={invalid}\n            labelledBy={`${id}-label`}\n            onValueChange={(value) => onChange({ supportStartDate: value })}\n            placeholder=\"Pick A Date\"\n            required={!row.saved}\n            value={row.supportStartDate}\n          />\n          {invalid && (\n            <FieldError id={`${id}-error`}>Choose a start date.</FieldError>\n          )}\n        </div>\n      </TableCell>\n      <TableCell>\n        <Switch\n          aria-label={`${name} Locally Fulfilled`}\n          checked={row.supportLocallyFulfilled}\n          disabled={readOnly}\n          onCheckedChange={(checked) =>\n            onChange({ supportLocallyFulfilled: checked })\n          }\n        />\n      </TableCell>\n      <TableCell>\n        {!row.saved && !readOnly && (\n          <div className=\"flex justify-end\">\n            <Button\n              aria-label={`Remove ${name}`}\n              data-remove-program\n              onClick={onRemove}\n              size=\"icon-sm\"\n              variant=\"destructive\"\n            >\n              <Trash2Icon />\n            </Button>\n          </div>\n        )}\n      </TableCell>\n    </TableRow>\n  )\n}\n\nfunction FacilityProgramsSkeleton({ readOnly }: { readOnly: boolean }) {\n  return (\n    <div aria-busy className=\"flex flex-col gap-4\">\n      {!readOnly && (\n        <div className=\"flex justify-end\">\n          <Button disabled variant=\"outline\">\n            <PlusIcon data-icon=\"inline-start\" />\n            Add Program\n          </Button>\n        </div>\n      )}\n      <DataTableCard>\n        <Table>\n          <ProgramsHeader />\n          <TableBody>\n            {[0, 1, 2].map((row) => (\n              <TableRow key={row}>\n                <TableCell>\n                  <Skeleton className=\"h-4 w-28\" />\n                </TableCell>\n                <TableCell>\n                  <div className=\"h-4.5 w-8 animate-pulse rounded-full bg-muted\" />\n                </TableCell>\n                <TableCell>\n                  <Skeleton className=\"h-8 w-44\" />\n                </TableCell>\n                <TableCell>\n                  <div className=\"h-4.5 w-8 animate-pulse rounded-full bg-muted\" />\n                </TableCell>\n                <TableCell />\n              </TableRow>\n            ))}\n          </TableBody>\n        </Table>\n      </DataTableCard>\n    </div>\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/facility-editor-page/facility-programs.tsx"
    },
    {
      "path": "registry/templates/openlmis/facility-editor-page/components/mock-facility.ts",
      "content": "import type { FacilityValues } from \"@/components/openlmis/facility-editor-page/facility-form\"\nimport type { FacilityLookups } from \"@/components/openlmis/facility-editor-page/facility-form-fields\"\nimport type {\n  FacilityProgram,\n  ProgramOption,\n} from \"@/components/openlmis/facility-editor-page/facility-program\"\n\nexport type MockFacility = {\n  values: FacilityValues\n  programs: FacilityProgram[]\n  /** Another system owns its name, code, zone, description and Active. */\n  managedExternally: boolean\n}\n\nexport const MOCK_LOOKUPS: FacilityLookups = {\n  types: [\n    { id: \"health-center\", name: \"Health Center\" },\n    { id: \"district-hospital\", name: \"District Hospital\" },\n    { id: \"district-store\", name: \"District Store\" },\n    { id: \"warehouse\", name: \"Warehouse\" },\n  ],\n  zones: [\n    { id: \"malawi\", name: \"Malawi\", description: \"Country\" },\n    { id: \"southern\", name: \"Southern Region\", description: \"Region\" },\n    { id: \"balaka\", name: \"Balaka\", description: \"District\" },\n    { id: \"neno\", name: \"Neno\", description: \"District\" },\n  ],\n  operators: [\n    { id: \"moh\", name: \"Ministry of Health\" },\n    { id: \"chai\", name: \"CHAI\" },\n    { id: \"dwb\", name: \"Doctors Without Borders\" },\n  ],\n}\n\nexport const MOCK_PROGRAMS: ProgramOption[] = [\n  { id: \"family-planning\", code: \"PRG001\", name: \"Family Planning\" },\n  { id: \"essential-meds\", code: \"PRG002\", name: \"Essential Meds\" },\n  { id: \"new-program\", code: \"PRG003\", name: \"New Program\" },\n  { id: \"epi\", code: \"PRG004\", name: \"EPI\" },\n  { id: \"tb\", code: \"PRG005\", name: \"TB\" },\n]\n\n/** Codes other facilities already use. */\nexport const MOCK_TAKEN_CODES = [\"HC02\", \"HC03\", \"DH01\", \"W001\"]\n\nexport const MOCK_FACILITY: MockFacility = {\n  values: {\n    name: \"Comfort Health Clinic\",\n    code: \"HC01\",\n    typeId: \"health-center\",\n    zoneId: \"neno\",\n    goLiveDate: \"2017-01-01\",\n    description: \"\",\n    operatorId: \"moh\",\n    active: true,\n    enabled: true,\n  },\n  programs: [\n    {\n      id: \"family-planning\",\n      code: \"PRG001\",\n      name: \"Family Planning\",\n      supportActive: true,\n      supportLocallyFulfilled: false,\n      supportStartDate: \"2017-01-01\",\n      saved: true,\n    },\n    {\n      id: \"essential-meds\",\n      code: \"PRG002\",\n      name: \"Essential Meds\",\n      supportActive: true,\n      supportLocallyFulfilled: true,\n      // Legacy records may have no start date; a saved row keeps that.\n      supportStartDate: \"\",\n      saved: true,\n    },\n  ],\n  managedExternally: false,\n}\n\nexport const MOCK_MANAGED_FACILITY: MockFacility = {\n  values: {\n    name: \"Balaka District Hospital\",\n    code: \"DH01\",\n    typeId: \"district-hospital\",\n    zoneId: \"balaka\",\n    goLiveDate: \"2016-06-01\",\n    description: \"Synced from the national facility registry.\",\n    operatorId: \"moh\",\n    active: true,\n    enabled: true,\n  },\n  programs: [\n    {\n      id: \"epi\",\n      code: \"PRG004\",\n      name: \"EPI\",\n      supportActive: true,\n      supportLocallyFulfilled: false,\n      supportStartDate: \"2016-06-01\",\n      saved: true,\n    },\n  ],\n  managedExternally: true,\n}",
      "type": "registry:lib",
      "target": "components/openlmis/facility-editor-page/mock-facility.ts"
    },
    {
      "path": "registry/templates/openlmis/facility-editor-page/page.tsx",
      "content": "import { FacilityEditorPage } from \"@/components/openlmis/facility-editor-page/facility-editor-page\"\n\n// A Next.js App Router route; in any other React app, render FacilityEditorPage from your own route.\nexport default function Page() {\n  return <FacilityEditorPage />\n}",
      "type": "registry:page",
      "target": "app/facility-editor-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": "680px"
  },
  "categories": [
    "facilities"
  ],
  "type": "registry:page"
}
