{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "geo-04",
  "description": "Revenue split across regions, each with its share and its change on the previous quarter.",
  "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/kpi.json",
    "https://www.dashboardblocks.com/r/radix/table.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/geo/geo-04.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  BreakdownBar,\n  BreakdownKey,\n  formatShare,\n} from '@/registry/components/dashboardblocks/breakdown'\nimport { KPIChange, KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport {\n  DataTable,\n  DataTableBody,\n  DataTableCell,\n  DataTableHead,\n  DataTableHeader,\n  DataTableRow,\n  DataTableRowHead,\n} from '@/registry/components/dashboardblocks/table'\nimport { formatCurrency, formatNumber } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Region {\n  color: string\n  current: number\n  label: string\n  previous: number\n}\n\ninterface Geo4Props extends BlockStateProps {\n  /** Follows the previous value in a sentence, such as `in Q2`. */\n  comparison: string\n  /** Defaults to a sentence about the fastest-growing region. */\n  description?: string\n  formatter?: (value: number) => string\n  /** Leave out, or pass none, to show the empty state. */\n  regions?: Region[]\n  title: string\n}\n\nconst currency = (value: number) => formatCurrency(value, { compact: true })\n\nconst exampleProps: Geo4Props = {\n  comparison: 'in Q2',\n  formatter: currency,\n  regions: [\n    {\n      color: 'var(--color-chart-2)',\n      current: 1_284_600,\n      label: 'North America',\n      previous: 1_196_300,\n    },\n    {\n      color: 'var(--color-chart-3)',\n      current: 912_400,\n      label: 'Europe',\n      previous: 861_900,\n    },\n    {\n      color: 'var(--color-chart-4)',\n      current: 538_700,\n      label: 'Asia Pacific',\n      previous: 462_100,\n    },\n    {\n      color: 'var(--color-chart-5)',\n      current: 186_300,\n      label: 'Latin America',\n      previous: 191_800,\n    },\n    {\n      color: 'var(--color-chart-1)',\n      current: 97_900,\n      label: 'Middle East & Africa',\n      previous: 84_600,\n    },\n  ],\n  title: 'Revenue by region',\n}\n\nconst Geo4 = (props: Geo4Props) => {\n  const {\n    comparison,\n    formatter = (value: number) => formatNumber(value),\n    regions = [],\n    errorMessage,\n    status,\n    title,\n  } = props\n  const state = getBlockState(status, regions)\n  const total = regions.reduce((sum, region) => sum + region.current, 0)\n  const previousTotal = regions.reduce((sum, region) => sum + region.previous, 0)\n  const growth = (region: Region) =>\n    region.previous > 0 ? region.current / region.previous - 1 : 0\n  const fastest = regions.reduce<Region | null>(\n    (best, region) => (best === null || growth(region) > growth(best) ? region : best),\n    null,\n  )\n  const {\n    description = fastest\n      ? `${fastest.label} grew fastest, by ${formatShare(fastest.current - fastest.previous, fastest.previous, 1)}.`\n      : undefined,\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                {description && (\n                  <p className='text-muted-foreground text-sm'>{description}</p>\n                )}\n              </BlockReady>\n            </header>\n            <div className='flex flex-col gap-1 border-t pt-4'>\n              <KPIValue value={total} format={formatter} />\n              <KPIChange comparison={comparison} previous={previousTotal} value={total} />\n            </div>\n            <BreakdownBar\n              segments={regions.map((region) => ({\n                color: region.color,\n                label: region.label,\n                value: region.current,\n              }))}\n            />\n            {state === 'loading' && <BlockStateRows rows={5} />}\n            {!state && (\n              <DataTable\n                density='compact'\n                caption={`${title}, with the change on the amount ${comparison}`}\n              >\n                <DataTableHeader>\n                  <DataTableRow>\n                    <DataTableHead>Region</DataTableHead>\n                    <DataTableHead align='end'>Revenue</DataTableHead>\n                    <DataTableHead align='end' className='w-24'>\n                      Change\n                    </DataTableHead>\n                  </DataTableRow>\n                </DataTableHeader>\n                <DataTableBody>\n                  {regions.map((region) => (\n                    <DataTableRow key={region.label}>\n                      <DataTableRowHead>\n                        <span className='flex items-start gap-2'>\n                          <BreakdownKey color={region.color} className='mt-1' />\n                          <span className='flex min-w-0 flex-col @md:flex-row @md:gap-2'>\n                            <span>{region.label}</span>\n                            <span className='text-muted-foreground text-xs tabular-nums @md:text-sm'>\n                              {formatShare(region.current, total, 1)}\n                              <span className='sr-only'> of revenue</span>\n                            </span>\n                          </span>\n                        </span>\n                      </DataTableRowHead>\n                      <DataTableCell align='end' className='align-top font-medium'>\n                        {formatter(region.current)}\n                      </DataTableCell>\n                      <DataTableCell align='end' className='align-top'>\n                        <KPIChange\n                          inline\n                          className='text-xs'\n                          comparison={comparison}\n                          previous={region.previous}\n                          value={region.current}\n                          variant='short'\n                        />\n                      </DataTableCell>\n                    </DataTableRow>\n                  ))}\n                </DataTableBody>\n              </DataTable>\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Geo4, exampleProps as geo4ExampleProps, type Geo4Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/geo/geo-04.tsx"
    }
  ],
  "meta": {
    "shows": "Revenue split across regions, each with its share and its change on the previous quarter.",
    "size": "half",
    "usedWith": [
      "heatmap-01",
      "billing-01"
    ],
    "component": "Geo4",
    "props": "{ comparison: string; description?: string; formatter?: (value: number) => string; regions?: { color: string; current: number; label: string; previous: number }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
