{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "openlmis-home-dashboard",
  "title": "Home Dashboard",
  "description": "OpenLMIS home screen on mock data: a greeting with what is waiting, Add User, system notices, a stat strip, requisitions by period and by status, cold chain equipment and the approvals queue, each shown only when the user's rights allow.",
  "dependencies": [
    "lucide-react@^1",
    "recharts@^3",
    "@base-ui/react@^1"
  ],
  "registryDependencies": [
    "alert",
    "badge",
    "button",
    "chart",
    "empty",
    "skeleton",
    "table",
    "https://registry.soldevelo.com/r/openlmis-dashboard-card.json",
    "https://registry.soldevelo.com/r/openlmis-segmented-meter.json",
    "https://registry.soldevelo.com/r/openlmis-stat-strip.json",
    "https://registry.soldevelo.com/r/openlmis-status-meter-list.json",
    "https://registry.soldevelo.com/r/openlmis-workspace.json"
  ],
  "files": [
    {
      "path": "registry/templates/openlmis/home-dashboard/components/approvals-table/approvals-table.tsx",
      "content": "import { CircleCheckIcon } from \"lucide-react\"\n\nimport { Badge } from \"@/components/ui/badge\"\nimport {\n  Empty,\n  EmptyDescription,\n  EmptyHeader,\n  EmptyMedia,\n  EmptyTitle,\n} from \"@/components/ui/empty\"\nimport { Skeleton } from \"@/components/ui/skeleton\"\nimport {\n  Table,\n  TableBody,\n  TableCell,\n  TableHead,\n  TableHeader,\n  TableRow,\n} from \"@/components/ui/table\"\nimport {\n  DashboardCard,\n  DashboardCardCount,\n  DashboardCardError,\n} from \"@/components/blocks/openlmis/dashboard-card\"\n\n/** A requisition waiting on the user; map your API's requisitions onto it. */\nexport type ApprovalRequisition = {\n  id: string\n  emergency: boolean\n  program: { name: string }\n  facility: { code: string; name: string }\n  processingPeriod: { name: string }\n  /** When it reached this approver, as an ISO date. */\n  waitingSince: string\n}\n\ntype ApprovalsTableProps = {\n  /** Most urgent first; a placeholder shows until it is set. */\n  requisitions: readonly ApprovalRequisition[] | undefined\n  /** All that are waiting, when `requisitions` is only the first page of them. */\n  total?: number\n  failed?: boolean\n  onRetry?: () => void\n}\n\n// A fixed locale and time zone, so a server render and the browser print the same date.\nconst formatDate = new Intl.DateTimeFormat(\"en-US\", {\n  dateStyle: \"medium\",\n  timeZone: \"UTC\",\n}).format\n\n/** The requisitions waiting on this user: a table with room, two lines each on a narrow card. */\nexport function ApprovalsTable({\n  requisitions,\n  total = requisitions?.length,\n  failed = false,\n  onRetry,\n}: ApprovalsTableProps) {\n  return (\n    <DashboardCard\n      badge={<DashboardCardCount failed={failed} value={total} />}\n      description=\"Requisitions waiting for your approval, emergencies first.\"\n      title=\"Awaiting Your Approval\"\n    >\n      {failed && onRetry ? (\n        <DashboardCardError onRetry={onRetry} />\n      ) : requisitions === undefined ? (\n        <div aria-busy className=\"flex flex-col gap-3\">\n          {[\"a\", \"b\", \"c\", \"d\", \"e\"].map((row) => (\n            <Skeleton className=\"h-10 w-full\" key={row} />\n          ))}\n        </div>\n      ) : requisitions.length === 0 ? (\n        <Empty>\n          <EmptyHeader>\n            <EmptyMedia variant=\"icon\">\n              <CircleCheckIcon />\n            </EmptyMedia>\n            <EmptyTitle>Nothing To Approve</EmptyTitle>\n            <EmptyDescription>\n              Requisitions that need your approval appear here.\n            </EmptyDescription>\n          </EmptyHeader>\n        </Empty>\n      ) : (\n        // Its own container, so the layout follows the card's width; the hidden one is out of the accessibility tree.\n        <div className=\"@container/approvals\">\n          <div className=\"hidden @xl/approvals:block\">\n            <ApprovalsGrid requisitions={requisitions} />\n          </div>\n          <div className=\"@xl/approvals:hidden\">\n            <ApprovalsList requisitions={requisitions} />\n          </div>\n        </div>\n      )}\n    </DashboardCard>\n  )\n}\n\nfunction EmergencyBadge({ emergency }: { emergency: boolean }) {\n  return emergency ? <Badge variant=\"destructive\">Emergency</Badge> : null\n}\n\nfunction ApprovalsGrid({\n  requisitions,\n}: {\n  requisitions: readonly ApprovalRequisition[]\n}) {\n  return (\n    <Table>\n      <TableHeader>\n        <TableRow>\n          <TableHead>Program</TableHead>\n          <TableHead>Facility</TableHead>\n          <TableHead>Period</TableHead>\n          <TableHead>Waiting Since</TableHead>\n        </TableRow>\n      </TableHeader>\n      <TableBody>\n        {requisitions.map((requisition) => (\n          <TableRow key={requisition.id}>\n            <TableCell>\n              <div className=\"flex items-center gap-2\">\n                <span className=\"font-medium\">{requisition.program.name}</span>\n                <EmergencyBadge emergency={requisition.emergency} />\n              </div>\n            </TableCell>\n            <TableCell>\n              <div className=\"flex flex-col\">\n                <span>{requisition.facility.name}</span>\n                <span className=\"text-xs text-muted-foreground\">\n                  {requisition.facility.code}\n                </span>\n              </div>\n            </TableCell>\n            <TableCell>{requisition.processingPeriod.name}</TableCell>\n            <TableCell>\n              <span className=\"text-muted-foreground\">\n                {formatDate(new Date(requisition.waitingSince))}\n              </span>\n            </TableCell>\n          </TableRow>\n        ))}\n      </TableBody>\n    </Table>\n  )\n}\n\n/** Two lines per requisition: where and since when, then what for. */\nfunction ApprovalsList({\n  requisitions,\n}: {\n  requisitions: readonly ApprovalRequisition[]\n}) {\n  return (\n    <ul className=\"flex flex-col divide-y\">\n      {requisitions.map((requisition) => (\n        <li\n          className=\"flex flex-col gap-1 py-3 first:pt-0 last:pb-0\"\n          key={requisition.id}\n        >\n          <div className=\"flex items-baseline justify-between gap-3\">\n            {/* Separate items, so the gap holds even where Latin names sit in a right-to-left line. */}\n            <span className=\"flex min-w-0 items-baseline gap-1.5\">\n              <span className=\"truncate text-sm font-medium\">\n                {requisition.facility.name}\n              </span>\n              <span className=\"shrink-0 text-xs text-muted-foreground\">\n                {requisition.facility.code}\n              </span>\n            </span>\n            <span className=\"shrink-0 text-xs text-muted-foreground\">\n              <span className=\"sr-only\">Waiting since </span>\n              {formatDate(new Date(requisition.waitingSince))}\n            </span>\n          </div>\n          <div className=\"flex items-center gap-2 text-sm text-muted-foreground\">\n            {/* Only the program gives way; the period stays whole, and the dot reads as a comma. */}\n            <span className=\"flex min-w-0 items-baseline gap-1.5\">\n              <span className=\"truncate\">{requisition.program.name}</span>\n              <span aria-hidden=\"true\">·</span>\n              <span className=\"sr-only\">, </span>\n              <span className=\"shrink-0\">\n                {requisition.processingPeriod.name}\n              </span>\n            </span>\n            <EmergencyBadge emergency={requisition.emergency} />\n          </div>\n        </li>\n      ))}\n    </ul>\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/home-dashboard/approvals-table.tsx"
    },
    {
      "path": "registry/templates/openlmis/home-dashboard/components/equipment-status/equipment-status.tsx",
      "content": "\"use client\"\n\nimport {\n  CircleCheckIcon,\n  CircleXIcon,\n  type LucideIcon,\n  TriangleAlertIcon,\n  WrenchIcon,\n} from \"lucide-react\"\n\nimport { Skeleton } from \"@/components/ui/skeleton\"\nimport {\n  DashboardCard,\n  DashboardCardCount,\n  DashboardCardError,\n  formatCount,\n} from \"@/components/blocks/openlmis/dashboard-card\"\nimport {\n  StatusMeter,\n  StatusMeterIcon,\n  StatusMeterLabel,\n  StatusMeterList,\n  StatusMeterValue,\n  type StatusMeterTone,\n} from \"@/components/openlmis/status-meter-list\"\n\n/** Cold chain equipment's functional statuses, best first. */\nexport const EQUIPMENT_STATUSES = [\n  \"FUNCTIONING\",\n  \"NEEDS_ATTENTION\",\n  \"AWAITING_REPAIR\",\n  \"UNSERVICEABLE\",\n] as const\n\nexport type EquipmentStatus = (typeof EQUIPMENT_STATUSES)[number]\n\ntype StatusStyle = {\n  label: string\n  icon: LucideIcon\n  tone: StatusMeterTone\n}\n\n/** The colours carry good-to-critical meaning, so each status also has its own icon and label. */\nconst STATUS_STYLE: Record<EquipmentStatus, StatusStyle> = {\n  FUNCTIONING: {\n    label: \"Functioning\",\n    icon: CircleCheckIcon,\n    tone: \"success\",\n  },\n  NEEDS_ATTENTION: {\n    label: \"Needs Attention\",\n    icon: TriangleAlertIcon,\n    tone: \"warning\",\n  },\n  AWAITING_REPAIR: {\n    label: \"Awaiting Repair\",\n    icon: WrenchIcon,\n    tone: \"warning\",\n  },\n  UNSERVICEABLE: {\n    label: \"Unserviceable\",\n    icon: CircleXIcon,\n    tone: \"destructive\",\n  },\n}\n\ntype EquipmentStatusCardProps = {\n  /** How much equipment is in each status; a placeholder shows until it is set. */\n  counts: Record<EquipmentStatus, number> | undefined\n  failed?: boolean\n  onRetry?: () => void\n}\n\n/** How much cold chain equipment works, needs work or is out of service. */\nexport function EquipmentStatusCard({\n  counts,\n  failed = false,\n  onRetry,\n}: EquipmentStatusCardProps) {\n  const total = counts\n    ? EQUIPMENT_STATUSES.reduce((sum, status) => sum + counts[status], 0)\n    : undefined\n\n  return (\n    <DashboardCard\n      badge={<DashboardCardCount failed={failed} value={total} />}\n      description=\"Cold chain equipment by functional status.\"\n      title=\"Cold Chain Equipment\"\n    >\n      {failed && onRetry ? (\n        <DashboardCardError onRetry={onRetry} />\n      ) : counts === undefined || total === undefined ? (\n        <Skeleton className=\"h-40 w-full\" />\n      ) : (\n        <StatusMeterList>\n          {EQUIPMENT_STATUSES.map((status) => {\n            const { label, icon, tone } = STATUS_STYLE[status]\n            return (\n              <StatusMeter\n                key={status}\n                max={total}\n                tone={tone}\n                value={counts[status]}\n              >\n                <StatusMeterIcon icon={icon} />\n                <StatusMeterLabel>{label}</StatusMeterLabel>\n                <StatusMeterValue>\n                  {formatCount(counts[status])}\n                </StatusMeterValue>\n              </StatusMeter>\n            )\n          })}\n        </StatusMeterList>\n      )}\n    </DashboardCard>\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/home-dashboard/equipment-status.tsx"
    },
    {
      "path": "registry/templates/openlmis/home-dashboard/components/home-dashboard.tsx",
      "content": "\"use client\"\n\nimport { InfoIcon, LayoutDashboardIcon, PlusIcon } from \"lucide-react\"\n\nimport { Alert, AlertDescription, AlertTitle } from \"@/components/ui/alert\"\nimport { Button } from \"@/components/ui/button\"\nimport {\n  Empty,\n  EmptyDescription,\n  EmptyHeader,\n  EmptyMedia,\n  EmptyTitle,\n} from \"@/components/ui/empty\"\nimport { ApprovalsTable } from \"@/components/openlmis/home-dashboard/approvals-table\"\nimport { EquipmentStatusCard } from \"@/components/openlmis/home-dashboard/equipment-status\"\nimport { RequisitionStatusMeter } from \"@/components/openlmis/home-dashboard/requisition-status-meter\"\nimport { RequisitionsByPeriod } from \"@/components/openlmis/home-dashboard/requisitions-by-period\"\nimport {\n  Workspace,\n  WorkspaceActions,\n  WorkspaceContent,\n  WorkspaceDescription,\n  WorkspaceHeader,\n  WorkspaceHeading,\n  WorkspaceTitle,\n} from \"@/components/blocks/openlmis/workspace\"\nimport { DashboardRow } from \"@/components/blocks/openlmis/dashboard-card\"\nimport {\n  Stat,\n  StatStrip,\n} from \"@/components/blocks/openlmis/stat-strip\"\n\nimport {\n  type DashboardAccess,\n  type DashboardData,\n  MOCK_ACCESS,\n  MOCK_DASHBOARD,\n  MOCK_USER,\n} from \"@/components/openlmis/home-dashboard/mock-dashboard\"\n\nconst needsAttention = (counts: {\n  AWAITING_REPAIR: number\n  UNSERVICEABLE: number\n}) => counts.AWAITING_REPAIR + counts.UNSERVICEABLE\n\ntype HomeDashboardProps = {\n  /** Which parts the user's rights allow; the rest stay hidden. */\n  access?: DashboardAccess\n  data?: DashboardData\n  firstName?: string\n  /** Opens Add User, e.g. by navigating to the users list. */\n  onAddUser?: () => void\n}\n\n/** The home screen: a greeting, headline numbers and the cards the user's rights allow. */\nexport function HomeDashboard({\n  access = MOCK_ACCESS,\n  data = MOCK_DASHBOARD,\n  firstName = MOCK_USER.firstName,\n  onAddUser,\n}: HomeDashboardProps) {\n  const nothingToShow = !Object.entries(access).some(\n    ([part, allowed]) => part !== \"manageUsers\" && allowed\n  )\n\n  const stats = [\n    access.approve && (\n      <Stat\n        key=\"approve\"\n        label=\"Requisitions To Approve\"\n        value={data.approvals.length}\n      />\n    ),\n    access.convert && (\n      <Stat\n        key=\"convert\"\n        label=\"Requisitions To Convert\"\n        value={data.convertCount}\n      />\n    ),\n    access.orders && (\n      <Stat\n        key=\"orders\"\n        label=\"Orders Not Received\"\n        value={data.openOrdersCount}\n      />\n    ),\n    access.equipment && (\n      <Stat\n        key=\"equipment\"\n        label=\"Equipment Not Functioning\"\n        value={needsAttention(data.equipmentCounts)}\n      />\n    ),\n  ].filter(Boolean)\n\n  return (\n    <Workspace>\n      <WorkspaceHeader>\n        <WorkspaceHeading>\n          <WorkspaceTitle>Welcome, {firstName}</WorkspaceTitle>\n          <WorkspaceDescription>\n            {waitingSummary(data.approvals.length, data.convertCount, access)}\n          </WorkspaceDescription>\n        </WorkspaceHeading>\n        {access.manageUsers && (\n          <WorkspaceActions>\n            <Button onClick={onAddUser} size=\"lg\">\n              <PlusIcon data-icon=\"inline-start\" />\n              Add User\n            </Button>\n          </WorkspaceActions>\n        )}\n      </WorkspaceHeader>\n      <WorkspaceContent>\n        {data.notifications.map((notification) => (\n          <Alert key={notification.id}>\n            <InfoIcon />\n            {notification.title && (\n              <AlertTitle>{notification.title}</AlertTitle>\n            )}\n            <AlertDescription>{notification.message}</AlertDescription>\n          </Alert>\n        ))}\n\n        {nothingToShow && (\n          <Empty>\n            <EmptyHeader>\n              <EmptyMedia variant=\"icon\">\n                <LayoutDashboardIcon />\n              </EmptyMedia>\n              <EmptyTitle>Nothing To Show Yet</EmptyTitle>\n              <EmptyDescription>\n                Your roles do not include any of the work this page summarizes.\n              </EmptyDescription>\n            </EmptyHeader>\n          </Empty>\n        )}\n\n        {stats.length > 0 && <StatStrip>{stats}</StatStrip>}\n\n        {access.requisitions && (\n          <DashboardRow\n            narrow={<RequisitionStatusMeter counts={data.statusCounts} />}\n            wide={\n              <RequisitionsByPeriod requisitions={data.recentRequisitions} />\n            }\n          />\n        )}\n\n        {(access.approve || access.equipment) && (\n          <DashboardRow\n            narrow={\n              access.equipment && (\n                <EquipmentStatusCard counts={data.equipmentCounts} />\n              )\n            }\n            wide={\n              access.approve && <ApprovalsTable requisitions={data.approvals} />\n            }\n          />\n        )}\n      </WorkspaceContent>\n    </Workspace>\n  )\n}\n\nconst requisitions = (count: number) =>\n  `${count} ${count === 1 ? \"requisition\" : \"requisitions\"}`\n\n/** One sentence on what is waiting, from the counts this user's rights let them see. */\nfunction waitingSummary(\n  toApprove: number | undefined,\n  toConvert: number | undefined,\n  { approve, convert }: DashboardAccess\n) {\n  if (approve && convert && toApprove !== undefined && toConvert !== undefined)\n    return `${requisitions(toApprove)} to approve and ${toConvert} to convert to orders.`\n  if (approve && !convert && toApprove !== undefined)\n    return `${requisitions(toApprove)} waiting for your approval.`\n  if (convert && !approve && toConvert !== undefined)\n    return `${requisitions(toConvert)} ready to convert to orders.`\n  return approve || convert\n    ? \"What needs your attention today.\"\n    : \"An overview of your work in OpenLMIS.\"\n}",
      "type": "registry:component",
      "target": "components/openlmis/home-dashboard/home-dashboard.tsx"
    },
    {
      "path": "registry/templates/openlmis/home-dashboard/components/mock-dashboard.ts",
      "content": "// Mock numbers for the dashboard, so the page runs with no backend. Pass your own data instead.\n\nimport type { ApprovalRequisition } from \"@/components/openlmis/home-dashboard/approvals-table\"\nimport type { EquipmentStatus } from \"@/components/openlmis/home-dashboard/equipment-status\"\nimport type { PipelineStatus } from \"@/components/openlmis/home-dashboard/requisition-status-meter\"\nimport type { PeriodRequisition } from \"@/components/openlmis/home-dashboard/periods\"\n\n/** What the signed-in user's rights let the dashboard show; work it out from their rights. */\nexport type DashboardAccess = {\n  approve: boolean\n  convert: boolean\n  orders: boolean\n  equipment: boolean\n  requisitions: boolean\n  manageUsers: boolean\n}\n\nexport type SystemNotification = {\n  id: string\n  title: string | null\n  message: string\n}\n\nexport const MOCK_USER = { firstName: \"Grace\" }\n\nexport const MOCK_ACCESS: DashboardAccess = {\n  approve: true,\n  convert: true,\n  orders: true,\n  equipment: true,\n  requisitions: true,\n  manageUsers: true,\n}\n\nexport const MOCK_NOTIFICATIONS: SystemNotification[] = [\n  {\n    id: \"n1\",\n    title: \"Scheduled Maintenance\",\n    message: \"OpenLMIS will be unavailable on Saturday from 22:00 to 23:00.\",\n  },\n]\n\nexport const MOCK_APPROVALS: ApprovalRequisition[] = [\n  {\n    id: \"r1\",\n    emergency: true,\n    program: { name: \"Essential Meds\" },\n    facility: { code: \"HC02\", name: \"Nandumbo Health Center\" },\n    processingPeriod: { name: \"Jan 2026\" },\n    waitingSince: \"2026-02-03T09:12:00Z\",\n  },\n  {\n    id: \"r2\",\n    emergency: false,\n    program: { name: \"Family Planning\" },\n    facility: { code: \"HC01\", name: \"Comfort Health Clinic\" },\n    processingPeriod: { name: \"Jan 2026\" },\n    waitingSince: \"2026-02-04T13:40:00Z\",\n  },\n  {\n    id: \"r3\",\n    emergency: false,\n    program: { name: \"Essential Meds\" },\n    facility: { code: \"HC03\", name: \"Kankao Health Facility\" },\n    processingPeriod: { name: \"Jan 2026\" },\n    waitingSince: \"2026-02-05T08:05:00Z\",\n  },\n  {\n    id: \"r4\",\n    emergency: false,\n    program: { name: \"ARV\" },\n    facility: { code: \"DH01\", name: \"Balaka District Hospital\" },\n    processingPeriod: { name: \"Q4 2025\" },\n    waitingSince: \"2026-01-12T10:30:00Z\",\n  },\n]\n\nexport const MOCK_CONVERT_COUNT = 2\n\nexport const MOCK_OPEN_ORDERS_COUNT = 14\n\nexport const MOCK_EQUIPMENT_COUNTS: Record<EquipmentStatus, number> = {\n  FUNCTIONING: 42,\n  NEEDS_ATTENTION: 6,\n  AWAITING_REPAIR: 3,\n  UNSERVICEABLE: 2,\n}\n\nconst STATUS_CYCLE: PeriodRequisition[\"status\"][] = [\n  \"APPROVED\",\n  \"RELEASED\",\n  \"SUBMITTED\",\n  \"APPROVED\",\n  \"AUTHORIZED\",\n  \"IN_APPROVAL\",\n  \"RELEASED\",\n  \"INITIATED\",\n]\n\n// Six months of requisitions, more of them still in progress in the latest months.\nexport const MOCK_RECENT_REQUISITIONS: PeriodRequisition[] = [\n  \"2025-08\",\n  \"2025-09\",\n  \"2025-10\",\n  \"2025-11\",\n  \"2025-12\",\n  \"2026-01\",\n].flatMap((month, index) =>\n  Array.from({ length: 6 + index * 2 }, (_, count) => ({\n    status: STATUS_CYCLE[(count + index) % STATUS_CYCLE.length] ?? \"APPROVED\",\n    processingPeriod: { startDate: `${month}-01` },\n  }))\n)\n\nexport const MOCK_STATUS_COUNTS: Record<PipelineStatus, number> = {\n  SUBMITTED: 9,\n  AUTHORIZED: 6,\n  IN_APPROVAL: 4,\n  APPROVED: 18,\n  RELEASED: 31,\n}\n\n/** Everything the dashboard shows; pass your own, leaving out what the user's rights hide. */\nexport type DashboardData = {\n  notifications: SystemNotification[]\n  approvals: ApprovalRequisition[]\n  convertCount: number\n  openOrdersCount: number\n  equipmentCounts: Record<EquipmentStatus, number>\n  recentRequisitions: PeriodRequisition[]\n  statusCounts: Record<PipelineStatus, number>\n}\n\nexport const MOCK_DASHBOARD: DashboardData = {\n  notifications: MOCK_NOTIFICATIONS,\n  approvals: MOCK_APPROVALS,\n  convertCount: MOCK_CONVERT_COUNT,\n  openOrdersCount: MOCK_OPEN_ORDERS_COUNT,\n  equipmentCounts: MOCK_EQUIPMENT_COUNTS,\n  recentRequisitions: MOCK_RECENT_REQUISITIONS,\n  statusCounts: MOCK_STATUS_COUNTS,\n}",
      "type": "registry:lib",
      "target": "components/openlmis/home-dashboard/mock-dashboard.ts"
    },
    {
      "path": "registry/templates/openlmis/home-dashboard/components/requisition-status-meter/requisition-status-meter.tsx",
      "content": "\"use client\"\n\nimport { Skeleton } from \"@/components/ui/skeleton\"\nimport {\n  DashboardCard,\n  DashboardCardCount,\n  DashboardCardError,\n} from \"@/components/blocks/openlmis/dashboard-card\"\nimport { SegmentedMeter } from \"@/components/openlmis/segmented-meter\"\n\n/** A sent requisition's steps, in the order it takes them. */\nexport const REQUISITION_PIPELINE = [\n  \"SUBMITTED\",\n  \"AUTHORIZED\",\n  \"IN_APPROVAL\",\n  \"APPROVED\",\n  \"RELEASED\",\n] as const\n\nexport type PipelineStatus = (typeof REQUISITION_PIPELINE)[number]\n\nconst LABELS = {\n  SUBMITTED: \"Submitted\",\n  AUTHORIZED: \"Authorized\",\n  IN_APPROVAL: \"In Approval\",\n  APPROVED: \"Approved\",\n  RELEASED: \"Released\",\n} as const satisfies Record<PipelineStatus, string>\n\ntype RequisitionStatusMeterProps = {\n  /** How many requisitions stand at each step; a placeholder shows until it is set. */\n  counts: Record<PipelineStatus, number> | undefined\n  failed?: boolean\n  onRetry?: () => void\n  /** Fills the meter from the right on a right-to-left page. */\n  dir?: \"ltr\" | \"rtl\"\n  /** Formats each share, e.g. \"43%\"; fixed so a server render matches the browser. */\n  locale?: string\n}\n\n/** Where sent requisitions stand, from submitted to released, as one segmented bar with a legend. */\nexport function RequisitionStatusMeter({\n  counts,\n  failed = false,\n  onRetry,\n  dir = \"ltr\",\n  locale = \"en-US\",\n}: RequisitionStatusMeterProps) {\n  const total = counts\n    ? REQUISITION_PIPELINE.reduce((sum, status) => sum + counts[status], 0)\n    : undefined\n\n  return (\n    <DashboardCard\n      badge={<DashboardCardCount failed={failed} value={total} />}\n      description=\"Where sent requisitions stand today.\"\n      title=\"Requisitions By Status\"\n    >\n      {failed && onRetry ? (\n        <DashboardCardError onRetry={onRetry} />\n      ) : counts === undefined || total === undefined ? (\n        <Skeleton className=\"h-36 w-full\" />\n      ) : (\n        <SegmentedMeter\n          dir={dir}\n          locale={locale}\n          segments={REQUISITION_PIPELINE.map((status) => ({\n            id: status,\n            label: LABELS[status],\n            value: counts[status],\n          }))}\n        />\n      )}\n    </DashboardCard>\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/home-dashboard/requisition-status-meter.tsx"
    },
    {
      "path": "registry/templates/openlmis/home-dashboard/components/requisitions-by-period/periods.ts",
      "content": "export type RequisitionStatus =\n  | \"INITIATED\"\n  | \"REJECTED\"\n  | \"SUBMITTED\"\n  | \"AUTHORIZED\"\n  | \"IN_APPROVAL\"\n  | \"APPROVED\"\n  | \"RELEASED\"\n  | \"RELEASED_WITHOUT_ORDER\"\n  | \"SKIPPED\"\n\n/** The parts of a requisition the chart reads; map your API's requisitions onto it. */\nexport type PeriodRequisition = {\n  status: RequisitionStatus\n  processingPeriod: { startDate: string }\n}\n\n/** Sent on but not approved yet; drafts, rejections and skipped periods are left out. */\nconst IN_PROGRESS: ReadonlySet<RequisitionStatus> = new Set<RequisitionStatus>([\n  \"SUBMITTED\",\n  \"AUTHORIZED\",\n  \"IN_APPROVAL\",\n])\nconst APPROVED: ReadonlySet<RequisitionStatus> = new Set<RequisitionStatus>([\n  \"APPROVED\",\n  \"RELEASED\",\n  \"RELEASED_WITHOUT_ORDER\",\n])\n\nexport type MonthTotals = {\n  /** `YYYY-MM`, the month the requisitions' periods start. */\n  month: string\n  inProgress: number\n  approved: number\n}\n\n/** The latest months with requisitions, oldest first; monthly and quarterly periods meet on one timeline. */\nexport function totalsByMonth(\n  requisitions: readonly PeriodRequisition[],\n  limit = 6\n): MonthTotals[] {\n  const months = new Map<string, MonthTotals>()\n\n  for (const { status, processingPeriod } of requisitions) {\n    const group = IN_PROGRESS.has(status)\n      ? \"inProgress\"\n      : APPROVED.has(status)\n        ? \"approved\"\n        : null\n    if (!group) continue\n    const month = processingPeriod.startDate.slice(0, 7)\n    const totals = months.get(month) ?? { month, inProgress: 0, approved: 0 }\n    totals[group] += 1\n    months.set(month, totals)\n  }\n\n  const totals = [...months.values()]\n  // oxlint-disable-next-line unicorn/no-array-sort -- sorts a copy; toSorted needs the ES2023 lib\n  totals.sort((a, b) => a.month.localeCompare(b.month))\n  return totals.slice(-limit)\n}\n\n/** Whether a month's tick shows its year: on the first month and wherever the year changes. */\nexport function showsYear(\n  months: readonly MonthTotals[],\n  index: number\n): boolean {\n  return (\n    index === 0 ||\n    months[index - 1]?.month.slice(0, 4) !== months[index]?.month.slice(0, 4)\n  )\n}",
      "type": "registry:lib",
      "target": "components/openlmis/home-dashboard/periods.ts"
    },
    {
      "path": "registry/templates/openlmis/home-dashboard/components/requisitions-by-period/requisitions-by-period.tsx",
      "content": "\"use client\"\n\nimport { BarChartIcon } from \"lucide-react\"\nimport { useMemo } from \"react\"\nimport {\n  Bar,\n  BarChart,\n  CartesianGrid,\n  LabelList,\n  Rectangle,\n  type RectangleProps,\n  XAxis,\n  YAxis,\n} from \"recharts\"\n\nimport {\n  type ChartConfig,\n  ChartContainer,\n  ChartLegend,\n  ChartLegendContent,\n  ChartTooltip,\n  ChartTooltipContent,\n} from \"@/components/ui/chart\"\nimport {\n  Empty,\n  EmptyDescription,\n  EmptyHeader,\n  EmptyMedia,\n  EmptyTitle,\n} from \"@/components/ui/empty\"\nimport { Skeleton } from \"@/components/ui/skeleton\"\nimport {\n  DashboardCard,\n  DashboardCardCount,\n  DashboardCardError,\n  formatCount,\n} from \"@/components/blocks/openlmis/dashboard-card\"\n\nimport {\n  type MonthTotals,\n  type PeriodRequisition,\n  showsYear,\n  totalsByMonth,\n} from \"@/components/openlmis/home-dashboard/periods\"\n\nconst TITLE = \"Requisitions By Period\"\n\nconst config = {\n  inProgress: { label: \"In Progress\", color: \"var(--chart-2)\" },\n  approved: { label: \"Approved\", color: \"var(--chart-4)\" },\n} satisfies ChartConfig\n\n/** Month and year from a `YYYY-MM` key, read in UTC so a period never slips into the month before. */\n// A fixed locale, so a server render and the browser print the same labels.\nconst monthFormat = (options: Intl.DateTimeFormatOptions) => {\n  const formatter = new Intl.DateTimeFormat(\"en-US\", {\n    ...options,\n    timeZone: \"UTC\",\n  })\n  return (key: string) => formatter.format(new Date(`${key}-01T00:00:00Z`))\n}\nconst formatMonthYear = monthFormat({ month: \"short\", year: \"numeric\" })\nconst formatMonth = monthFormat({ month: \"short\" })\nconst formatYear = monthFormat({ year: \"numeric\" })\n\ntype RequisitionsByPeriodProps = {\n  /** A placeholder shows until it is set. */\n  requisitions: readonly PeriodRequisition[] | undefined\n  failed?: boolean\n  onRetry?: () => void\n  /** Mirrors the axes for a right-to-left page. */\n  dir?: \"ltr\" | \"rtl\"\n}\n\n/** Sent requisitions in each of the latest months, split into still in progress and approved. */\nexport function RequisitionsByPeriod({\n  requisitions,\n  failed = false,\n  onRetry,\n  dir = \"ltr\",\n}: RequisitionsByPeriodProps) {\n  const months = useMemo(\n    () => (requisitions ? totalsByMonth(requisitions) : undefined),\n    [requisitions]\n  )\n  const total = months?.reduce(\n    (sum, month) => sum + month.inProgress + month.approved,\n    0\n  )\n\n  return (\n    <DashboardCard\n      badge={<DashboardCardCount failed={failed} value={total} />}\n      description=\"Sent requisitions by the month their period starts.\"\n      title={TITLE}\n    >\n      {failed && onRetry ? (\n        <DashboardCardError onRetry={onRetry} />\n      ) : months === undefined ? (\n        <Skeleton className=\"h-64 w-full\" />\n      ) : months.length === 0 ? (\n        <Empty>\n          <EmptyHeader>\n            <EmptyMedia variant=\"icon\">\n              <BarChartIcon />\n            </EmptyMedia>\n            <EmptyTitle>No Requisitions Yet</EmptyTitle>\n            <EmptyDescription>\n              Requisitions appear here once they are submitted.\n            </EmptyDescription>\n          </EmptyHeader>\n        </Empty>\n      ) : (\n        <MonthChart dir={dir} months={months} />\n      )}\n    </DashboardCard>\n  )\n}\n\nfunction MonthChart({\n  months,\n  dir,\n}: {\n  months: MonthTotals[]\n  dir: \"ltr\" | \"rtl\"\n}) {\n  const isRtl = dir === \"rtl\"\n\n  return (\n    <>\n      {/* Sized by height, so the plot fills whatever width the card has. */}\n      <ChartContainer className=\"aspect-auto h-64 w-full\" config={config}>\n        <BarChart accessibilityLayer data={months} margin={{ top: 20 }}>\n          <CartesianGrid vertical={false} />\n          {/* Every month is labelled; there are at most six, so none is skipped. */}\n          <XAxis\n            axisLine={false}\n            dataKey=\"month\"\n            height={36}\n            interval={0}\n            reversed={isRtl}\n            tick={<MonthTick months={months} />}\n            tickLine={false}\n            tickMargin={4}\n          />\n          <YAxis\n            allowDecimals={false}\n            axisLine={false}\n            orientation={isRtl ? \"right\" : \"left\"}\n            tickFormatter={formatCount}\n            tickLine={false}\n            width={32}\n          />\n          <ChartTooltip\n            content={\n              <ChartTooltipContent\n                labelFormatter={(month) => formatMonthYear(String(month))}\n              />\n            }\n            cursor={false}\n          />\n          {/* Recharts sorts the legend by name; the stacking order reads better. */}\n          <ChartLegend content={<ChartLegendContent />} itemSorter={null} />\n          {/* The card-coloured stroke is the 2px gap that keeps stacked segments apart. */}\n          <Bar\n            dataKey=\"inProgress\"\n            fill=\"var(--color-inProgress)\"\n            maxBarSize={24}\n            shape={InProgressSegment}\n            stackId=\"month\"\n            stroke=\"var(--card)\"\n            strokeWidth={2}\n          />\n          <Bar\n            dataKey=\"approved\"\n            fill=\"var(--color-approved)\"\n            maxBarSize={24}\n            radius={[4, 4, 0, 0]}\n            stackId=\"month\"\n            stroke=\"var(--card)\"\n            strokeWidth={2}\n          >\n            <LabelList\n              className=\"fill-muted-foreground\"\n              formatter={(value) =>\n                typeof value === \"number\" ? formatCount(value) : value\n              }\n              position=\"top\"\n              valueAccessor={(entry: { payload: MonthTotals }) =>\n                entry.payload.inProgress + entry.payload.approved\n              }\n            />\n          </Bar>\n        </BarChart>\n      </ChartContainer>\n      <table className=\"sr-only\">\n        <caption>{TITLE}</caption>\n        <thead>\n          <tr>\n            <th scope=\"col\">Month</th>\n            <th scope=\"col\">{config.inProgress.label}</th>\n            <th scope=\"col\">{config.approved.label}</th>\n          </tr>\n        </thead>\n        <tbody>\n          {months.map((month) => (\n            <tr key={month.month}>\n              <th scope=\"row\">{formatMonthYear(month.month)}</th>\n              <td>{formatCount(month.inProgress)}</td>\n              <td>{formatCount(month.approved)}</td>\n            </tr>\n          ))}\n        </tbody>\n      </table>\n    </>\n  )\n}\n\ntype MonthTickProps = {\n  x?: number\n  y?: number\n  index?: number\n  payload?: { value: string }\n  months: readonly MonthTotals[]\n}\n\n/** The month, with its year beneath where the year starts or changes, so six ticks fit a phone. */\nfunction MonthTick({\n  x = 0,\n  y = 0,\n  index = 0,\n  payload,\n  months,\n}: MonthTickProps) {\n  if (!payload) return null\n  return (\n    <text\n      className=\"fill-muted-foreground text-xs\"\n      textAnchor=\"middle\"\n      x={x}\n      y={y}\n    >\n      <tspan dy=\"0.8em\" x={x}>\n        {formatMonth(payload.value)}\n      </tspan>\n      {showsYear(months, index) && (\n        <tspan dy=\"1.3em\" x={x}>\n          {formatYear(payload.value)}\n        </tspan>\n      )}\n    </text>\n  )\n}\n\n/** The lower segment, rounded on top only when nothing is stacked above it. */\nfunction InProgressSegment(props: RectangleProps & { payload?: MonthTotals }) {\n  return (\n    <Rectangle {...props} radius={props.payload?.approved ? 0 : [4, 4, 0, 0]} />\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/home-dashboard/requisitions-by-period.tsx"
    },
    {
      "path": "registry/templates/openlmis/home-dashboard/page.tsx",
      "content": "import { HomeDashboard } from \"@/components/openlmis/home-dashboard/home-dashboard\"\n\n// A Next.js App Router route; in any other React app, render HomeDashboard from your own route.\nexport default function Page() {\n  return <HomeDashboard />\n}",
      "type": "registry:page",
      "target": "app/home-dashboard/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": "1024px"
  },
  "categories": [
    "dashboard"
  ],
  "type": "registry:page"
}
