{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "inventory-03",
  "description": "Every SKU by stock status, with the value of stock on hand and how many times a year it turns over.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/breakdown.json",
    "https://www.dashboardblocks.com/r/radix/chart.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/inventory.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/inventory/inventory-03.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  BlockStateText,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  BreakdownBar,\n  BreakdownTable,\n  getTotal,\n} from '@/registry/components/dashboardblocks/breakdown'\nimport { ChartPlaceholder } from '@/registry/components/dashboardblocks/chart'\nimport {\n  type StockStatus,\n  stockStatusConfig,\n} from '@/registry/components/dashboardblocks/inventory'\nimport { formatCurrency, formatNumber } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Inventory3Props extends BlockStateProps {\n  annualCogs?: number\n  /** Leave out, with `value`, to show the empty state. */\n  counts?: Record<StockStatus, number>\n  /** @default 'USD' */\n  currency?: string\n  /** Defaults to a sentence counting the SKUs that need ordering. */\n  description?: string\n  title: string\n  /** Leave out, with `counts`, to show the empty state. */\n  value?: number\n}\n\nconst exampleProps: Inventory3Props = {\n  annualCogs: 9_860_000,\n  counts: { low: 64, ok: 1_182, out: 17, over: 93 },\n  title: 'Stock health',\n  value: 2_340_000,\n}\n\nconst ORDER: StockStatus[] = ['ok', 'low', 'out', 'over']\n\nconst noCounts: Record<StockStatus, number> = { low: 0, ok: 0, out: 0, over: 0 }\n\nconst Inventory3 = (props: Inventory3Props) => {\n  const {\n    annualCogs,\n    counts = noCounts,\n    currency = 'USD',\n    errorMessage,\n    status,\n    title,\n    value,\n  } = props\n  const state = getBlockState(status, value)\n  const segments = ORDER.map((stock) => ({\n    color: stockStatusConfig[stock].color,\n    label: stockStatusConfig[stock].label,\n    value: counts[stock],\n  }))\n  const total = getTotal(segments)\n  const reorder = counts.low + counts.out\n  const turnover =\n    annualCogs !== undefined && value !== undefined && value > 0\n      ? annualCogs / value\n      : null\n  const {\n    description = `${formatNumber(total)} SKUs across every warehouse; ${formatNumber(reorder)} of them are low or out and need ordering.`,\n  } = props\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            <div className='flex flex-col gap-1 border-t pt-4'>\n              <p className='text-4xl font-light tracking-tight tabular-nums'>\n                {state || value === undefined ? (\n                  <BlockStateText variant='short' />\n                ) : (\n                  <>\n                    {formatCurrency(value, { compact: true, currency })}\n                    <span className='text-muted-foreground ml-1 text-base font-normal tracking-normal'>\n                      in stock\n                    </span>\n                  </>\n                )}\n              </p>\n              <BlockReady className='text-sm'>\n                {turnover !== null && (\n                  <p className='text-muted-foreground text-sm'>\n                    Turns over{' '}\n                    <span className='text-foreground font-medium tabular-nums'>\n                      {formatNumber(turnover)}\n                    </span>{' '}\n                    times a year, about {Math.round(365 / turnover)} days of stock.\n                  </p>\n                )}\n              </BlockReady>\n            </div>\n            {state === 'loading' && (\n              <>\n                <ChartPlaceholder className='rounded-full' height={12} />\n                <BlockStateRows rows={4} />\n              </>\n            )}\n            {!state && (\n              <>\n                <BreakdownBar segments={segments} />\n                <BreakdownTable\n                  caption={`${title}: ${description}`}\n                  labels={['Status', 'SKUs', 'Share']}\n                  segments={segments}\n                />\n              </>\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Inventory3, exampleProps as inventory3ExampleProps, type Inventory3Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/inventory/inventory-03.tsx"
    }
  ],
  "meta": {
    "shows": "Every SKU by stock status, with the value of stock on hand and how many times a year it turns over.",
    "size": "full",
    "usedWith": [
      "inventory-01",
      "inventory-02",
      "stat-group-02"
    ],
    "component": "Inventory3",
    "props": "{ annualCogs?: number; counts?: { low: number; out: number; ok: number; over: number }; currency?: string; description?: string; title: string; value?: number; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
