{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "inventory-01",
  "description": "Items at or near their reorder point, soonest to run out first, with how much to order and which will run out before an order arrives.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/details.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/inventory.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/inventory/inventory-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { Details } from '@/registry/components/dashboardblocks/details'\nimport {\n  ReorderPointKey,\n  StockBar,\n  StockStatusLabel,\n  getDaysOfCover,\n  getReorderQuantity,\n  getStockStatus,\n} from '@/registry/components/dashboardblocks/inventory'\nimport { formatNumber, joinDetails } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\nimport { cn } from '@/lib/utils'\n\ninterface StockItem {\n  dailyDemand: number\n  leadTimeDays: number\n  name: string\n  onHand: number\n  onOrder?: number\n  reorderPoint: number\n  sku: string\n}\n\ninterface Inventory1Props extends BlockStateProps {\n  /** Defaults to a sentence counting the items that are out or run out before an order arrives. */\n  description?: string\n  /** Leave out, or pass none, to show the empty state. */\n  items?: StockItem[]\n  targetDays?: number\n  title: string\n}\n\nconst exampleProps: Inventory1Props = {\n  items: [\n    {\n      dailyDemand: 14,\n      leadTimeDays: 10,\n      name: 'Trail runner, size 42',\n      onHand: 0,\n      reorderPoint: 160,\n      sku: 'TR-42-BLK',\n    },\n    {\n      dailyDemand: 22,\n      leadTimeDays: 7,\n      name: 'Merino crew socks, 3 pack',\n      onHand: 58,\n      onOrder: 120,\n      reorderPoint: 180,\n      sku: 'MS-3P-GRY',\n    },\n    {\n      dailyDemand: 9,\n      leadTimeDays: 14,\n      name: 'Waterproof shell, M',\n      onHand: 71,\n      reorderPoint: 140,\n      sku: 'WS-M-NVY',\n    },\n    {\n      dailyDemand: 31,\n      leadTimeDays: 5,\n      name: 'Insulated bottle, 750 ml',\n      onHand: 204,\n      reorderPoint: 170,\n      sku: 'IB-750-STL',\n    },\n    {\n      dailyDemand: 6,\n      leadTimeDays: 21,\n      name: 'Daypack, 22 l',\n      onHand: 118,\n      reorderPoint: 130,\n      sku: 'DP-22-OLV',\n    },\n  ],\n  title: 'Low stock',\n}\n\nconst summarize = (items: StockItem[]) => {\n  const out = items.filter((item) => item.onHand <= 0).length\n  const late = items.filter((item) => {\n    const cover = getDaysOfCover(item.onHand, item.dailyDemand)\n    return cover > 0 && cover < item.leadTimeDays\n  }).length\n  const count = `${items.length} ${items.length === 1 ? 'item' : 'items'} at or near their reorder point`\n  const details = [\n    out > 0 && `${out} out of stock`,\n    late > 0 && `${late} running out before an order would arrive`,\n  ].filter(Boolean)\n  return details.length > 0 ? `${count}: ${details.join(', ')}.` : `${count}.`\n}\n\nconst formatCover = (cover: number) =>\n  cover === 0\n    ? 'Out now'\n    : Number.isFinite(cover)\n      ? `${Math.floor(cover)} ${Math.floor(cover) === 1 ? 'day' : 'days'} left`\n      : 'No demand'\n\nconst Inventory1 = (props: Inventory1Props) => {\n  const { items = [], errorMessage, status, targetDays = 30, title } = props\n  const state = getBlockState(status, items)\n  const { description = summarize(items) } = props\n  const sorted = [...items].sort(\n    (a, b) =>\n      getDaysOfCover(a.onHand, a.dailyDemand) - getDaysOfCover(b.onHand, b.dailyDemand),\n  )\n  const capacity =\n    Math.max(...items.map((item) => Math.max(item.onHand, item.reorderPoint))) * 1.1\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <BlockReady className='text-sm'>\n                <p className='text-muted-foreground text-sm'>{description}</p>\n              </BlockReady>\n            </header>\n            <BlockStateRows className='border-t' rows={4} />\n            {!state && (\n              <ul className='flex flex-col border-t'>\n                {sorted.map((item) => {\n                  const cover = getDaysOfCover(item.onHand, item.dailyDemand)\n                  const late = cover < item.leadTimeDays\n                  const reorder = getReorderQuantity({ ...item, targetDays })\n                  return (\n                    <li key={item.sku} className='flex flex-col gap-2 border-b py-3'>\n                      <div className='flex items-start justify-between gap-3'>\n                        <div className='flex min-w-0 flex-col'>\n                          <span className='truncate text-sm font-medium'>\n                            {item.name}\n                          </span>\n                          <span className='text-muted-foreground font-mono text-xs'>\n                            {item.sku}\n                          </span>\n                        </div>\n                        <StockStatusLabel status={getStockStatus(item)} />\n                      </div>\n                      <StockBar\n                        capacity={capacity}\n                        onHand={item.onHand}\n                        reorderPoint={item.reorderPoint}\n                      />\n                      <div className='text-muted-foreground flex flex-wrap items-center justify-between gap-x-3 gap-y-1 text-xs tabular-nums'>\n                        <span>\n                          {joinDetails(\n                            `${formatNumber(item.onHand)} on hand`,\n                            `reorder at ${formatNumber(item.reorderPoint)}`,\n                            item.onOrder\n                              ? `${formatNumber(item.onOrder)} on order`\n                              : undefined,\n                          )}\n                        </span>\n                        <Details>\n                          <span\n                            className={cn(\n                              late && 'font-medium text-red-700 dark:text-red-400',\n                            )}\n                          >\n                            {formatCover(cover)}\n                            {late && cover > 0 && (\n                              <span className='sr-only'>\n                                , runs out before a new order would arrive\n                              </span>\n                            )}\n                          </span>\n                          {reorder > 0 && (\n                            <span className='text-foreground font-medium'>\n                              Order {formatNumber(reorder)}\n                            </span>\n                          )}\n                        </Details>\n                      </div>\n                    </li>\n                  )\n                })}\n              </ul>\n            )}\n            {state !== 'empty' && state !== 'error' && (\n              <div className='text-muted-foreground flex flex-wrap items-center gap-x-4 gap-y-1 text-xs'>\n                <ReorderPointKey />\n                <span>Red days: runs out before an order placed today arrives.</span>\n              </div>\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Inventory1,\n  exampleProps as inventory1ExampleProps,\n  type Inventory1Props,\n  type StockItem,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/inventory/inventory-01.tsx"
    }
  ],
  "meta": {
    "shows": "Items at or near their reorder point, soonest to run out first, with how much to order and which will run out before an order arrives.",
    "size": "full",
    "usedWith": [
      "inventory-02",
      "inventory-03",
      "inventory-04"
    ],
    "component": "Inventory1",
    "props": "{ description?: string; items?: { dailyDemand: number; leadTimeDays: number; name: string; onHand: number; onOrder?: number; reorderPoint: number; sku: string }[]; targetDays?: number; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
