{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "area-chart-kpi-01",
  "description": "Gross profit with its margin, and profit inside revenue by day, with the best margin day.",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/chart.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/kpi/area-chart-kpi-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { TinyAreaChart } from '@/registry/components/dashboardblocks/chart'\nimport {\n  KPI,\n  KPIChange,\n  KPIChart,\n  KPIContent,\n  KPITitle,\n  type KPIFormat,\n  KPIValue,\n  getKPIFormatter,\n} from '@/registry/components/dashboardblocks/kpi'\nimport { formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface DailyProfit {\n  label: string\n  profit: number\n  revenue: number\n}\n\ninterface AreaChartKPI1Props extends BlockStateProps {\n  comparison: string\n  /** Leave out, or pass no days, to show the empty state. */\n  data?: DailyProfit[]\n  format?: KPIFormat\n  /** @default 112 */\n  height?: number\n  previous?: number\n  title: string\n}\n\nconst exampleProps: AreaChartKPI1Props = {\n  comparison: 'last week',\n  data: [\n    { label: 'Mon', profit: 1_200, revenue: 4_200 },\n    { label: 'Tue', profit: 1_500, revenue: 5_100 },\n    { label: 'Wed', profit: 800, revenue: 2_800 },\n    { label: 'Thu', profit: 1_600, revenue: 5_600 },\n    { label: 'Fri', profit: 1_800, revenue: 6_300 },\n    { label: 'Sat', profit: 1_400, revenue: 5_400 },\n    { label: 'Sun', profit: 2_000, revenue: 6_900 },\n  ],\n  format: 'currency',\n  previous: 9_550,\n  title: 'Gross profit',\n}\n\nconst AreaChartKPI1 = (props: AreaChartKPI1Props) => {\n  const {\n    comparison,\n    data = [],\n    format,\n    height = 112,\n    previous,\n    errorMessage,\n    status,\n    title,\n  } = props\n  const formatter = getKPIFormatter(format)\n  const profit = data.reduce((sum, point) => sum + point.profit, 0)\n  const revenue = data.reduce((sum, point) => sum + point.revenue, 0)\n  const margin = (point: { profit: number; revenue: number }) =>\n    point.revenue > 0 ? point.profit / point.revenue : 0\n  const best = data.reduce(\n    (top, point) => (margin(point) > margin(top) ? point : top),\n    data[0],\n  )\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={getBlockState(status, data)}>\n      <Card>\n        <CardContent>\n          <KPI>\n            <KPIContent className='gap-3'>\n              <div className='flex flex-col gap-1'>\n                <KPITitle>{title}</KPITitle>\n                <KPIValue value={profit} format={format} animated />\n                <KPIChange comparison={comparison} previous={previous} value={profit} />\n              </div>\n              <KPIChart\n                label={`Revenue and profit by day: ${data\n                  .map(\n                    (point) =>\n                      `${point.label} ${formatter(point.revenue)} revenue, ${formatter(point.profit)} profit`,\n                  )\n                  .join('; ')}`}\n              >\n                <TinyAreaChart\n                  accessibilityLayer={false}\n                  areas={[\n                    {\n                      dataKey: 'revenue',\n                      fill: 'var(--color-chart-2)',\n                      fillOpacity: 0.12,\n                      name: 'Revenue',\n                      stroke:\n                        'color-mix(in oklab, var(--color-chart-2) 40%, transparent)',\n                      strokeWidth: 1.5,\n                    },\n                    {\n                      dataKey: 'profit',\n                      fill: 'var(--color-chart-2)',\n                      fillOpacity: 0.45,\n                      name: 'Profit',\n                      stroke: 'var(--color-chart-2)',\n                    },\n                  ]}\n                  data={data}\n                  formatter={formatter}\n                  height={height}\n                  markLast='profit'\n                  xAxisKey='label'\n                />\n              </KPIChart>\n              <BlockReady className='text-xs'>\n                <p className='text-muted-foreground text-xs'>\n                  <span className='text-foreground font-medium tabular-nums'>\n                    {formatPercent(margin({ profit, revenue }))}\n                  </span>{' '}\n                  margin on {formatter(revenue)} revenue\n                  {best && (\n                    <>\n                      , best on {best.label} at{' '}\n                      <span className='tabular-nums'>{formatPercent(margin(best))}</span>\n                    </>\n                  )}\n                  . The light area is revenue, the dark one profit.\n                </p>\n              </BlockReady>\n            </KPIContent>\n          </KPI>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  AreaChartKPI1,\n  exampleProps as areaChartKpi1ExampleProps,\n  type AreaChartKPI1Props,\n  type DailyProfit,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/kpi/area-chart-kpi-01.tsx"
    }
  ],
  "meta": {
    "shows": "Gross profit with its margin, and profit inside revenue by day, with the best margin day.",
    "size": "compact",
    "usedWith": [
      "spend-01",
      "chart-panel-04",
      "stat-group-02"
    ],
    "component": "AreaChartKPI1",
    "props": "{ comparison: string; data?: { label: string; profit: number; revenue: number }[]; format?: \"number\" | \"compact\" | \"currency\" | \"currency-compact\" | \"percent\"; height?: number; previous?: number; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
