{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dashboard-01",
  "title": "Store dashboard",
  "description": "A store dashboard: header filters scope stats, revenue, channels, products, a checkout funnel and month-to-date revenue, with low stock alongside.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/breakdown-01.json",
    "https://www.dashboardblocks.com/r/radix/chart-panel-01.json",
    "https://www.dashboardblocks.com/r/radix/dashboard-header.json",
    "https://www.dashboardblocks.com/r/radix/data-table-02.json",
    "https://www.dashboardblocks.com/r/radix/forecast-03.json",
    "https://www.dashboardblocks.com/r/radix/funnel-01.json",
    "https://www.dashboardblocks.com/r/radix/inventory-01.json",
    "https://www.dashboardblocks.com/r/radix/stat-group-02.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/dashboards/dashboard-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockBusy,\n  BlockStateProvider,\n  type BlockStateProps,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { BREAKDOWN_OTHER_COLOR } from '@/registry/components/dashboardblocks/breakdown'\nimport { Breakdown1 } from '@/registry/components/dashboardblocks/breakdown/breakdown-01'\nimport { ChartPanel1 } from '@/registry/components/dashboardblocks/chart-panel/chart-panel-01'\nimport {\n  CompareToggle,\n  type DateRangePreset,\n  DateRangePicker,\n  ExportMenu,\n  FilterChip,\n  FilterMenu,\n  getDateRange,\n  getPreset,\n  getPreviousRange,\n} from '@/registry/components/dashboardblocks/dashboard-header'\nimport { DataTable2 } from '@/registry/components/dashboardblocks/data-table/data-table-02'\nimport { Forecast3 } from '@/registry/components/dashboardblocks/forecast/forecast-03'\nimport { Funnel1 } from '@/registry/components/dashboardblocks/funnel/funnel-01'\nimport { Inventory1 } from '@/registry/components/dashboardblocks/inventory/inventory-01'\nimport { StatGroup2 } from '@/registry/components/dashboardblocks/stat-group/stat-group-02'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport {\n  formatCurrency,\n  formatDate,\n  formatDateRange,\n  formatPercent,\n} from '@/registry/lib/dashboardblocks/format'\nimport { useEffect, useState } from 'react'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Dashboard1Props extends BlockStateProps {\n  empty?: boolean\n  title: string\n  /** The last day of every date range. */\n  today: Date\n}\n\nconst exampleProps: Dashboard1Props = {\n  title: 'Store overview',\n  today: new Date(Date.UTC(2026, 8, 25)),\n}\n\nconst REGIONS = [\n  { name: 'North America', phase: 0, share: 0.48 },\n  { name: 'Europe', phase: 1.3, share: 0.34 },\n  { name: 'Asia Pacific', phase: 2.6, share: 0.18 },\n]\n\nconst CHANNELS = [\n  { color: 'var(--color-chart-2)', label: 'Organic search', share: 0.38 },\n  { color: 'var(--color-chart-3)', label: 'Paid search', share: 0.27 },\n  { color: 'var(--color-chart-4)', label: 'Email', share: 0.17 },\n  { color: BREAKDOWN_OTHER_COLOR, label: 'Other', share: 0.18 },\n]\n\nconst PRODUCTS = [\n  { category: 'Displays', name: 'Studio Display 27\"', price: 437, share: 0.29 },\n  { category: 'Audio', name: 'Wireless headphones', price: 144, share: 0.24 },\n  { category: 'Furniture', name: 'Ergonomic chair', price: 435, share: 0.21 },\n  { category: 'Accessories', name: 'Mechanical keyboard', price: 120, share: 0.13 },\n  { category: 'Accessories', name: 'USB-C dock', price: 90, share: 0.08 },\n  { category: 'Audio', name: 'Desk speakers', price: 90, share: 0.05 },\n]\n\nconst STOCK = [\n  {\n    dailyDemand: 9,\n    leadTimeDays: 12,\n    name: 'Studio Display 27\"',\n    onHand: 0,\n    reorderPoint: 110,\n    sku: 'SD-27-SLV',\n  },\n  {\n    dailyDemand: 21,\n    leadTimeDays: 8,\n    name: 'Wireless headphones',\n    onHand: 64,\n    onOrder: 200,\n    reorderPoint: 170,\n    sku: 'WH-01-BLK',\n  },\n  {\n    dailyDemand: 6,\n    leadTimeDays: 21,\n    name: 'Ergonomic chair',\n    onHand: 88,\n    reorderPoint: 126,\n    sku: 'EC-02-GRY',\n  },\n  {\n    dailyDemand: 14,\n    leadTimeDays: 6,\n    name: 'USB-C dock',\n    onHand: 131,\n    reorderPoint: 84,\n    sku: 'UD-11-GRY',\n  },\n]\n\nconst DAILY_TARGET = 1_750\n\ninterface Query {\n  compare: boolean\n  preset: DateRangePreset\n  region: string | null\n}\n\nconst revenueAt = (offset: number, region: string | null, hourly: boolean) => {\n  const regions = region ? REGIONS.filter((item) => item.name === region) : REGIONS\n  return regions.reduce((sum, { phase, share }) => {\n    if (hourly) {\n      const hour = 23 - offset\n      const curve =\n        Math.exp(-((hour - 14) ** 2) / 20) + 0.35 * Math.exp(-((hour - 21) ** 2) / 6)\n      return sum + share * (20 + 170 * curve)\n    }\n    const weekend = (offset + 2) % 7 < 2 ? 0.8 : 1\n    const trend = 1_700 - offset * 3.2\n    const wave =\n      Math.sin(offset / 3.1 + phase) * 180 + Math.sin(offset / 11 + phase) * 120\n    return sum + share * (trend + wave) * weekend\n  }, 0)\n}\n\nconst aovAt = (offset: number) => 36.5 + Math.sin(offset / 5) * 1.6\nconst conversionAt = (offset: number) => 0.031 + Math.sin(offset / 7 + 1) * 0.003\n\nconst splitTotal = (total: number, shares: number[]) => {\n  const parts = shares.map((share) => Math.round(total * share))\n  parts[parts.length - 1] =\n    total - parts.slice(0, -1).reduce((sum, part) => sum + part, 0)\n  return parts\n}\n\nconst currency = (value: number) => formatCurrency(value)\n\nfunction buildStoreData({ compare, preset, region }: Query, today: Date) {\n  const hourly = preset === 'today'\n  const length = hourly ? 24 : getPreset(preset).days\n  const range = getDateRange(preset, today)\n  const previousRange = getPreviousRange(range)\n\n  const series = (shift: number) =>\n    Array.from({ length }, (_, index) => {\n      const offset = length - 1 - index + shift\n      const revenue = Math.round(revenueAt(offset, region, hourly))\n      const orders = revenue / aovAt(offset)\n      return { offset, orders, revenue, sessions: orders / conversionAt(offset) }\n    })\n  const current = series(0)\n  const previous = series(length)\n  const sum = (points: typeof current, key: 'orders' | 'revenue' | 'sessions') =>\n    points.reduce((total, point) => total + point[key], 0)\n\n  const totals = (points: typeof current) => {\n    const revenue = sum(points, 'revenue')\n    const orders = sum(points, 'orders')\n    const sessions = sum(points, 'sessions')\n    return {\n      aov: revenue / orders,\n      conversion: (orders / sessions) * 100,\n      orders,\n      revenue,\n      sessions,\n    }\n  }\n  const now = totals(current)\n  const before = totals(previous)\n  const label = (index: number) => {\n    if (hourly) return `${String(index).padStart(2, '0')}:00`\n    const date = new Date(range.start.getTime() + index * 86_400_000)\n    return formatDate(date, 'day')\n  }\n  const elapsed = today.getUTCDate()\n  const daysInMonth = new Date(\n    Date.UTC(today.getUTCFullYear(), today.getUTCMonth() + 1, 0),\n  ).getUTCDate()\n  const regionShare = region\n    ? (REGIONS.find((item) => item.name === region)?.share ?? 1)\n    : 1\n  const rangeLabel = formatDateRange(range)\n  const previousLabel = formatDateRange(previousRange)\n\n  const best = current.reduce(\n    (top, point, index) => (point.revenue > current[top].revenue ? index : top),\n    0,\n  )\n  const channels = splitTotal(\n    now.revenue,\n    CHANNELS.map((channel, index) => channel.share + (region ? (index - 1.5) * 0.02 : 0)),\n  ).map((value, index) => ({\n    color: CHANNELS[index].color,\n    label: CHANNELS[index].label,\n    value,\n  }))\n  const search = channels\n    .filter((channel) => channel.label.endsWith('search'))\n    .reduce((sum, channel) => sum + channel.value, 0)\n\n  return {\n    bestDay: `${hourly ? 'Busiest hour' : 'Best day'} was ${label(best)}, at ${currency(current[best].revenue)}.`,\n    channels,\n    channelSummary: `Search brings in ${formatPercent(search / now.revenue, { maximumFractionDigits: 0 })} of revenue.`,\n    chart: current.map((point, index) => ({\n      current: Math.round(point.revenue),\n      label: label(index),\n      previous: Math.round(previous[index].revenue),\n    })),\n    month: {\n      current: Array.from({ length: elapsed }, (_, offset) =>\n        Math.round(revenueAt(offset, region, false)),\n      ).reduce((sum, value) => sum + value, 0),\n      elapsed,\n      name: formatDate(today, 'month-long'),\n      target: Math.round((DAILY_TARGET * daysInMonth * regionShare) / 1_000) * 1_000,\n      total: daysInMonth,\n    },\n    funnel: [\n      { label: 'Sessions', value: Math.round(now.sessions) },\n      { label: 'Viewed a product', value: Math.round(now.sessions * 0.62) },\n      { label: 'Added to cart', value: Math.round(now.sessions * 0.17) },\n      { label: 'Started checkout', value: Math.round(now.sessions * 0.071) },\n      { label: 'Purchased', value: Math.round(now.orders) },\n    ],\n    previousLabel,\n    products: splitTotal(\n      now.revenue,\n      PRODUCTS.map((product) => product.share),\n    ).map((revenue, index) => ({\n      category: PRODUCTS[index].category,\n      name: PRODUCTS[index].name,\n      revenue,\n      units: Math.max(1, Math.round(revenue / PRODUCTS[index].price)),\n    })),\n    rangeLabel,\n    stats: [\n      {\n        history: current.map((point) => Math.round(point.sessions)),\n        key: 'sessions',\n        label: 'Sessions',\n        previous: compare ? Math.round(before.sessions) : undefined,\n        value: Math.round(now.sessions),\n      },\n      {\n        history: current.map((point) => Math.round(point.orders)),\n        key: 'orders',\n        label: 'Orders',\n        previous: compare ? Math.round(before.orders) : undefined,\n        value: Math.round(now.orders),\n      },\n      {\n        formatter: (value: number) => formatCurrency(value, { precision: 'exact' }),\n        history: current.map((point) =>\n          Number((point.revenue / point.orders).toFixed(2)),\n        ),\n        key: 'aov',\n        label: 'Avg order value',\n        previous: compare ? Number(before.aov.toFixed(2)) : undefined,\n        value: Number(now.aov.toFixed(2)),\n      },\n      {\n        changeType: 'points' as const,\n        formatter: (value: number) => formatPercent(value / 100),\n        history: current.map((point) =>\n          Number(((point.orders / point.sessions) * 100).toFixed(1)),\n        ),\n        key: 'conversion',\n        label: 'Conversion rate',\n        previous: compare ? Number(before.conversion.toFixed(1)) : undefined,\n        value: Number(now.conversion.toFixed(1)),\n      },\n    ],\n  }\n}\n\nconst Dashboard1 = (props: Dashboard1Props) => {\n  const { empty = false, errorMessage, status, title, today } = props\n  const [query, setQuery] = useState<Query>({\n    compare: true,\n    preset: '30d',\n    region: null,\n  })\n  const [displayedQuery, setDisplayedQuery] = useState(query)\n  const busy = displayedQuery !== query\n\n  useEffect(() => {\n    if (displayedQuery === query) return\n    const timer = setTimeout(() => setDisplayedQuery(query), 500)\n    return () => clearTimeout(timer)\n  }, [query, displayedQuery])\n\n  const update = (patch: Partial<Query>) =>\n    setQuery((current) => ({ ...current, ...patch }))\n  const data = buildStoreData(displayedQuery, today)\n  const range = getDateRange(query.preset, today)\n\n  return (\n    <BlockStateProvider\n      errorMessage={errorMessage}\n      state={status ?? (empty ? 'empty' : undefined)}\n    >\n      <div className='@container flex w-full flex-col gap-8'>\n        <header className='flex flex-col gap-2'>\n          <div className='flex flex-wrap items-start justify-between gap-3'>\n            <h1 className='min-w-0 text-2xl font-semibold tracking-tight'>{title}</h1>\n            <div className='flex items-center gap-3'>\n              <CompareToggle\n                checked={query.compare}\n                onCheckedChange={(compare) => update({ compare })}\n              />\n              <ExportMenu disabled={status !== undefined || empty} onExport={() => {}} />\n            </div>\n          </div>\n          <div className='flex flex-wrap items-center justify-between gap-x-4 gap-y-2'>\n            <p className='text-muted-foreground min-w-0 leading-relaxed'>\n              Showing{' '}\n              <DateRangePicker\n                onValueChange={(preset) => update({ preset })}\n                today={today}\n                value={query.preset}\n                variant='inline'\n              />\n              <span aria-live='polite'>\n                , {formatDateRange(range)}\n                {query.compare &&\n                  `, compared with ${formatDateRange(getPreviousRange(range))}`}\n                .\n              </span>\n            </p>\n            <div className='flex flex-wrap items-center gap-2'>\n              {query.region && (\n                <FilterChip\n                  field='Region'\n                  value={query.region}\n                  onRemove={() => update({ region: null })}\n                />\n              )}\n              <FilterMenu\n                allLabel='All regions'\n                label='Region'\n                onValueChange={(region) => update({ region })}\n                options={REGIONS.map((item) => item.name)}\n                value={query.region}\n              >\n                <IconPlaceholder\n                  lucide='MapPinIcon'\n                  tabler='IconMapPin'\n                  hugeicons='Location01Icon'\n                  phosphor='MapPinIcon'\n                  remixicon='RiMapPinLine'\n                />\n                {query.region ? 'Change region' : 'Filter by region'}\n              </FilterMenu>\n            </div>\n          </div>\n        </header>\n        <BlockBusy\n          busy={busy}\n          label='Updating the dashboard'\n          className='grid gap-4 @4xl:grid-cols-3'\n        >\n          <div className='grid @4xl:col-span-3'>\n            <StatGroup2\n              errorMessage={errorMessage}\n              status={status}\n              comparison={data.previousLabel}\n              description={\n                displayedQuery.compare\n                  ? undefined\n                  : 'Sessions, orders, order value and conversion, by day.'\n              }\n              metrics={empty ? [] : data.stats}\n              title='Shoppers and orders'\n            />\n          </div>\n          <div className='grid @4xl:col-span-2'>\n            <ChartPanel1\n              errorMessage={errorMessage}\n              status={status}\n              comparison={`in ${data.previousLabel}`}\n              currentLabel={data.rangeLabel}\n              data={empty ? [] : data.chart}\n              description={status || empty ? '' : data.bestDay}\n              formatter={currency}\n              previousLabel={data.previousLabel}\n              showPrevious={displayedQuery.compare}\n              title='Revenue'\n            />\n          </div>\n          <Forecast3\n            errorMessage={errorMessage}\n            status={status}\n            current={empty ? undefined : data.month.current}\n            description='Projected at the daily run-rate.'\n            elapsed={data.month.elapsed}\n            formatter={currency}\n            target={data.month.target}\n            title={`${data.month.name} revenue`}\n            total={data.month.total}\n          />\n          <div className='grid @4xl:col-span-2'>\n            <Card>\n              <CardContent>\n                <DataTable2\n                  errorMessage={errorMessage}\n                  status={status}\n                  rows={empty ? [] : data.products}\n                  title='Revenue by product'\n                />\n              </CardContent>\n            </Card>\n          </div>\n          <Funnel1\n            errorMessage={errorMessage}\n            status={status}\n            description='Most shoppers leave before adding to cart.'\n            stages={empty ? [] : data.funnel}\n            title='Checkout funnel'\n          />\n          <div className='grid @4xl:col-span-2'>\n            <Inventory1\n              errorMessage={errorMessage}\n              status={status}\n              items={empty ? [] : STOCK}\n              title='Low stock'\n            />\n          </div>\n          <Breakdown1\n            errorMessage={errorMessage}\n            status={status}\n            description={status || empty ? '' : data.channelSummary}\n            formatter={currency}\n            segments={empty ? [] : data.channels}\n            title='Revenue by channel'\n          />\n        </BlockBusy>\n      </div>\n    </BlockStateProvider>\n  )\n}\n\nexport { Dashboard1, exampleProps as dashboard1ExampleProps, type Dashboard1Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/dashboards/dashboard-01.tsx"
    }
  ],
  "meta": {
    "shows": "A full store dashboard with revenue, sales channels, top products, a checkout funnel and low stock, scoped by header filters.",
    "size": "page",
    "usedWith": [],
    "component": "Dashboard1",
    "props": "{ empty?: boolean; title: string; today: Date; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:block"
}
