{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "retention-01",
  "description": "A retention triangle with a row per cohort and a weighted average row, shaded by share.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/heatmap.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json",
    "https://www.dashboardblocks.com/r/radix/retention.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/retention/retention-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { HeatmapLegend } from '@/registry/components/dashboardblocks/heatmap'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport {\n  CohortTable,\n  type RetentionCohort,\n  getAverageRetention,\n} from '@/registry/components/dashboardblocks/retention'\nimport { formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Retention1Props extends BlockStateProps {\n  /** Oldest first. Leave out, or pass none, to show the empty state. */\n  cohorts?: RetentionCohort[]\n  description: string\n  mode?: 'percent' | 'count'\n  /** @default 'Month' */\n  periodName?: string\n  title: string\n}\n\nconst COHORT_NAMES = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep']\nconst COHORT_SIZES = [1_184, 1_246, 1_402, 1_318, 1_527, 1_611, 1_489, 1_702, 1_836]\n\nconst exampleProps: Retention1Props = {\n  cohorts: COHORT_NAMES.map((name, index) => {\n    const size = COHORT_SIZES[index]\n    const floor = 0.21 + index * 0.012\n    const periods = COHORT_NAMES.length - index\n    return {\n      label: `${name} 2026`,\n      retained: Array.from({ length: periods }, (_, month) => {\n        if (month === 0) return size\n        const rate = floor + (0.62 - floor) * Math.exp(-(month - 1) / 1.4)\n        const wobble = Math.sin(index * 2.3 + month * 1.7) * 0.012\n        return Math.round(size * (rate + wobble))\n      }),\n      size,\n    }\n  }),\n  description:\n    'Share of each monthly signup cohort still active, by months since signup.',\n  periodName: 'Month',\n  title: 'Cohort retention',\n}\n\nconst Retention1 = (props: Retention1Props) => {\n  const {\n    cohorts = [],\n    description,\n    mode = 'percent',\n    periodName = 'Month',\n    errorMessage,\n    status,\n    title,\n  } = props\n  const state = getBlockState(status, cohorts)\n  const averages = getAverageRetention(cohorts)\n  const unit = periodName.toLowerCase()\n  const milestone = state ? 3 : Math.min(3, averages.length - 1)\n  const milestoneRate = milestone > 0 ? averages[milestone] : null\n  const reached = cohorts.filter((cohort) => cohort.retained.length > milestone)\n  const best = reached.reduce<RetentionCohort | null>(\n    (top, cohort) =>\n      top === null ||\n      cohort.retained[milestone] / (cohort.size || 1) >\n        top.retained[milestone] / (top.size || 1)\n        ? cohort\n        : top,\n    null,\n  )\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 || (milestoneRate !== null && milestoneRate !== undefined)) && (\n              <dl className='flex flex-wrap items-start gap-x-10 gap-y-3 border-t pt-4'>\n                <div className='flex flex-col gap-1'>\n                  <dt className='text-muted-foreground text-sm'>\n                    Still active in {unit} {milestone}, on average\n                  </dt>\n                  <dd>\n                    <KPIValue\n                      value={milestoneRate ?? undefined}\n                      format={(value) =>\n                        formatPercent(value, { maximumFractionDigits: 0 })\n                      }\n                    />\n                  </dd>\n                </div>\n                {state === 'loading' && (\n                  <div className='flex flex-col gap-1'>\n                    <dt className='text-muted-foreground text-sm'>Best cohort</dt>\n                    <dd>\n                      <KPIValue className='text-2xl' value={undefined} />\n                    </dd>\n                  </div>\n                )}\n                {!state && best && (\n                  <div className='flex flex-col gap-1'>\n                    <dt className='text-muted-foreground text-sm'>Best cohort</dt>\n                    <dd className='text-2xl font-light tracking-tight tabular-nums'>\n                      {best.label}\n                      <span className='text-muted-foreground ml-2 text-sm'>\n                        {formatPercent(best.retained[milestone] / (best.size || 1), {\n                          maximumFractionDigits: 0,\n                        })}{' '}\n                        in {unit} {milestone}\n                      </span>\n                    </dd>\n                  </div>\n                )}\n              </dl>\n            )}\n            {state === 'loading' && <BlockStateRows className='border-t' rows={6} />}\n            {!state && (\n              <CohortTable\n                caption={`${title}: ${description} The last row is the average, weighted by cohort size.`}\n                cohorts={cohorts}\n                footer={<HeatmapLegend low='Fewer' high='More retained' />}\n                minWidth='36rem'\n                mode={mode}\n                periodName={periodName}\n              />\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Retention1, exampleProps as retention1ExampleProps, type Retention1Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/retention/retention-01.tsx"
    }
  ],
  "meta": {
    "shows": "A retention triangle with a row per cohort and a weighted average row, shaded by share.",
    "size": "full",
    "usedWith": [
      "retention-02",
      "heatmap-02"
    ],
    "component": "Retention1",
    "props": "{ cohorts?: { label: string; size: number; retained: number[]; color?: string; icon?: ReactNode; eligible?: number[]; filling?: boolean }[]; description: string; mode?: \"percent\" | \"count\"; periodName?: string; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
