{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "flow-02",
  "description": "Where visitors go in their first pages after landing, with the ones who left at each step.",
  "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-02.tsx",
      "content": "'use client'\n\nimport {\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  getFlowColumns,\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 Flow2Props extends BlockStateProps {\n  description: string\n  /** Leave out, or pass none, to show the empty state. */\n  links?: FlowLink[]\n  nodes?: FlowNode[]\n  title: string\n  /** @default 'visitors' */\n  unit?: string\n}\n\nconst exampleProps: Flow2Props = {\n  description:\n    'Where visitors go in their first three pages after landing on Home, last 7 days. Grey bands are visitors who left.',\n  links: [\n    { source: 'home', target: 'pricing-2', value: 4_820 },\n    { source: 'home', target: 'features-2', value: 3_640 },\n    { source: 'home', target: 'docs-2', value: 2_210 },\n    { source: 'home', target: 'exit-2', value: 5_330 },\n    { source: 'pricing-2', target: 'signup-3', value: 1_540 },\n    { source: 'pricing-2', target: 'sales-3', value: 610 },\n    { source: 'pricing-2', target: 'docs-3', value: 720 },\n    { source: 'pricing-2', target: 'exit-3', value: 1_950 },\n    { source: 'features-2', target: 'pricing-3', value: 1_380 },\n    { source: 'features-2', target: 'signup-3', value: 520 },\n    { source: 'features-2', target: 'exit-3', value: 1_740 },\n    { source: 'docs-2', target: 'signup-3', value: 290 },\n    { source: 'docs-2', target: 'docs-3', value: 1_120 },\n    { source: 'docs-2', target: 'exit-3', value: 800 },\n  ],\n  nodes: [\n    { id: 'home', label: 'Home' },\n    { id: 'pricing-2', label: 'Pricing' },\n    { id: 'features-2', label: 'Features' },\n    { id: 'docs-2', label: 'Docs' },\n    { id: 'exit-2', kind: 'exit', label: 'Left' },\n    { id: 'signup-3', label: 'Sign up' },\n    { id: 'sales-3', label: 'Contact sales' },\n    { id: 'pricing-3', label: 'Pricing' },\n    { id: 'docs-3', label: 'Docs' },\n    { id: 'exit-3', kind: 'exit', label: 'Left' },\n  ],\n  title: 'User paths',\n  unit: 'visitors',\n}\n\nconst Flow2 = (props: Flow2Props) => {\n  const {\n    description,\n    links = [],\n    nodes = [],\n    errorMessage,\n    status,\n    title,\n    unit = 'visitors',\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 start = nodes.find((node) => (totals.get(node.id)?.in ?? 0) === 0)\n  const entered = start ? (totals.get(start.id)?.out ?? 0) : 0\n  const columnOf = getFlowColumns(nodes, links)\n  const columns = Math.max(0, ...columnOf.values())\n  const leftAt = Array.from({ length: columns }, (_, index) =>\n    nodes\n      .filter((node) => node.kind === 'exit' && columnOf.get(node.id) === index + 1)\n      .reduce((sum, node) => sum + (totals.get(node.id)?.in ?? 0), 0),\n  )\n  const percent = (value: number) =>\n    formatPercent(value / (entered || 1), { maximumFractionDigits: 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                    Landed on {state ? <SkeletonText className='w-12' /> : start?.label}\n                  </dt>\n                  <dd>\n                    <KPIValue value={entered} format={(value) => formatNumber(value)} />\n                  </dd>\n                </div>\n                {(state ? [0, 0] : leftAt).map((value, index) => (\n                  <div key={index} className='flex flex-col gap-1'>\n                    <dt className='text-muted-foreground text-sm'>\n                      Left after page {index + 1}\n                    </dt>\n                    <dd>\n                      <KPIValue className='text-2xl' value={value} format={percent} />\n                    </dd>\n                  </div>\n                ))}\n              </dl>\n            )}\n            <FlowChart\n              colorBy='target'\n              height={300}\n              label={title}\n              links={links}\n              minWidth='34rem'\n              nodes={nodes}\n            />\n            <ChartPanelTable\n              caption={`${title}: ${description}`}\n              columns={[\n                { key: 'step', label: 'Step' },\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                step: `Page ${(columnOf.get(link.source) ?? 0) + 1}`,\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 { Flow2, exampleProps as flow2ExampleProps, type Flow2Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/flow/flow-02.tsx"
    }
  ],
  "meta": {
    "shows": "Where visitors go in their first pages after landing, with the ones who left at each step.",
    "size": "full",
    "usedWith": [
      "flow-04",
      "funnel-01"
    ],
    "component": "Flow2",
    "props": "{ description: string; links?: { source: string; target: string; value: number }[]; nodes?: { color?: string; id: string; kind?: \"default\" | \"exit\" | \"gap\"; label: string }[]; title: string; unit?: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
