{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "inventory-02",
  "description": "Units stored against capacity in each warehouse, with what arrives this week and which will be nearly full.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/goals.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/inventory/inventory-02.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  GoalProgress,\n  GoalProgressKey,\n} from '@/registry/components/dashboardblocks/goals'\nimport {\n  StatusLabel,\n  type StatusTone,\n} from '@/registry/components/dashboardblocks/status-label'\nimport {\n  formatNumber,\n  formatPercent,\n  joinDetails,\n} from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Warehouse {\n  capacity: number\n  /** Units arriving in the next 7 days. */\n  inbound?: number\n  location: string\n  name: string\n  stored: number\n}\n\ninterface Inventory2Props extends BlockStateProps {\n  /** Defaults to a sentence with the units stored and the warehouses filling up. */\n  description?: string\n  title: string\n  /** Leave out, or pass none, to show the empty state. */\n  warehouses?: Warehouse[]\n  /** Utilisation at which a warehouse is getting full, 0–1. */\n  warnAt?: number\n}\n\nconst exampleProps: Inventory2Props = {\n  title: 'Warehouse capacity',\n  warehouses: [\n    {\n      capacity: 48_000,\n      inbound: 6_200,\n      location: 'Rotterdam',\n      name: 'EU Central',\n      stored: 41_300,\n    },\n    {\n      capacity: 36_000,\n      inbound: 1_800,\n      location: 'Reno, NV',\n      name: 'US West',\n      stored: 22_450,\n    },\n    {\n      capacity: 30_000,\n      inbound: 4_900,\n      location: 'Columbus, OH',\n      name: 'US East',\n      stored: 27_100,\n    },\n    {\n      capacity: 12_000,\n      inbound: 300,\n      location: 'Melbourne',\n      name: 'APAC',\n      stored: 5_880,\n    },\n  ],\n}\n\ntype Fill = 'full' | 'warning' | 'ok'\n\nconst FILL: Record<Fill, { color: string; label: string; tone: StatusTone }> = {\n  full: { color: 'var(--color-red-500)', label: 'Over capacity', tone: 'bad' },\n  ok: { color: 'var(--color-chart-2)', label: 'Room to spare', tone: 'neutral' },\n  warning: { color: 'var(--color-orange-500)', label: 'Nearly full', tone: 'warning' },\n}\n\nconst percent = (ratio: number) => formatPercent(ratio, { maximumFractionDigits: 0 })\n\nconst Inventory2 = (props: Inventory2Props) => {\n  const { errorMessage, status, title, warehouses = [], warnAt = 0.85 } = props\n  const state = getBlockState(status, warehouses)\n  const stored = warehouses.reduce((sum, warehouse) => sum + warehouse.stored, 0)\n  const capacity = warehouses.reduce((sum, warehouse) => sum + warehouse.capacity, 0)\n  const rows = warehouses.map((warehouse) => {\n    const after = warehouse.stored + (warehouse.inbound ?? 0)\n    const ratio = after / (warehouse.capacity || 1)\n    const fill: Fill = ratio >= 1 ? 'full' : ratio >= warnAt ? 'warning' : 'ok'\n    return { ...warehouse, after, fill, ratio }\n  })\n  const filling = rows.filter((row) => row.fill !== 'ok')\n  const {\n    description = filling.length > 0\n      ? `${formatNumber(stored)} of ${formatNumber(capacity)} units stored; ${filling.map((row) => row.name).join(' and ')} ${filling.length === 1 ? 'fills' : 'fill'} up once this week’s stock arrives.`\n      : `${formatNumber(stored)} of ${formatNumber(capacity)} units stored, with room for everything arriving this week.`,\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            <p className='flex flex-wrap items-baseline gap-x-2 border-t pt-4'>\n              <span className='text-4xl font-light tracking-tight tabular-nums'>\n                {state ? (\n                  <BlockStateText variant='short' />\n                ) : (\n                  percent(stored / (capacity || 1))\n                )}\n              </span>\n              {(state === undefined || state === 'loading') && (\n                <span className='text-muted-foreground text-sm'>\n                  full across the network\n                </span>\n              )}\n            </p>\n            {state === 'loading' && <BlockStateRows rows={warehouses.length || 4} />}\n            {!state && (\n              <ul className='flex flex-col'>\n                {rows.map((row) => {\n                  const fill = FILL[row.fill]\n                  return (\n                    <li\n                      key={row.name}\n                      className='flex flex-col gap-2 border-b py-3 first:pt-0'\n                    >\n                      <div className='flex items-baseline justify-between gap-3'>\n                        <span className='flex min-w-0 flex-col'>\n                          <span className='truncate text-sm font-medium'>{row.name}</span>\n                          <span className='text-muted-foreground truncate text-xs'>\n                            {row.location}\n                          </span>\n                        </span>\n                        <span className='text-sm tabular-nums'>\n                          {percent(row.stored / (row.capacity || 1))}\n                        </span>\n                      </div>\n                      <GoalProgress\n                        color={fill.color}\n                        current={row.stored}\n                        expected={row.capacity * warnAt}\n                        projected={row.after}\n                        target={row.capacity}\n                      />\n                      <p className='text-muted-foreground flex flex-wrap justify-between gap-x-3 gap-y-1 text-xs tabular-nums'>\n                        <span>\n                          {joinDetails(\n                            `${formatNumber(row.stored)} of ${formatNumber(row.capacity)} units`,\n                            row.inbound\n                              ? `${formatNumber(row.inbound)} arriving takes it to ${percent(row.ratio)}`\n                              : 'nothing arriving',\n                          )}\n                        </span>\n                        {row.fill !== 'ok' && (\n                          <StatusLabel className='text-xs' tone={fill.tone}>\n                            {fill.label}\n                          </StatusLabel>\n                        )}\n                      </p>\n                    </li>\n                  )\n                })}\n              </ul>\n            )}\n            {(state === undefined || state === 'loading') && (\n              <div className='text-muted-foreground flex flex-wrap gap-x-4 gap-y-1 text-xs'>\n                <GoalProgressKey label='Stored' shape='progress' />\n                <GoalProgressKey label='Arriving this week' shape='projected' />\n                <GoalProgressKey label={`Nearly full, ${percent(warnAt)}`} />\n              </div>\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Inventory2,\n  exampleProps as inventory2ExampleProps,\n  type Inventory2Props,\n  type Warehouse,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/inventory/inventory-02.tsx"
    }
  ],
  "meta": {
    "shows": "Units stored against capacity in each warehouse, with what arrives this week and which will be nearly full.",
    "size": "half",
    "usedWith": [
      "inventory-01",
      "inventory-03"
    ],
    "component": "Inventory2",
    "props": "{ description?: string; title: string; warehouses?: { capacity: number; inbound?: number; location: string; name: string; stored: number }[]; warnAt?: number; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
