{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "flow-03",
  "description": "Revenue streams into total revenue, then out to costs and profit, with each part's share of revenue.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart-panel.json",
    "https://www.dashboardblocks.com/r/radix/flow.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/flow/flow-03.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  SkeletonText,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { ChartPanelTable } from '@/registry/components/dashboardblocks/chart-panel'\nimport {\n  FlowChart,\n  type FlowLink,\n  type FlowNode,\n  getFlowTotals,\n} from '@/registry/components/dashboardblocks/flow'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport { formatCurrency, formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Flow3Props extends BlockStateProps {\n  /** @default 'USD' */\n  currency?: string\n  description: string\n  /** Leave out, or pass none, to show the empty state. */\n  links?: FlowLink[]\n  nodes?: FlowNode[]\n  /** Node ids for the headline figures. */\n  totals: { grossProfit?: string; profit: string; revenue: string }\n  title: string\n}\n\nconst COST = 'color-mix(in oklab, var(--color-destructive) 75%, var(--color-background))'\nconst PROFIT = 'var(--color-chart-3)'\n\nconst exampleProps: Flow3Props = {\n  description: 'Where revenue went, Q3 2026.',\n  links: [\n    { source: 'subscriptions', target: 'revenue', value: 3_860_000 },\n    { source: 'services', target: 'revenue', value: 940_000 },\n    { source: 'marketplace', target: 'revenue', value: 520_000 },\n    { source: 'revenue', target: 'cost-of-revenue', value: 1_380_000 },\n    { source: 'revenue', target: 'gross-profit', value: 3_940_000 },\n    { source: 'gross-profit', target: 'r-and-d', value: 1_420_000 },\n    { source: 'gross-profit', target: 'sales-marketing', value: 1_310_000 },\n    { source: 'gross-profit', target: 'g-and-a', value: 480_000 },\n    { source: 'gross-profit', target: 'operating-profit', value: 730_000 },\n  ],\n  nodes: [\n    { id: 'subscriptions', label: 'Subscriptions' },\n    { id: 'services', label: 'Services' },\n    { id: 'marketplace', label: 'Marketplace' },\n    { color: 'var(--color-primary)', id: 'revenue', label: 'Revenue' },\n    { color: PROFIT, id: 'gross-profit', label: 'Gross profit' },\n    { color: COST, id: 'cost-of-revenue', label: 'Cost of revenue' },\n    { color: PROFIT, id: 'operating-profit', label: 'Operating profit' },\n    { color: COST, id: 'r-and-d', label: 'R&D' },\n    { color: COST, id: 'sales-marketing', label: 'Sales & marketing' },\n    { color: COST, id: 'g-and-a', label: 'G&A' },\n  ],\n  title: 'Income flow',\n  totals: { grossProfit: 'gross-profit', profit: 'operating-profit', revenue: 'revenue' },\n}\n\nconst Flow3 = (props: Flow3Props) => {\n  const {\n    currency = 'USD',\n    description,\n    links = [],\n    nodes = [],\n    errorMessage,\n    status,\n    title,\n    totals: ids,\n  } = props\n  const state = getBlockState(status, links)\n  const totals = getFlowTotals(nodes, links)\n  const labels = new Map(nodes.map((node) => [node.id, node.label]))\n  const format = (value: number) => formatCurrency(value, { compact: true, currency })\n  const revenue = totals.get(ids.revenue)?.in ?? 0\n  const profit = totals.get(ids.profit)?.in ?? 0\n  const gross = ids.grossProfit ? totals.get(ids.grossProfit)?.in : undefined\n  const margin = (value: number) => formatPercent(value / (revenue || 1))\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              <p className='text-muted-foreground text-sm'>{description}</p>\n            </header>\n            {state === 'empty' || state === 'error' ? (\n              <div className='border-t pt-4'>\n                <KPIValue />\n              </div>\n            ) : (\n              <dl className='grid grid-cols-2 gap-x-6 gap-y-4 border-t pt-4 @lg:grid-cols-3 @lg:items-start'>\n                <div className='col-span-2 flex flex-col gap-1 @lg:col-span-1'>\n                  <dt className='text-muted-foreground text-sm'>\n                    {state ? <SkeletonText className='w-16' /> : labels.get(ids.revenue)}\n                  </dt>\n                  <dd>\n                    <KPIValue value={revenue} format={format} />\n                  </dd>\n                </div>\n                {(state ? ids.grossProfit : gross !== undefined) && (\n                  <div className='flex flex-col gap-1'>\n                    <dt className='text-muted-foreground text-sm'>Gross margin</dt>\n                    <dd>\n                      <KPIValue className='text-2xl' value={gross} format={margin} />\n                    </dd>\n                  </div>\n                )}\n                <div className='flex flex-col gap-1'>\n                  <dt className='text-muted-foreground text-sm'>Operating margin</dt>\n                  <dd>\n                    <KPIValue className='text-2xl' value={profit} format={margin} />\n                  </dd>\n                  <BlockReady className='text-xs'>\n                    <dd className='text-muted-foreground text-xs tabular-nums'>\n                      {format(profit)} kept\n                    </dd>\n                  </BlockReady>\n                </div>\n              </dl>\n            )}\n            <FlowChart\n              colorBy='target'\n              describeLink={(link) => `${margin(link.value)} of revenue`}\n              describeNode={(node) => `${margin(node.value)} of revenue`}\n              format={format}\n              height={300}\n              label={title}\n              links={links}\n              minWidth='36rem'\n              nodes={nodes}\n            />\n            <ChartPanelTable\n              caption={`${title}: ${description}`}\n              columns={[\n                { key: 'source', label: 'From' },\n                { key: 'target', label: 'To' },\n                { key: 'value', label: 'Amount' },\n                { key: 'share', label: 'Share of revenue' },\n              ]}\n              rows={links.map((link) => ({\n                share: margin(link.value),\n                source: labels.get(link.source) ?? link.source,\n                target: labels.get(link.target) ?? link.target,\n                value: format(link.value),\n              }))}\n            />\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Flow3, exampleProps as flow3ExampleProps, type Flow3Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/flow/flow-03.tsx"
    }
  ],
  "meta": {
    "shows": "Revenue streams into total revenue, then out to costs and profit, with each part's share of revenue.",
    "size": "full",
    "usedWith": [
      "spend-02",
      "billing-01"
    ],
    "component": "Flow3",
    "props": "{ currency?: string; description: string; links?: { source: string; target: string; value: number }[]; nodes?: { color?: string; id: string; kind?: \"default\" | \"exit\" | \"gap\"; label: string }[]; totals: { grossProfit?: string; profit: string; revenue: string }; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
