{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "inventory-04",
  "description": "One item's stock day by day at its current demand, with incoming orders, the reorder point and when it runs out.",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart.json",
    "https://www.dashboardblocks.com/r/radix/chart-panel.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/inventory.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/inventory/inventory-04.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateText,\n  type BlockStateProps,\n  SkeletonText,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  ChartPlaceholder,\n  chartActiveDot,\n  chartAxisProps,\n  chartGridProps,\n  chartLineCursor,\n  chartReferenceLabel,\n  chartReferenceProps,\n  ChartTooltipContent,\n  chartValueAxisWidth,\n  useChartId,\n} from '@/registry/components/dashboardblocks/chart'\nimport {\n  ChartPanelFigure,\n  ChartPanelLegend,\n  ChartPanelTable,\n} from '@/registry/components/dashboardblocks/chart-panel'\nimport {\n  StockStatusLabel,\n  getStockStatus,\n  projectStock,\n} from '@/registry/components/dashboardblocks/inventory'\nimport { formatDate, formatNumber } from '@/registry/lib/dashboardblocks/format'\nimport {\n  Area,\n  AreaChart,\n  CartesianGrid,\n  ReferenceDot,\n  ReferenceLine,\n  ResponsiveContainer,\n  Tooltip,\n  XAxis,\n  YAxis,\n} from 'recharts'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface IncomingOrder {\n  day: number\n  quantity: number\n}\n\ninterface Inventory4Props extends BlockStateProps {\n  dailyDemand: number\n  /** Defaults to a sentence saying when stock runs out. */\n  description?: string\n  horizon?: number\n  incoming?: IncomingOrder[]\n  /** Pass a fixed date, so the block renders the same on the server and in the browser. */\n  now: Date\n  /** Leave out to show the empty state. */\n  onHand?: number\n  /** Names the item in the default description, such as `the merino socks 3-pack`. */\n  product: string\n  reorderPoint: number\n  title: string\n}\n\nconst exampleProps: Inventory4Props = {\n  dailyDemand: 22,\n  incoming: [{ day: 9, quantity: 360 }],\n  now: new Date(Date.UTC(2026, 8, 26)),\n  onHand: 238,\n  product: 'the merino socks 3-pack',\n  reorderPoint: 180,\n  title: 'Stock projection',\n}\n\nconst DAY = 86_400_000\nconst STOCK_COLOR = 'var(--color-chart-2)'\nconst STOCKOUT_COLOR = 'var(--color-red-500)'\n\nconst units = (value: number) => `${formatNumber(value)} units`\n\nconst Inventory4 = (props: Inventory4Props) => {\n  const {\n    dailyDemand,\n    horizon = 30,\n    incoming = [],\n    now,\n    onHand,\n    product,\n    reorderPoint,\n    errorMessage,\n    status,\n    title,\n  } = props\n  const state = getBlockState(status, onHand)\n  const ready = state === undefined || state === 'loading'\n  const gradientId = useChartId()\n  const { levels, stockoutDay } = projectStock({\n    dailyDemand,\n    days: horizon,\n    incoming,\n    onHand: onHand ?? 0,\n  })\n  const rows = levels.map((level, day) => ({\n    date: formatDate(new Date(now.getTime() + day * DAY), 'day'),\n    day,\n    stock: Math.max(0, Math.round(level)),\n  }))\n  const stockout = stockoutDay === null ? null : rows[stockoutDay]\n  const lowest = rows.reduce((min, row) => (row.stock < min.stock ? row : min), rows[0])\n  const arriving = incoming.reduce((sum, order) => sum + order.quantity, 0)\n  const {\n    description = stockout\n      ? `At ${formatNumber(dailyDemand)} a day, ${product} runs out on ${stockout.date}, even with what’s on order.`\n      : `At ${formatNumber(dailyDemand)} a day, ${product} lasts the next ${horizon} days.`,\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            <dl className='grid grid-cols-2 gap-x-6 gap-y-4 border-t pt-4 @md:grid-cols-3'>\n              <div className='flex flex-col gap-1'>\n                <dt className='text-muted-foreground text-sm'>On hand</dt>\n                <dd className='text-2xl font-light tracking-tight tabular-nums'>\n                  {state || onHand === undefined ? (\n                    <BlockStateText variant='short' />\n                  ) : (\n                    formatNumber(onHand)\n                  )}\n                </dd>\n                <dd>\n                  <BlockReady className='text-xs'>\n                    <StockStatusLabel\n                      className='text-xs'\n                      status={getStockStatus({ onHand: onHand ?? 0, reorderPoint })}\n                    />\n                  </BlockReady>\n                </dd>\n              </div>\n              {ready && (\n                <div className='flex flex-col gap-1'>\n                  <dt className='text-muted-foreground text-sm'>Lowest point</dt>\n                  <dd className='text-2xl font-light tracking-tight tabular-nums'>\n                    {state ? (\n                      <SkeletonText className='w-16' />\n                    ) : (\n                      formatNumber(lowest.stock)\n                    )}\n                  </dd>\n                  <dd className='text-muted-foreground text-xs'>\n                    <BlockReady className='text-xs'>on {lowest.date}</BlockReady>\n                  </dd>\n                </div>\n              )}\n              {ready && (\n                <div className='col-span-2 flex flex-col gap-1 @md:col-span-1'>\n                  <dt className='text-muted-foreground text-sm'>Runs out</dt>\n                  <dd className='text-2xl font-light tracking-tight'>\n                    {state ? (\n                      <SkeletonText className='w-20' />\n                    ) : stockout ? (\n                      stockout.date\n                    ) : (\n                      `Not in ${horizon} days`\n                    )}\n                  </dd>\n                  <dd className='text-muted-foreground text-xs'>\n                    <BlockReady className='text-xs'>\n                      {incoming.length > 0\n                        ? `${formatNumber(arriving)} arriving ${incoming.map((order) => rows[order.day]?.date).join(', ')}`\n                        : 'Nothing on order'}\n                    </BlockReady>\n                  </dd>\n                </div>\n              )}\n            </dl>\n            {ready && (\n              <ChartPanelLegend\n                items={[\n                  { color: STOCK_COLOR, label: 'Projected stock' },\n                  {\n                    color: 'var(--color-muted-foreground)',\n                    label: 'Reorder point',\n                    shape: 'line',\n                  },\n                ]}\n              />\n            )}\n            {state ? (\n              <ChartPanelFigure className='h-56'>\n                <ChartPlaceholder height='100%' />\n              </ChartPanelFigure>\n            ) : (\n              <>\n                <ChartPanelFigure className='h-56'>\n                  <ResponsiveContainer width='100%' height='100%'>\n                    <AreaChart\n                      data={rows}\n                      margin={{ top: 20, right: 12, bottom: 0, left: 0 }}\n                    >\n                      <defs>\n                        <linearGradient id={gradientId} x1='0' y1='0' x2='0' y2='1'>\n                          <stop offset='0%' stopColor={STOCK_COLOR} stopOpacity={0.3} />\n                          <stop offset='100%' stopColor={STOCK_COLOR} stopOpacity={0} />\n                        </linearGradient>\n                      </defs>\n                      <CartesianGrid {...chartGridProps} />\n                      <XAxis\n                        {...chartAxisProps}\n                        dataKey='date'\n                        interval='preserveStartEnd'\n                        minTickGap={24}\n                      />\n                      <YAxis {...chartAxisProps} width={chartValueAxisWidth} />\n                      <ReferenceLine\n                        {...chartReferenceProps}\n                        label={{\n                          ...chartReferenceLabel,\n                          position: 'insideTopRight',\n                          value: 'Reorder point',\n                        }}\n                        y={reorderPoint}\n                      />\n                      {incoming.map((order) => (\n                        <ReferenceLine\n                          key={order.day}\n                          {...chartReferenceProps}\n                          label={{\n                            ...chartReferenceLabel,\n                            fill: 'var(--color-foreground)',\n                            position: 'top',\n                            value: `+${formatNumber(order.quantity)} arrive`,\n                          }}\n                          x={rows[order.day]?.date}\n                        />\n                      ))}\n                      <Tooltip\n                        content={<ChartTooltipContent valueFormatter={units} />}\n                        cursor={chartLineCursor}\n                      />\n                      <Area\n                        activeDot={chartActiveDot}\n                        dataKey='stock'\n                        fill={`url(#${gradientId})`}\n                        name='Projected stock'\n                        stroke={STOCK_COLOR}\n                        strokeWidth={2}\n                        type='stepAfter'\n                      />\n                      {stockout && (\n                        <ReferenceLine\n                          label={{\n                            ...chartReferenceLabel,\n                            fill: STOCKOUT_COLOR,\n                            position: 'insideTopLeft',\n                            value: 'Runs out',\n                          }}\n                          stroke={STOCKOUT_COLOR}\n                          strokeDasharray='3 3'\n                          x={stockout.date}\n                        />\n                      )}\n                      {stockout && (\n                        <ReferenceDot\n                          fill={STOCKOUT_COLOR}\n                          r={4}\n                          stroke='var(--color-background)'\n                          strokeWidth={2}\n                          x={stockout.date}\n                          y={0}\n                        />\n                      )}\n                    </AreaChart>\n                  </ResponsiveContainer>\n                </ChartPanelFigure>\n                <ChartPanelTable\n                  caption={`${title}: ${description} Reorder point ${formatNumber(reorderPoint)}.`}\n                  columns={[\n                    { key: 'date', label: 'Date' },\n                    { key: 'stock', label: 'Projected stock' },\n                  ]}\n                  rows={rows.filter(\n                    (row) =>\n                      row.day % 5 === 0 ||\n                      incoming.some((order) => order.day === row.day),\n                  )}\n                />\n              </>\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Inventory4,\n  exampleProps as inventory4ExampleProps,\n  type IncomingOrder,\n  type Inventory4Props,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/inventory/inventory-04.tsx"
    }
  ],
  "meta": {
    "shows": "One item's stock day by day at its current demand, with incoming orders, the reorder point and when it runs out.",
    "size": "full",
    "usedWith": [
      "inventory-01",
      "inventory-03"
    ],
    "component": "Inventory4",
    "props": "{ dailyDemand: number; description?: string; horizon?: number; incoming?: { day: number; quantity: number }[]; now: Date; onHand?: number; product: string; reorderPoint: number; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
