{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "openlmis-lots-page",
  "title": "Lots Page",
  "description": "Mock lot list with product/expiry filters, paging and editable lot dialogs.",
  "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-combobox-filter.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-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-workspace.json"
  ],
  "files": [
    {
      "path": "registry/templates/openlmis/lots-page/components/lot-form-dialog/lot-form-dialog.tsx",
      "content": "\"use client\"\n\nimport { revalidateLogic } from \"@tanstack/react-form\"\nimport { type ReactNode, useEffect, useMemo } 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  type Lot,\n  type LotFormValues,\n  type LotProduct,\n  lotFormSchema,\n  toLotFormValues,\n} from \"@/components/openlmis/lots-page/lot-form\"\n\nconst NO_CODES: readonly string[] = []\n\nconst TITLE = \"Edit Lot\"\n\ntype LotFormDialogProps = {\n  /** The id of the lot to edit; opens the dialog while set. */\n  target: string | undefined\n  /** The lot being edited; a skeleton shows until it is set. */\n  lot?: Lot | undefined\n  /** The lot's product: `undefined` while it loads, `null` when no product has the lot's trade item. */\n  product?: LotProduct | null | undefined\n  /** Shown in place of the product when it could not be loaded. */\n  productError?: string | undefined\n  /** Codes the server refused as taken by another lot of the product. */\n  refusedCodes?: readonly string[]\n  /** The lot no longer exists. */\n  notFound?: boolean\n  /** Loading the lot 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: (values: LotFormValues, lot: Lot) => void\n  /** Keeps the dialog open and shows a spinner while the lot 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 LotFormDialog({\n  target,\n  lot,\n  product,\n  productError,\n  refusedCodes = NO_CODES,\n  notFound = false,\n  onRetry,\n  onSubmit,\n  pending = false,\n  error,\n  onClose,\n}: LotFormDialogProps) {\n  const { shown, dialogProps } = useDialogTarget(target, onClose)\n\n  return (\n    <FormDialog {...dialogProps(pending)}>\n      {shown &&\n        (notFound ? (\n          <>\n            <FormDialogHeader>\n              <FormDialogTitle>{TITLE}</FormDialogTitle>\n              <FormDialogDescription>\n                This lot 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 Lot\"\n            onRetry={onRetry}\n            title={TITLE}\n          />\n        ) : lot === undefined ? (\n          <LotFormSkeleton />\n        ) : (\n          <LotForm\n            error={error}\n            // Keyed, so opening another lot starts a fresh form.\n            key={lot.id}\n            lot={lot}\n            onSubmit={onSubmit}\n            pending={pending}\n            product={product}\n            productError={productError}\n            refusedCodes={refusedCodes}\n          />\n        ))}\n    </FormDialog>\n  )\n}\n\nfunction LotProductLine({\n  product,\n  error,\n}: Pick<LotFormDialogProps, \"product\"> & { error: string | undefined }) {\n  if (error) return <FormDialogDescription>{error}</FormDialogDescription>\n  if (product === undefined) return <SkeletonLine />\n  return (\n    <FormDialogDescription>\n      {product\n        ? `A lot of ${product.fullProductName} (${product.productCode}).`\n        : \"No product has this lot's trade item.\"}\n    </FormDialogDescription>\n  )\n}\n\ntype LotFormProps = Pick<\n  LotFormDialogProps,\n  \"product\" | \"productError\" | \"onSubmit\" | \"error\"\n> & {\n  lot: Lot\n  refusedCodes: readonly string[]\n  pending: boolean\n}\n\nfunction LotForm({\n  lot,\n  product,\n  productError,\n  refusedCodes,\n  onSubmit,\n  pending,\n  error,\n}: LotFormProps) {\n  const schema = useMemo(() => lotFormSchema(refusedCodes), [refusedCodes])\n\n  const form = useAppForm({\n    defaultValues: toLotFormValues(lot),\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, lot),\n  })\n\n  // A code the server just refused shows its error at once, without another submit.\n  useEffect(() => {\n    if (refusedCodes.length > 0) void form.validate(\"change\")\n  }, [refusedCodes, form])\n\n  return (\n    <FormDialogForm onSubmit={form.handleSubmit}>\n      <FormDialogHeader>\n        <FormDialogTitle>{TITLE}</FormDialogTitle>\n        <LotProductLine error={productError} product={product} />\n      </FormDialogHeader>\n      <FormDialogBody>\n        <FieldGroup>\n          {error && (\n            <FormDialogError description={error} title=\"Could Not Save Lot\" />\n          )}\n          <form.AppField name=\"lotCode\">\n            {(field) => (\n              <field.TextField\n                autoComplete=\"off\"\n                dir=\"ltr\"\n                label=\"Lot Code\"\n                required\n              />\n            )}\n          </form.AppField>\n          <form.AppField name=\"expirationDate\">\n            {(field) => (\n              <field.DateField\n                clearLabel=\"Clear Expiry Date\"\n                label=\"Expiry Date\"\n                placeholder=\"Pick A Date\"\n              />\n            )}\n          </form.AppField>\n          <form.AppField name=\"manufactureDate\">\n            {(field) => (\n              <field.DateField\n                clearLabel=\"Clear Manufacture Date\"\n                label=\"Manufacture Date\"\n                placeholder=\"Pick A Date\"\n              />\n            )}\n          </form.AppField>\n        </FieldGroup>\n      </FormDialogBody>\n      <FormDialogFooter>\n        <FormDialogCancel disabled={pending} />\n        <FormDialogSubmit pending={pending}>Save</FormDialogSubmit>\n      </FormDialogFooter>\n    </FormDialogForm>\n  )\n}\n\n/** Laid out like the form, so nothing moves when the lot arrives. */\nfunction LotFormSkeleton() {\n  return (\n    <>\n      <FormDialogHeader>\n        <FormDialogTitle>{TITLE}</FormDialogTitle>\n        <SkeletonLine />\n      </FormDialogHeader>\n      <FormDialogBody>\n        <div aria-busy>\n          <FieldGroup>\n            <FieldSkeleton label=\"Lot Code\" required />\n            <FieldSkeleton label=\"Expiry Date\" />\n            <FieldSkeleton label=\"Manufacture Date\" />\n          </FieldGroup>\n        </div>\n      </FormDialogBody>\n      <FormDialogFooter>\n        <FormDialogCancel />\n        <FormDialogSubmit disabled>Save</FormDialogSubmit>\n      </FormDialogFooter>\n    </>\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/lots-page/lot-form-dialog.tsx"
    },
    {
      "path": "registry/templates/openlmis/lots-page/components/lot-form-dialog/lot-form.ts",
      "content": "import { z } from \"zod\"\n\n/** A lot of a product, as OpenLMIS keeps it; dates are `yyyy-MM-dd`. */\nexport type Lot = {\n  id: string\n  lotCode: string\n  active: boolean\n  tradeItemId: string\n  expirationDate: string | null\n  manufactureDate: string | null\n}\n\n/** The product a lot belongs to, found through its trade item. */\nexport type LotProduct = {\n  id: string\n  productCode: string\n  fullProductName: string\n}\n\nconst MAX_CODE_LENGTH = 20\n\n// The characters GS1 allows in a lot number, which the server enforces.\nconst CODE_CHARACTERS = /^[!\"%&'()*+,\\-./0-9:;<=>?A-Z_a-z]*$/\n\n/** `refusedCodes` are codes the server said another lot of the product has. */\nexport function lotFormSchema(refusedCodes: readonly string[]) {\n  const refused = new Set(refusedCodes.map((code) => code.toLowerCase()))\n  return z.object({\n    lotCode: z\n      .string()\n      .refine((code) => code.trim().length > 0, \"Enter a lot code.\")\n      .refine(\n        (code) => code.length <= MAX_CODE_LENGTH,\n        \"Use at most 20 characters.\"\n      )\n      .refine(\n        (code) => CODE_CHARACTERS.test(code),\n        \"Use only letters, digits and ! \\\" % & ' ( ) * + , - . / : ; < = > ? _\"\n      )\n      .refine(\n        (code) => !refused.has(code.toLowerCase()),\n        \"Another lot of this product already has this code.\"\n      ),\n    expirationDate: z.string(),\n    manufactureDate: z.string(),\n  })\n}\n\nexport type LotFormValues = z.infer<ReturnType<typeof lotFormSchema>>\n\nexport function toLotFormValues(lot: Lot): LotFormValues {\n  return {\n    lotCode: lot.lotCode,\n    expirationDate: lot.expirationDate ?? \"\",\n    manufactureDate: lot.manufactureDate ?? \"\",\n  }\n}\n\n/** The saved lot with the form's values; an empty date is no date. */\nexport function toLot(values: LotFormValues, saved: Lot): Lot {\n  return {\n    ...saved,\n    lotCode: values.lotCode,\n    expirationDate: values.expirationDate || null,\n    manufactureDate: values.manufactureDate || null,\n  }\n}",
      "type": "registry:lib",
      "target": "components/openlmis/lots-page/lot-form.ts"
    },
    {
      "path": "registry/templates/openlmis/lots-page/components/lots-page.tsx",
      "content": "\"use client\"\n\nimport type {\n  ColumnVisibilityState,\n  PaginationState,\n} from \"@tanstack/react-table\"\nimport { BoxesIcon } from \"lucide-react\"\nimport { useCallback, useMemo, useState } from \"react\"\n\nimport {\n  useColumnVisibility,\n  useContainerSize,\n} from \"@/components/blocks/openlmis/data-table/responsive-columns\"\nimport type { Lot, LotFormValues } from \"@/components/openlmis/lots-page/lot-form\"\nimport { toLot } from \"@/components/openlmis/lots-page/lot-form\"\nimport { LotFormDialog } from \"@/components/openlmis/lots-page/lot-form-dialog\"\nimport { LOT_HIDEABLE_COLUMNS } from \"@/components/openlmis/lots-page/lots\"\nimport { LotsTable } from \"@/components/openlmis/lots-page/lots-table\"\nimport { type LotsFilters, LotsToolbar } from \"@/components/openlmis/lots-page/lots-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\"\n\nimport { MOCK_LOTS, MOCK_PRODUCTS } from \"@/components/openlmis/lots-page/mock-lots\"\n\nconst NO_FILTERS: LotsFilters = { product: \"\", expiryFrom: \"\", expiryTo: \"\" }\n\ntype Notice = { title: string; description: string }\n\n/** The lots screen; mount it from any route, e.g. the `page.tsx` this template ships. */\nexport function LotsPage() {\n  const [lots, setLots] = useState(MOCK_LOTS)\n  const [filters, setFilters] = useState(NO_FILTERS)\n  const [pagination, setPagination] = useState<PaginationState>({\n    pageIndex: 0,\n    pageSize: 10,\n  })\n  const [typed, setTyped] = useState(\"\")\n  const [editing, setEditing] = useState<string>()\n  const [refused, setRefused] = useState<string[]>([])\n  const [notice, setNotice] = useState<Notice>()\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    LOT_HIDEABLE_COLUMNS,\n    columnChoices,\n    contentSize\n  )\n\n  // Every lot is in memory, so filtering and paging happen here.\n  const matching = useMemo(\n    () =>\n      lots.filter(\n        (lot) =>\n          (!filters.product || lot.product?.id === filters.product) &&\n          (!filters.expiryFrom ||\n            (lot.expirationDate !== null &&\n              lot.expirationDate >= filters.expiryFrom)) &&\n          (!filters.expiryTo ||\n            (lot.expirationDate !== null &&\n              lot.expirationDate <= filters.expiryTo))\n      ),\n    [lots, filters]\n  )\n  const lastPage = Math.max(\n    0,\n    Math.ceil(matching.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 rows = useMemo(\n    () =>\n      matching.slice(\n        page.pageIndex * page.pageSize,\n        (page.pageIndex + 1) * page.pageSize\n      ),\n    [matching, page]\n  )\n\n  const query = typed.trim().toLowerCase()\n  const found = MOCK_PRODUCTS.filter(\n    (product) =>\n      !query ||\n      product.fullProductName.toLowerCase().includes(query) ||\n      product.productCode.toLowerCase().includes(query)\n  )\n  // The picked product stays first, so the filter can show its name.\n  const picked = MOCK_PRODUCTS.find((product) => product.id === filters.product)\n  const options = [\n    ...(picked ? [picked] : []),\n    ...found.filter((product) => product.id !== picked?.id),\n  ].map((product) => ({\n    value: product.id,\n    label: product.fullProductName,\n    description: product.productCode,\n  }))\n\n  const updateFilters = (patch: Partial<LotsFilters>) => {\n    setFilters((current) => ({ ...current, ...patch }))\n    setPagination((current) => ({ ...current, pageIndex: 0 }))\n  }\n  const onEdit = useCallback((id: string) => {\n    setNotice(undefined)\n    setRefused([])\n    setEditing(id)\n  }, [])\n  const editingLot = lots.find((lot) => lot.id === editing)\n\n  const save = (values: LotFormValues, saved: Lot) => {\n    // Lot codes are unique per product, as the server enforces.\n    const taken = lots.some(\n      (lot) =>\n        lot.id !== saved.id &&\n        lot.tradeItemId === saved.tradeItemId &&\n        lot.lotCode.toLowerCase() === values.lotCode.toLowerCase()\n    )\n    if (taken) {\n      setRefused((codes) => [...codes, values.lotCode])\n      return\n    }\n    setLots((current) =>\n      current.map((lot) =>\n        lot.id === saved.id ? { ...lot, ...toLot(values, saved) } : lot\n      )\n    )\n    setNotice({\n      title: \"Lot Saved\",\n      description: `Changes to ${values.lotCode} are saved.`,\n    })\n    setEditing(undefined)\n  }\n\n  return (\n    <Workspace>\n      <WorkspaceHeader>\n        <WorkspaceHeading>\n          <WorkspaceIcon>\n            <BoxesIcon />\n          </WorkspaceIcon>\n          <WorkspaceTitle>Lots</WorkspaceTitle>\n          <WorkspaceDescription>\n            Batches of products, with their codes and expiry dates.\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          <LotsToolbar\n            columnView={columnView}\n            filters={filters}\n            onFiltersChange={updateFilters}\n            onProductSearch={setTyped}\n            productOptions={options}\n            productTotal={found.length}\n          />\n          <LotsTable\n            columnVisibility={columnView.visibility}\n            filtered={Boolean(\n              filters.product || filters.expiryFrom || filters.expiryTo\n            )}\n            lots={rows}\n            onClearFilters={() => updateFilters(NO_FILTERS)}\n            onEdit={onEdit}\n            onPaginationChange={setPagination}\n            pagination={page}\n            rowCount={matching.length}\n          />\n        </div>\n      </WorkspaceContent>\n      <LotFormDialog\n        lot={editingLot}\n        onClose={() => setEditing(undefined)}\n        onSubmit={save}\n        product={editingLot?.product ?? null}\n        refusedCodes={refused}\n        target={editing}\n      />\n    </Workspace>\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/lots-page/lots-page.tsx"
    },
    {
      "path": "registry/templates/openlmis/lots-page/components/lots-table/lots-table.tsx",
      "content": "\"use client\"\n\nimport {\n  createColumnHelper,\n  type ColumnVisibilityState,\n  functionalUpdate,\n  type PaginationState,\n  useTable,\n} from \"@tanstack/react-table\"\nimport { BoxesIcon, EllipsisIcon, PencilIcon, SearchXIcon } from \"lucide-react\"\nimport { useMemo } from \"react\"\n\nimport { Button } from \"@/components/ui/button\"\nimport {\n  DropdownMenu,\n  DropdownMenuContent,\n  DropdownMenuItem,\n  DropdownMenuTrigger,\n} from \"@/components/ui/dropdown-menu\"\nimport {\n  DataTable,\n  DataTableColumnHeader,\n  DataTableEmpty,\n  DataTableError,\n  type DataTableFeatures,\n  DataTablePagination,\n  DataTableSkeleton,\n  dataTableFeatures,\n} from \"@/components/blocks/openlmis/data-table/data-table\"\nimport { useMenuOpensDialog } from \"@/components/blocks/openlmis/data-table/row-actions\"\nimport { formatDateValue } from \"@/components/openlmis/date-picker/date-value\"\n\nimport type { LotRow } from \"@/components/openlmis/lots-page/lots\"\n\nconst columnHelper = createColumnHelper<DataTableFeatures, LotRow>()\n\nconst muted = (text: string) => (\n  <span className=\"text-muted-foreground\">{text}</span>\n)\n\nfunction createColumns(\n  dateLanguage: string,\n  onEdit: ((id: string) => void) | undefined\n) {\n  const date = (value: string | null) =>\n    value ? formatDateValue(value, dateLanguage) : muted(\"-\")\n  return columnHelper.columns([\n    columnHelper.accessor((lot) => lot.product?.productCode ?? \"\", {\n      id: \"productCode\",\n      header: ({ column }) => (\n        <DataTableColumnHeader column={column} title=\"Product Code\" />\n      ),\n      cell: ({ getValue }) =>\n        getValue() ? (\n          <span className=\"flex\">\n            <span className=\"min-w-0 truncate\" dir=\"ltr\">\n              {getValue()}\n            </span>\n          </span>\n        ) : (\n          muted(\"-\")\n        ),\n      meta: { className: \"w-40\" },\n    }),\n    columnHelper.accessor((lot) => lot.product?.fullProductName ?? \"\", {\n      id: \"productName\",\n      header: ({ column }) => (\n        <DataTableColumnHeader column={column} title=\"Product Name\" />\n      ),\n      cell: ({ row, getValue }) =>\n        !row.original.product ? (\n          muted(\"No Product\")\n        ) : getValue() ? (\n          <span className=\"block break-words whitespace-normal\" dir=\"auto\">\n            {getValue()}\n          </span>\n        ) : (\n          muted(\"-\")\n        ),\n    }),\n    columnHelper.accessor(\"lotCode\", {\n      header: ({ column }) => (\n        <DataTableColumnHeader column={column} title=\"Lot 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: \"w-36 @xl/table:w-44\" },\n    }),\n    columnHelper.accessor(\"expirationDate\", {\n      header: ({ column }) => (\n        <DataTableColumnHeader column={column} title=\"Expiry Date\" />\n      ),\n      cell: ({ getValue }) => date(getValue()),\n      meta: { className: \"w-36\" },\n    }),\n    columnHelper.accessor(\"manufactureDate\", {\n      header: ({ column }) => (\n        <DataTableColumnHeader column={column} title=\"Manufacture Date\" />\n      ),\n      cell: ({ getValue }) => date(getValue()),\n      meta: { className: \"w-40\" },\n    }),\n    ...(onEdit\n      ? [\n          columnHelper.display({\n            id: \"actions\",\n            header: () => <span className=\"sr-only\">Actions</span>,\n            cell: ({ row }) => (\n              <LotActions lot={row.original} onEdit={onEdit} />\n            ),\n            meta: { className: \"w-16\" },\n          }),\n        ]\n      : []),\n  ])\n}\n\nfunction LotActions({\n  lot,\n  onEdit,\n}: {\n  lot: LotRow\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 ${lot.lotCode}`}\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          <DropdownMenuItem onClick={menu.opensDialog(() => onEdit(lot.id))}>\n            <PencilIcon />\n            Edit\n          </DropdownMenuItem>\n        </DropdownMenuContent>\n      </DropdownMenu>\n    </div>\n  )\n}\n\nconst ALL_COLUMNS: ColumnVisibilityState = {}\n\nconst NO_LOTS: LotRow[] = []\n\nconst getRowId = (lot: LotRow) => lot.id\n\ntype LotsTableProps = {\n  /** One page of lots; a skeleton shows until it is set. */\n  lots: readonly LotRow[] | undefined\n  /** Every lot that matches the filters, across all pages. */\n  rowCount: number\n  pagination: PaginationState\n  onPaginationChange: (pagination: PaginationState) => void\n  columnVisibility?: ColumnVisibilityState\n  /** Whether a filter is set, so an empty list offers to clear them. */\n  filtered?: boolean\n  onClearFilters?: () => void\n  /** Without it, the row menu is left out. */\n  onEdit?: ((id: string) => void) | undefined\n  /** Dims the rows while the next page loads. */\n  isStale?: boolean\n  /** Loading failed; shows the error with Try Again. */\n  onRetry?: (() => void) | undefined\n  /** The language dates are shown in. */\n  dateLanguage?: string\n}\n\n/** Lots with their product and dates, a page at a time; filtering and paging are left to the caller, who must clamp `pageIndex` to the last page when rows shrink. */\nexport function LotsTable({\n  lots,\n  rowCount,\n  pagination,\n  onPaginationChange,\n  columnVisibility = ALL_COLUMNS,\n  filtered = false,\n  onClearFilters,\n  onEdit,\n  isStale = false,\n  onRetry,\n  dateLanguage = \"en-US\",\n}: LotsTableProps) {\n  const columns = useMemo(\n    () => createColumns(dateLanguage, onEdit),\n    [dateLanguage, onEdit]\n  )\n  const table = useTable({\n    features: dataTableFeatures,\n    columns,\n    data: (lots ?? NO_LOTS) as LotRow[],\n    getRowId,\n    rowCount,\n    manualPagination: true,\n    manualSorting: true,\n    enableSorting: false,\n    state: { pagination, columnVisibility },\n    onPaginationChange: (updater) =>\n      onPaginationChange(functionalUpdate(updater, pagination)),\n  })\n\n  if (onRetry)\n    return (\n      <DataTableError\n        description=\"Something went wrong while loading the lots. Try again.\"\n        onRetry={onRetry}\n        title=\"Could Not Load Lots\"\n      />\n    )\n  if (lots === undefined)\n    return <DataTableSkeleton rowCount={pagination.pageSize} table={table} />\n\n  return (\n    <DataTable\n      empty={\n        filtered ? (\n          <DataTableEmpty\n            action={\n              onClearFilters && (\n                <Button onClick={onClearFilters} variant=\"destructive\">\n                  Clear Filters\n                </Button>\n              )\n            }\n            description=\"Try a different product or dates, or clear the filters.\"\n            icon={<SearchXIcon />}\n            title=\"No Matching Lots\"\n          />\n        ) : (\n          <DataTableEmpty\n            description=\"Lots appear here once stock is received or counted for them.\"\n            icon={<BoxesIcon />}\n            title=\"No Lots Yet\"\n          />\n        )\n      }\n      footer={rowCount > 0 && <DataTablePagination table={table} />}\n      isStale={isStale}\n      table={table}\n    />\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/lots-page/lots-table.tsx"
    },
    {
      "path": "registry/templates/openlmis/lots-page/components/lots-table/lots-toolbar.tsx",
      "content": "\"use client\"\n\nimport { ListToolbar } from \"@/components/blocks/openlmis/list-toolbar\"\nimport {\n  type ColumnVisibility,\n  ColumnViewOptions,\n} from \"@/components/openlmis/column-view-options\"\nimport {\n  ComboboxFilter,\n  type ComboboxFilterOption,\n} from \"@/components/openlmis/combobox-filter/combobox-filter\"\nimport { DatePicker } from \"@/components/openlmis/date-picker/date-picker\"\n\nimport { LOT_HIDEABLE_COLUMNS } from \"@/components/openlmis/lots-page/lots\"\n\nexport type LotsFilters = {\n  /** The product id, or an empty string for any product. */\n  product: string\n  /** `yyyy-MM-dd`, or an empty string for no bound. */\n  expiryFrom: string\n  expiryTo: string\n}\n\ntype LotsToolbarProps = {\n  filters: LotsFilters\n  onFiltersChange: (patch: Partial<LotsFilters>) => void\n  /** The products found for what was typed, with the picked one first. */\n  productOptions: ComboboxFilterOption[]\n  productTotal?: number\n  /** Called with what is typed in the product filter; debounce before searching. */\n  onProductSearch?: (text: string) => void\n  /** While a search runs, the list says so instead of showing no matches. */\n  searching?: boolean\n  /** Shown in the list when the product search failed. */\n  searchError?: string | undefined\n  columnView: {\n    visibility: ColumnVisibility\n    onVisibilityChange: (visibility: ColumnVisibility) => void\n    onReset?: () => void\n  }\n  dateLanguage?: string\n}\n\n/** A product picker, an expiry window and the View menu, above `LotsTable`. */\nexport function LotsToolbar({\n  filters,\n  onFiltersChange,\n  productOptions,\n  productTotal,\n  onProductSearch,\n  searching = false,\n  searchError,\n  columnView,\n  dateLanguage,\n}: LotsToolbarProps) {\n  return (\n    <ListToolbar>\n      <div className=\"w-full @2xl/toolbar:w-72\">\n        <ComboboxFilter\n          emptyMessage={\n            searching ? \"Searching...\" : (searchError ?? \"No Matches\")\n          }\n          label=\"Product\"\n          onSearch={onProductSearch}\n          onValueChange={(product) => onFiltersChange({ product })}\n          options={productOptions}\n          total={productTotal}\n          value={filters.product}\n        />\n      </div>\n      <div className=\"min-w-64 flex-1 @2xl/toolbar:max-w-80\">\n        <DatePicker\n          clearLabel=\"Clear Earliest Expiry Date\"\n          dateLanguage={dateLanguage}\n          id=\"lots-earliest-expiry\"\n          label=\"Earliest Expiry Date\"\n          latest={filters.expiryTo || undefined}\n          onValueChange={(expiryFrom) => onFiltersChange({ expiryFrom })}\n          placeholder=\"Earliest Expiry Date\"\n          value={filters.expiryFrom}\n        />\n      </div>\n      <div className=\"min-w-64 flex-1 @2xl/toolbar:max-w-80\">\n        <DatePicker\n          clearLabel=\"Clear Latest Expiry Date\"\n          dateLanguage={dateLanguage}\n          earliest={filters.expiryFrom || undefined}\n          id=\"lots-latest-expiry\"\n          label=\"Latest Expiry Date\"\n          onValueChange={(expiryTo) => onFiltersChange({ expiryTo })}\n          placeholder=\"Latest Expiry Date\"\n          value={filters.expiryTo}\n        />\n      </div>\n      <div className=\"@2xl/toolbar:ms-auto\">\n        <ColumnViewOptions\n          columns={LOT_HIDEABLE_COLUMNS}\n          onReset={columnView.onReset}\n          onVisibilityChange={columnView.onVisibilityChange}\n          visibility={columnView.visibility}\n        />\n      </div>\n    </ListToolbar>\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/lots-page/lots-toolbar.tsx"
    },
    {
      "path": "registry/templates/openlmis/lots-page/components/lots-table/lots.ts",
      "content": "import type { ResponsiveColumn } from \"@/components/blocks/openlmis/data-table/responsive-columns\"\nimport type { Lot, LotProduct } from \"@/components/openlmis/lots-page/lot-form\"\n\n/** A lot with the product of its trade item, or `null` when no product has it. */\nexport type LotRow = Lot & { product: LotProduct | null }\n\n/** The columns the View menu lists, in order; the lot code always shows. */\nexport const LOT_HIDEABLE_COLUMNS: (ResponsiveColumn & { label: string })[] = [\n  { id: \"productCode\", label: \"Product Code\", hideBelow: \"3xl\" },\n  { id: \"productName\", label: \"Product Name\" },\n  { id: \"expirationDate\", label: \"Expiry Date\", hideBelow: \"lg\" },\n  { id: \"manufactureDate\", label: \"Manufacture Date\", hideBelow: \"2xl\" },\n]",
      "type": "registry:lib",
      "target": "components/openlmis/lots-page/lots.ts"
    },
    {
      "path": "registry/templates/openlmis/lots-page/components/mock-lots.ts",
      "content": "import type { LotProduct } from \"@/components/openlmis/lots-page/lot-form\"\nimport type { LotRow } from \"@/components/openlmis/lots-page/lots\"\n\nexport const MOCK_PRODUCTS: LotProduct[] = [\n  { id: \"p-bcg\", productCode: \"C100\", fullProductName: \"BCG Vaccine\" },\n  {\n    id: \"p-mr\",\n    productCode: \"C101\",\n    fullProductName: \"Measles Rubella Vaccine, 10 dose vial\",\n  },\n  { id: \"p-pcv\", productCode: \"C102\", fullProductName: \"PCV-13\" },\n  { id: \"p-opv\", productCode: \"C103\", fullProductName: \"Oral Polio Vaccine\" },\n  {\n    id: \"p-penta\",\n    productCode: \"C104\",\n    fullProductName: \"Pentavalent Vaccine\",\n  },\n  { id: \"p-rota\", productCode: \"C105\", fullProductName: \"Rotavirus Vaccine\" },\n  { id: \"p-tt\", productCode: \"C106\", fullProductName: \"Tetanus Toxoid\" },\n  {\n    id: \"p-syringe\",\n    productCode: \"S200\",\n    fullProductName: \"AD Syringe 0.5 ml\",\n  },\n]\n\nconst product = (id: string) =>\n  MOCK_PRODUCTS.find((item) => item.id === id) ?? null\n\nconst LOT_SEEDS: [string, string, string | null, string | null][] = [\n  [\"p-bcg\", \"BCG-2026-A1\", \"2027-03-31\", \"2025-09-15\"],\n  [\"p-bcg\", \"BCG-2026-A2\", \"2027-06-30\", \"2025-12-01\"],\n  [\"p-mr\", \"MR-0425\", \"2026-12-01\", null],\n  [\"p-mr\", \"MR-0612\", \"2027-08-20\", \"2026-02-10\"],\n  [\"p-pcv\", \"PCV13-7781\", \"2028-01-15\", \"2025-11-02\"],\n  [\"p-pcv\", \"PCV13-7802\", \"2028-04-01\", \"2026-01-20\"],\n  [\"p-opv\", \"OPV-B33\", \"2026-11-15\", \"2025-05-05\"],\n  [\"p-penta\", \"PENTA-2291\", \"2027-02-28\", \"2025-08-12\"],\n  [\"p-penta\", \"PENTA-2310\", \"2027-10-31\", null],\n  [\"p-rota\", \"ROTA-118\", \"2027-05-31\", \"2025-10-01\"],\n  [\"p-tt\", \"TT-55A\", \"2029-01-01\", \"2026-03-15\"],\n  [\"p-syringe\", \"ADS-9001\", null, \"2026-04-01\"],\n]\n\nexport const MOCK_LOTS: LotRow[] = [\n  ...LOT_SEEDS.map(\n    ([productId, lotCode, expirationDate, manufactureDate], index) => ({\n      id: `lot-${index + 1}`,\n      lotCode,\n      active: true,\n      tradeItemId: `trade-${productId}`,\n      expirationDate,\n      manufactureDate,\n      product: product(productId),\n    })\n  ),\n  // No product has this trade item, so the table says so.\n  {\n    id: \"lot-orphan\",\n    lotCode: \"LEGACY-0001\",\n    active: true,\n    tradeItemId: \"trade-retired\",\n    expirationDate: \"2026-12-31\",\n    manufactureDate: null,\n    product: null,\n  },\n]",
      "type": "registry:lib",
      "target": "components/openlmis/lots-page/mock-lots.ts"
    },
    {
      "path": "registry/templates/openlmis/lots-page/page.tsx",
      "content": "import { LotsPage } from \"@/components/openlmis/lots-page/lots-page\"\n\n// A Next.js App Router route; in any other React app, render LotsPage from your own route.\nexport default function Page() {\n  return <LotsPage />\n}",
      "type": "registry:page",
      "target": "app/lots-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": "747px"
  },
  "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"
}
