{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "flow-01",
  "description": "Sessions from each source through the landing page, to signing up, browsing on or bouncing.",
  "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-01.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 { formatNumber, formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Flow1Props extends BlockStateProps {\n  description: string\n  /** Leave out, or pass none, to show the empty state. */\n  links?: FlowLink[]\n  /** Sources first, then each step, then outcomes. */\n  nodes?: FlowNode[]\n  goal: string\n  title: string\n  /** @default 'sessions' */\n  unit?: string\n}\n\nconst exampleProps: Flow1Props = {\n  description:\n    'Sessions from each source, through the landing page, to the outcome, last 30 days.',\n  goal: 'signed-up',\n  links: [\n    { source: 'organic', target: 'home', value: 18_400 },\n    { source: 'organic', target: 'blog', value: 12_600 },\n    { source: 'organic', target: 'pricing', value: 3_900 },\n    { source: 'paid', target: 'pricing', value: 9_800 },\n    { source: 'paid', target: 'home', value: 4_200 },\n    { source: 'social', target: 'blog', value: 6_300 },\n    { source: 'social', target: 'home', value: 2_100 },\n    { source: 'email', target: 'pricing', value: 3_400 },\n    { source: 'email', target: 'home', value: 1_600 },\n    { source: 'home', target: 'signed-up', value: 3_100 },\n    { source: 'home', target: 'browsed', value: 13_800 },\n    { source: 'home', target: 'bounced', value: 9_400 },\n    { source: 'pricing', target: 'signed-up', value: 4_700 },\n    { source: 'pricing', target: 'browsed', value: 7_200 },\n    { source: 'pricing', target: 'bounced', value: 5_200 },\n    { source: 'blog', target: 'signed-up', value: 900 },\n    { source: 'blog', target: 'browsed', value: 6_700 },\n    { source: 'blog', target: 'bounced', value: 11_300 },\n  ],\n  nodes: [\n    { id: 'organic', label: 'Organic search' },\n    { id: 'paid', label: 'Paid ads' },\n    { id: 'social', label: 'Social' },\n    { id: 'email', label: 'Email' },\n    { id: 'home', label: 'Home' },\n    { id: 'pricing', label: 'Pricing' },\n    { id: 'blog', label: 'Blog' },\n    { color: 'var(--color-chart-3)', id: 'signed-up', label: 'Signed up' },\n    { color: 'var(--color-chart-5)', id: 'browsed', label: 'Kept browsing' },\n    { id: 'bounced', kind: 'exit', label: 'Bounced' },\n  ],\n  title: 'Traffic flow',\n  unit: 'sessions',\n}\n\nconst Flow1 = (props: Flow1Props) => {\n  const {\n    description,\n    goal,\n    links = [],\n    nodes = [],\n    errorMessage,\n    status,\n    title,\n    unit = 'sessions',\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 sessions = nodes\n    .filter((node) => (totals.get(node.id)?.in ?? 0) === 0)\n    .reduce((sum, node) => sum + (totals.get(node.id)?.out ?? 0), 0)\n  const converted = totals.get(goal)?.in ?? 0\n  const bounced = nodes\n    .filter((node) => node.kind === 'exit')\n    .reduce((sum, node) => sum + (totals.get(node.id)?.in ?? 0), 0)\n  const percent = (value: number) => formatPercent(value / (sessions || 1))\n  const best = nodes\n    .filter((node) =>\n      links.some((link) => link.source === node.id && link.target === goal),\n    )\n    .map((node) => ({\n      label: node.label,\n      rate:\n        (links.find((link) => link.source === node.id && link.target === goal)?.value ??\n          0) / (totals.get(node.id)?.out || 1),\n    }))\n    .sort((a, b) => b.rate - a.rate)[0]\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-20' /> : labels.get(goal)}\n                  </dt>\n                  <dd>\n                    <KPIValue value={converted} format={percent} />\n                  </dd>\n                  <BlockReady className='text-xs'>\n                    <dd className='text-muted-foreground text-xs tabular-nums'>\n                      {formatNumber(converted)} of {formatNumber(sessions)} {unit}\n                    </dd>\n                  </BlockReady>\n                </div>\n                <div className='flex flex-col gap-1'>\n                  <dt className='text-muted-foreground text-sm'>Dropped off</dt>\n                  <dd>\n                    <KPIValue className='text-2xl' value={bounced} format={percent} />\n                  </dd>\n                </div>\n                {(state || best) && (\n                  <div className='flex flex-col gap-1'>\n                    <dt className='text-muted-foreground text-sm'>Converts best</dt>\n                    <dd className='text-2xl font-light tracking-tight'>\n                      {state ? <SkeletonText className='w-[4em]' /> : best?.label}\n                    </dd>\n                    <BlockReady className='text-xs'>\n                      <dd className='text-muted-foreground text-xs tabular-nums'>\n                        {formatPercent(best?.rate ?? 0, { maximumFractionDigits: 0 })} of\n                        its {unit}\n                      </dd>\n                    </BlockReady>\n                  </div>\n                )}\n              </dl>\n            )}\n            <FlowChart\n              emphasis={goal}\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: unit.charAt(0).toUpperCase() + unit.slice(1) },\n              ]}\n              rows={links.map((link) => ({\n                source: labels.get(link.source) ?? link.source,\n                target: labels.get(link.target) ?? link.target,\n                value: formatNumber(link.value),\n              }))}\n            />\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Flow1, exampleProps as flow1ExampleProps, type Flow1Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/flow/flow-01.tsx"
    }
  ],
  "meta": {
    "shows": "Sessions from each source through the landing page, to signing up, browsing on or bouncing.",
    "size": "full",
    "usedWith": [
      "funnel-01",
      "chart-panel-02",
      "geo-02"
    ],
    "component": "Flow1",
    "props": "{ description: string; links?: { source: string; target: string; value: number }[]; nodes?: { color?: string; id: string; kind?: \"default\" | \"exit\" | \"gap\"; label: string }[]; goal: string; title: string; unit?: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
