{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dashboard-02",
  "title": "SaaS dashboard",
  "description": "A SaaS dashboard: metric tabs, an activity heatmap, MRR by region, MRR movement, retention milestones and service status, filtered by plan.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/billing-01.json",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/dashboard-header.json",
    "https://www.dashboardblocks.com/r/radix/data-table-04.json",
    "https://www.dashboardblocks.com/r/radix/geo-04.json",
    "https://www.dashboardblocks.com/r/radix/heatmap-01.json",
    "https://www.dashboardblocks.com/r/radix/retention-03.json",
    "https://www.dashboardblocks.com/r/radix/stat-group-03.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/dashboards/dashboard-02.tsx",
      "content": "'use client'\n\nimport { Billing1 } from '@/registry/components/dashboardblocks/billing/billing-01'\nimport {\n  BlockBusy,\n  BlockStateProvider,\n  type BlockStateProps,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  type DateRangePreset,\n  DateRangePicker,\n  ExportMenu,\n  FilterChip,\n  FilterMenu,\n  getDateRange,\n  getPreset,\n  getPreviousRange,\n} from '@/registry/components/dashboardblocks/dashboard-header'\nimport {\n  DataTable4,\n  dataTable4ExampleProps,\n} from '@/registry/components/dashboardblocks/data-table/data-table-04'\nimport { Geo4 } from '@/registry/components/dashboardblocks/geo/geo-04'\nimport { Heatmap1 } from '@/registry/components/dashboardblocks/heatmap/heatmap-01'\nimport { Retention3 } from '@/registry/components/dashboardblocks/retention/retention-03'\nimport { StatGroup3 } from '@/registry/components/dashboardblocks/stat-group/stat-group-03'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport {\n  formatCurrency,\n  formatDate,\n  formatDateRange,\n  formatPercent,\n} from '@/registry/lib/dashboardblocks/format'\nimport { useEffect, useState } from 'react'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Dashboard2Props extends BlockStateProps {\n  empty?: boolean\n  title: string\n  /** The last day of every date range. */\n  today: Date\n}\n\nconst exampleProps: Dashboard2Props = {\n  title: 'Product health',\n  today: new Date(Date.UTC(2026, 8, 25)),\n}\n\nconst PLANS = [\n  { name: 'Starter', price: 19, retention: [0.52, 0.33, 0.19], share: 0.58 },\n  { name: 'Pro', price: 49, retention: [0.64, 0.46, 0.31], share: 0.33 },\n  { name: 'Enterprise', price: 240, retention: [0.81, 0.69, 0.58], share: 0.09 },\n]\n\nconst REGIONS = [\n  { color: 'var(--color-chart-2)', label: 'North America', share: 0.46 },\n  { color: 'var(--color-chart-3)', label: 'Europe', share: 0.36 },\n  { color: 'var(--color-chart-4)', label: 'Asia Pacific', share: 0.18 },\n]\n\nconst PRESETS: DateRangePreset[] = ['7d', '30d', '90d']\n\nconst DAYS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']\n\ninterface Query {\n  plan: string | null\n  preset: DateRangePreset\n}\n\nconst subscribersAt = (offset: number, share: number) =>\n  share *\n  (7_600 -\n    offset * 9 +\n    Math.sin(offset / 9) * 60 +\n    Math.sin(offset / 3.4) * 38 -\n    (offset > 11 ? 70 : 0) -\n    (offset > 47 ? 90 : 0))\n\nconst accountsAt = (offset: number, share: number) =>\n  share *\n  (5_400 - offset * 6 + Math.sin(offset / 4.3) * 140 - ((offset + 2) % 7 < 2 ? 520 : 0))\n\nfunction buildSaasData({ plan, preset }: Query, today: Date) {\n  const days = getPreset(preset).days\n  const range = getDateRange(preset, today)\n  const previousRange = getPreviousRange(range)\n  const plans = plan ? PLANS.filter((item) => item.name === plan) : PLANS\n  const share = plans.reduce((sum, item) => sum + item.share, 0)\n  const price = plans.reduce((sum, item) => sum + item.share * item.price, 0) / share\n\n  const day = (offset: number) => {\n    const accounts = accountsAt(offset, share)\n    const churn = 1.9 + Math.sin(offset / 6) * 0.3 + (plan === 'Starter' ? 0.8 : 0)\n    return {\n      accounts: Math.round(accounts),\n      churn: Number(churn.toFixed(1)),\n      mrr: Math.round(subscribersAt(offset, share) * price),\n      nps: Math.round(44 + Math.sin(offset / 9) * 4 + (plan === 'Enterprise' ? 8 : 0)),\n    }\n  }\n  const labelAt = (index: number) =>\n    formatDate(new Date(range.start.getTime() + index * 86_400_000), 'day')\n  const daily = (key: 'accounts' | 'churn' | 'mrr' | 'nps') =>\n    Array.from({ length: days }, (_, index) => {\n      const offset = days - 1 - index\n      return {\n        current: day(offset)[key],\n        label: labelAt(index),\n        previous: day(offset + days)[key],\n      }\n    })\n  const mean = (\n    points: { current: number; previous: number }[],\n    key: 'current' | 'previous',\n  ) => points.reduce((sum, point) => sum + point[key], 0) / (points.length || 1)\n  const last = <T,>(points: T[]) => points[points.length - 1]\n\n  const mrr = daily('mrr')\n  const accounts = daily('accounts')\n  const churn = daily('churn')\n  const nps = daily('nps')\n\n  const months = days / 30\n  const starting = day(days).mrr\n  const ending = last(mrr).current\n  const churned = Math.round((starting * mean(churn, 'current') * months) / 100)\n  const contraction = Math.round(starting * 0.011 * months)\n  const expansion = Math.round(starting * (plan === 'Starter' ? 0.018 : 0.034) * months)\n\n  const newBusiness = Math.max(0, ending - starting - expansion + contraction + churned)\n\n  const retention = [1, 7, 30].map((dayNumber, index) => {\n    const rate = plans.reduce((sum, item) => sum + item.share * item.retention[index], 0)\n    return {\n      current: Number((rate / share + 0.012).toFixed(3)),\n      label: `Day ${dayNumber}`,\n      previous: Number((rate / share + [-0.009, -0.011, 0.018][index]).toFixed(3)),\n    }\n  })\n\n  return {\n    activity: DAYS.map((_, weekday) =>\n      Array.from({ length: 24 }, (_, hour) => {\n        const weekend = weekday >= 5\n        const work =\n          Math.exp(-((hour - 11) ** 2) / 14) + 0.8 * Math.exp(-((hour - 15) ** 2) / 10)\n        return Math.round(share * (60 + 900 * work * (weekend ? 0.3 : 1)))\n      }),\n    ),\n    currentLabel: formatDateRange(range),\n    metrics: [\n      {\n        daily: mrr,\n        formatter: (value: number) => formatCurrency(value),\n        key: 'mrr',\n        label: 'MRR',\n        previous: last(mrr).previous,\n        value: last(mrr).current,\n      },\n      {\n        daily: accounts,\n        key: 'accounts',\n        label: 'Active accounts',\n        previous: last(accounts).previous,\n        value: last(accounts).current,\n      },\n      {\n        changeType: 'points' as const,\n        daily: churn,\n        formatter: (value: number) =>\n          formatPercent(value / 100, { minimumFractionDigits: 1 }),\n        goodDirection: 'down' as const,\n        key: 'churn',\n        label: 'Churn',\n        previous: Number(mean(churn, 'previous').toFixed(1)),\n        value: Number(mean(churn, 'current').toFixed(1)),\n      },\n      {\n        changeType: 'points' as const,\n        daily: nps,\n        key: 'nps',\n        label: 'NPS',\n        previous: Math.round(mean(nps, 'previous')),\n        value: Math.round(mean(nps, 'current')),\n      },\n    ],\n    movement: {\n      churn: churned,\n      contraction,\n      expansion,\n      newBusiness,\n      starting,\n    },\n    movementSummary: `New business and expansion added ${formatCurrency(newBusiness + expansion, { compact: true })}; churn and downgrades took ${formatCurrency(churned + contraction, { compact: true })}.`,\n    previousLabel: formatDateRange(previousRange),\n    regions: REGIONS.map((region, index) => {\n      const drift = (index - 1) * 0.01\n      return {\n        color: region.color,\n        current: Math.round(last(mrr).current * (region.share + drift)),\n        label: region.label,\n        previous: Math.round(last(mrr).previous * (region.share - drift)),\n      }\n    }),\n    retention,\n  }\n}\n\nconst Dashboard2 = (props: Dashboard2Props) => {\n  const { empty = false, errorMessage, status, title, today } = props\n  const [query, setQuery] = useState<Query>({ plan: null, preset: '30d' })\n  const [displayedQuery, setDisplayedQuery] = useState(query)\n  const busy = displayedQuery !== query\n\n  useEffect(() => {\n    if (displayedQuery === query) return\n    const timer = setTimeout(() => setDisplayedQuery(query), 500)\n    return () => clearTimeout(timer)\n  }, [query, displayedQuery])\n\n  const update = (patch: Partial<Query>) =>\n    setQuery((current) => ({ ...current, ...patch }))\n  const data = buildSaasData(displayedQuery, today)\n  const range = getDateRange(query.preset, today)\n\n  return (\n    <BlockStateProvider\n      errorMessage={errorMessage}\n      state={status ?? (empty ? 'empty' : undefined)}\n    >\n      <div className='@container flex w-full flex-col gap-8'>\n        <header className='flex flex-col gap-2'>\n          <div className='flex flex-wrap items-start justify-between gap-3'>\n            <h1 className='min-w-0 text-2xl font-semibold tracking-tight'>{title}</h1>\n            <ExportMenu disabled={status !== undefined || empty} onExport={() => {}} />\n          </div>\n          <div className='flex flex-wrap items-center justify-between gap-x-4 gap-y-2'>\n            <p className='text-muted-foreground min-w-0 leading-relaxed'>\n              Showing{' '}\n              <DateRangePicker\n                onValueChange={(preset) => update({ preset })}\n                presets={PRESETS}\n                today={today}\n                value={query.preset}\n                variant='inline'\n              />\n              <span aria-live='polite'>\n                , {formatDateRange(range)}, compared with{' '}\n                {formatDateRange(getPreviousRange(range))}.\n              </span>\n            </p>\n            <div className='flex flex-wrap items-center gap-2'>\n              {query.plan && (\n                <FilterChip\n                  field='Plan'\n                  value={query.plan}\n                  onRemove={() => update({ plan: null })}\n                />\n              )}\n              <FilterMenu\n                allLabel='All plans'\n                label='Plan'\n                onValueChange={(plan) => update({ plan })}\n                options={PLANS.map((item) => item.name)}\n                value={query.plan}\n              >\n                <IconPlaceholder\n                  lucide='LayersIcon'\n                  tabler='IconStack2'\n                  hugeicons='Layers01Icon'\n                  phosphor='StackIcon'\n                  remixicon='RiStackLine'\n                />\n                {query.plan ? 'Change plan' : 'Filter by plan'}\n              </FilterMenu>\n            </div>\n          </div>\n        </header>\n        <BlockBusy\n          busy={busy}\n          label='Updating the dashboard'\n          className='grid gap-4 @4xl:grid-cols-3'\n        >\n          <div className='grid @4xl:col-span-3'>\n            <StatGroup3\n              errorMessage={errorMessage}\n              status={status}\n              currentLabel={data.currentLabel}\n              metrics={empty ? [] : data.metrics}\n              previousLabel={data.previousLabel}\n              title='Revenue and customers'\n            />\n          </div>\n          <div className='grid @4xl:col-span-2'>\n            <Billing1\n              errorMessage={errorMessage}\n              status={status}\n              description={status || empty ? '' : data.movementSummary}\n              movement={empty ? undefined : data.movement}\n              title='MRR movement'\n            />\n          </div>\n          <Geo4\n            errorMessage={errorMessage}\n            status={status}\n            comparison={`in ${data.previousLabel}`}\n            formatter={(value) => formatCurrency(value)}\n            regions={empty ? [] : data.regions}\n            title='MRR by region'\n          />\n          <div className='grid @4xl:col-span-2'>\n            <Heatmap1\n              errorMessage={errorMessage}\n              status={status}\n              title='When customers are active'\n              unit='accounts'\n              values={empty ? [] : data.activity}\n            />\n          </div>\n          <Retention3\n            errorMessage={errorMessage}\n            status={status}\n            description='The latest cohort, against the one before.'\n            milestones={empty ? [] : data.retention}\n            title='Retention milestones'\n          />\n          <div className='grid @4xl:col-span-3'>\n            <Card>\n              <CardContent>\n                <DataTable4\n                  errorMessage={errorMessage}\n                  status={status}\n                  {...dataTable4ExampleProps}\n                  rows={empty ? [] : dataTable4ExampleProps.rows}\n                />\n              </CardContent>\n            </Card>\n          </div>\n        </BlockBusy>\n      </div>\n    </BlockStateProvider>\n  )\n}\n\nexport { Dashboard2, exampleProps as dashboard2ExampleProps, type Dashboard2Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/dashboards/dashboard-02.tsx"
    }
  ],
  "meta": {
    "shows": "A full SaaS dashboard with metric tabs, an activity heatmap, revenue by region, billing movement, retention and service status.",
    "size": "page",
    "usedWith": [],
    "component": "Dashboard2",
    "props": "{ empty?: boolean; title: string; today: Date; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:block"
}
