{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dashboards-01",
  "title": "Overview with a figures band",
  "description": "Four figures that pick what one line chart draws, a period switch whose figures roll to their new value, and a CSV export built in the browser.",
  "dependencies": [
    "@base-ui/react",
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/skeleton.json",
    "https://ui.ndekocode.dev/r/tabs.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/dashboards/dashboards-01/index.tsx",
      "content": "'use client';\n\nimport { useState } from 'react';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Skeleton } from '@/registry/ndeko/ui/skeleton';\n\nimport {\n  PERIODS,\n  WORKSPACE,\n  type MetricDefinition,\n  type MetricId,\n  type PeriodId,\n} from './data';\nimport {\n  chartPointsOf,\n  csvRowsOf,\n  figuresOf,\n  formatMetric,\n  metricOf,\n  periodOf,\n} from './figures';\nimport { MetricStrip } from './metric-strip';\nimport {\n  ExportButton,\n  PeriodSwitch,\n  REPORT_SURFACE,\n  ReportToolbar,\n  downloadCsv,\n  useSimulatedLoad,\n  type PeriodOption,\n} from './report-frame';\nimport { TrendChart } from './trend-chart';\n\nconst PERIOD_OPTIONS: PeriodOption<PeriodId>[] = PERIODS.map((period) => ({\n  id: period.id,\n  label: period.switchLabel,\n}));\n\nconst SKELETON_CELLS = ['tracked', 'closed', 'billable', 'review'];\n\nfunction periodKeyOf(periodId: PeriodId) {\n  return periodId;\n}\n\nfunction peopleLabelOf(count: number) {\n  if (count === 1) {\n    return '1 person';\n  }\n  return `${count} people`;\n}\n\nfunction formatterOf(metric: MetricDefinition) {\n  return (value: number) => formatMetric(metric, value);\n}\n\nfunction OverviewSkeleton() {\n  return (\n    <div\n      aria-hidden='true'\n      className={cn(REPORT_SURFACE, 'flex flex-col gap-6 p-2 pb-5')}\n    >\n      <div className='grid grid-cols-2 gap-1 lg:grid-cols-4'>\n        {SKELETON_CELLS.map((cell) => (\n          <div\n            key={cell}\n            className='flex flex-col gap-2 px-3 pt-2.5 pb-3.5 sm:px-4'\n          >\n            <Skeleton className='h-3 w-20' />\n            <Skeleton className='h-5 w-16' />\n            <Skeleton className='h-3 w-32' />\n          </div>\n        ))}\n      </div>\n      <div className='flex flex-col gap-3 px-3 sm:px-4'>\n        <Skeleton className='h-3.5 w-40' />\n        <Skeleton className='h-[224px] w-full rounded-lg' />\n      </div>\n    </div>\n  );\n}\n\nexport default function Dashboards01() {\n  const load = useSimulatedLoad<PeriodId>('weeks', periodKeyOf);\n  const [metricId, setMetricId] = useState<MetricId>('tracked');\n  const shownPeriodId = load.loaded ?? load.requested;\n  const shownPeriod = periodOf(shownPeriodId);\n  const metric = metricOf(metricId);\n  const figures = figuresOf(shownPeriodId);\n  const points = chartPointsOf(shownPeriodId, metricId);\n  const formatValue = formatterOf(metric);\n  const chartTitle = `${metric.chartTitle} ${shownPeriod.perUnit}`;\n  const peopleLabel = peopleLabelOf(WORKSPACE.peopleCount);\n  const meta = `${shownPeriod.label} · ${peopleLabel}`;\n\n  function exportOverview() {\n    const rows = csvRowsOf(shownPeriodId);\n    const fileName = `tidewell-overview-${shownPeriod.fileSlug}.csv`;\n    downloadCsv(fileName, rows);\n  }\n\n  return (\n    <div className='bg-background text-foreground min-h-dvh w-full'>\n      <ReportToolbar title={WORKSPACE.name} meta={meta}>\n        <ExportButton disabled={load.isFirstLoad} onExport={exportOverview} />\n      </ReportToolbar>\n      <div className='mx-auto flex w-full max-w-5xl flex-col gap-4 px-4 py-5 md:px-6'>\n        <PeriodSwitch\n          label='Period'\n          options={PERIOD_OPTIONS}\n          value={load.requested}\n          isUpdating={load.isUpdating}\n          onValueChange={load.request}\n        />\n        {load.isFirstLoad && <OverviewSkeleton />}\n        {!load.isFirstLoad && (\n          <section\n            aria-label='Overview'\n            aria-busy={load.isUpdating}\n            className={cn(REPORT_SURFACE, 'flex flex-col gap-5 p-2 pb-5')}\n          >\n            <MetricStrip\n              figures={figures}\n              value={metricId}\n              onValueChange={setMetricId}\n            />\n            <div className='flex flex-col gap-4 px-3 sm:px-4'>\n              <div className='flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1'>\n                <h2 className='text-sm font-medium'>{chartTitle}</h2>\n                <span className='text-muted-foreground text-xs'>\n                  Illustrative figures\n                </span>\n              </div>\n              <TrendChart\n                title={chartTitle}\n                valueHeading={metric.label}\n                points={points}\n                formatValue={formatValue}\n              />\n            </div>\n          </section>\n        )}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/dashboards-01/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/dashboards/dashboards-01/metric-strip.tsx",
      "content": "'use client';\n\nimport { Tabs as TabsPrimitive } from '@base-ui/react/tabs';\n\nimport { MotionNumber } from '@/components/core/motion-number';\n\nimport type { MetricId } from './data';\nimport type { MetricFigure } from './figures';\n\ntype MetricStripProps = {\n  figures: MetricFigure[];\n  value: MetricId;\n  onValueChange: (metricId: MetricId) => void;\n};\n\n/** The figures band. Each cell is a tab that picks the figure the chart below draws. */\nexport function MetricStrip({\n  figures,\n  value,\n  onValueChange,\n}: MetricStripProps) {\n  function changeValue(nextValue: unknown) {\n    const figure = figures.find(\n      (candidate) => candidate.metric.id === nextValue\n    );\n    if (figure) {\n      onValueChange(figure.metric.id);\n    }\n  }\n\n  return (\n    <TabsPrimitive.Root value={value} onValueChange={changeValue}>\n      <TabsPrimitive.List\n        aria-label='Figure drawn in the chart'\n        className='relative grid grid-cols-2 gap-1 lg:grid-cols-4'\n      >\n        {figures.map((figure) => (\n          <TabsPrimitive.Tab\n            key={figure.metric.id}\n            value={figure.metric.id}\n            className='group/metric hover:bg-foreground/[0.03] focus-visible:ring-ring/25 flex min-w-0 cursor-pointer flex-col items-start gap-1 rounded-lg px-3 pt-2.5 pb-3.5 text-left transition-colors duration-150 outline-none focus-visible:ring-[3px] sm:px-4'\n          >\n            <span className='text-muted-foreground group-data-active/metric:text-foreground text-xs font-medium transition-colors duration-150'>\n              {figure.metric.label}\n            </span>\n            <MotionNumber\n              value={figure.total}\n              suffix={figure.metric.suffix}\n              className='text-lg leading-7 font-semibold'\n            />\n            <span className='text-muted-foreground text-xs text-pretty'>\n              {figure.hint}\n            </span>\n          </TabsPrimitive.Tab>\n        ))}\n        <TabsPrimitive.Indicator className='bg-primary pointer-events-none absolute top-0 left-0 h-0.5 w-[calc(var(--active-tab-width)-1.5rem)] translate-x-[calc(var(--active-tab-left)+0.75rem)] translate-y-[calc(var(--active-tab-top)+var(--active-tab-height)-2px)] rounded-full transition-[translate,width] duration-300 ease-(--ease-out-quint) sm:w-[calc(var(--active-tab-width)-2rem)] sm:translate-x-[calc(var(--active-tab-left)+1rem)]' />\n      </TabsPrimitive.List>\n    </TabsPrimitive.Root>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/dashboards-01/metric-strip.tsx"
    },
    {
      "path": "registry/ndeko/blocks/dashboards/dashboards-01/trend-chart.tsx",
      "content": "'use client';\n\nimport { motion, type Transition } from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nimport {\n  ChartBubble,\n  bubbleAlignOf,\n  columnCenterOf,\n  niceScale,\n  percentOf,\n  useActiveIndex,\n} from './chart-kit';\n\nconst PLOT_HEIGHT = 200;\n\nconst VIEW_WIDTH = 1000;\n\nconst MAX_LINES = 4;\n\nconst PHONE_LABEL_STEP = 3;\n\nconst BUBBLE_GAP_PX = 10;\n\nconst MOVE_TRANSITION: Transition = {\n  duration: 0.3,\n  ease: [0.77, 0, 0.175, 1],\n};\n\nconst INSTANT: Transition = { duration: 0 };\n\nexport type TrendPoint = {\n  axisLabel: string;\n  label: string;\n  value: number;\n};\n\ntype Coordinate = { x: number; y: number };\n\nfunction moveTransitionOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return INSTANT;\n  }\n  return MOVE_TRANSITION;\n}\n\nfunction yOf(value: number, top: number) {\n  const ratio = value / top;\n  const height = ratio * PLOT_HEIGHT;\n  return PLOT_HEIGHT - height;\n}\n\nfunction coordinatesOf(points: TrendPoint[], top: number): Coordinate[] {\n  return points.map((point, index) => {\n    const share = columnCenterOf(index, points.length);\n    const x = share * VIEW_WIDTH;\n    const y = yOf(point.value, top);\n    return { x, y };\n  });\n}\n\nfunction commandOf(coordinate: Coordinate, index: number) {\n  const x = coordinate.x.toFixed(1);\n  const y = coordinate.y.toFixed(1);\n  if (index === 0) {\n    return `M${x} ${y}`;\n  }\n  return `L${x} ${y}`;\n}\n\nfunction linePathOf(coordinates: Coordinate[]) {\n  const commands = coordinates.map((coordinate, index) =>\n    commandOf(coordinate, index)\n  );\n  return commands.join(' ');\n}\n\nfunction areaPathOf(coordinates: Coordinate[]) {\n  const line = linePathOf(coordinates);\n  const lastIndex = coordinates.length - 1;\n  const first = coordinates[0];\n  const last = coordinates[lastIndex];\n  const firstX = first.x.toFixed(1);\n  const lastX = last.x.toFixed(1);\n  return `${line} L${lastX} ${PLOT_HEIGHT} L${firstX} ${PLOT_HEIGHT} Z`;\n}\n\nfunction leftOf(index: number, count: number) {\n  const share = columnCenterOf(index, count);\n  return percentOf(share);\n}\n\nfunction isPhoneLabel(index: number, count: number) {\n  const isLast = index === count - 1;\n  const isOnStep = index % PHONE_LABEL_STEP === 0;\n  return isLast || isOnStep;\n}\n\ntype TrendChartProps = {\n  title: string;\n  valueHeading: string;\n  points: TrendPoint[];\n  formatValue: (value: number) => string;\n};\n\n/** One series as a line over twelve columns. The line moves to its new shape when the data changes. */\nexport function TrendChart({\n  title,\n  valueHeading,\n  points,\n  formatValue,\n}: TrendChartProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const transition = moveTransitionOf(shouldReduceMotion);\n  const count = points.length;\n  const lastIndex = count - 1;\n  const values = points.map((point) => point.value);\n  const maxValue = Math.max(...values);\n  const scale = niceScale(maxValue, MAX_LINES);\n  const coordinates = coordinatesOf(points, scale.top);\n  const linePath = linePathOf(coordinates);\n  const areaPath = areaPathOf(coordinates);\n  const lastLeft = leftOf(lastIndex, count);\n  const lastY = coordinates[lastIndex].y;\n  const reading = useActiveIndex(count, lastIndex);\n  const shownPoint = points[reading.shownIndex];\n  const shownY = coordinates[reading.shownIndex].y;\n  const shownLeft = leftOf(reading.shownIndex, count);\n  const shownValue = formatValue(shownPoint.value);\n  const readingText = `${shownPoint.label}: ${shownValue}`;\n  const bubbleTop = shownY - BUBBLE_GAP_PX;\n  const bubbleAlign = bubbleAlignOf(reading.shownIndex, count);\n  const plotHeight = { height: PLOT_HEIGHT };\n\n  return (\n    <div className='flex flex-col'>\n      <div className='grid grid-cols-[2.75rem_minmax(0,1fr)]'>\n        <div aria-hidden='true' className='relative' style={plotHeight}>\n          {scale.ticks.map((tick) => {\n            const top = yOf(tick, scale.top);\n\n            return (\n              <span\n                key={tick}\n                className='text-muted-foreground absolute right-2.5 -translate-y-1/2 text-[11px] tabular-nums'\n                style={{ top }}\n              >\n                {formatValue(tick)}\n              </span>\n            );\n          })}\n        </div>\n        <div\n          role='group'\n          tabIndex={0}\n          aria-label={`${title}. Use the arrow keys to read each value.`}\n          className='focus-visible:ring-ring/25 relative touch-pan-y rounded-md outline-none focus-visible:ring-[3px]'\n          style={plotHeight}\n          {...reading.handlers}\n        >\n          <svg\n            aria-hidden='true'\n            viewBox={`0 0 ${VIEW_WIDTH} ${PLOT_HEIGHT}`}\n            preserveAspectRatio='none'\n            className='absolute inset-0 size-full overflow-visible'\n          >\n            {scale.ticks.map((tick) => {\n              const y = yOf(tick, scale.top);\n\n              return (\n                <line\n                  key={tick}\n                  x1={0}\n                  x2={VIEW_WIDTH}\n                  y1={y}\n                  y2={y}\n                  strokeWidth={1}\n                  vectorEffect='non-scaling-stroke'\n                  className='stroke-border'\n                />\n              );\n            })}\n            <motion.path\n              initial={false}\n              animate={{ d: areaPath }}\n              transition={transition}\n              className='fill-primary/[0.08]'\n            />\n            <motion.path\n              initial={false}\n              animate={{ d: linePath }}\n              transition={transition}\n              fill='none'\n              strokeWidth={2}\n              strokeLinecap='round'\n              strokeLinejoin='round'\n              vectorEffect='non-scaling-stroke'\n              className='stroke-primary'\n            />\n          </svg>\n          {reading.isActive && (\n            <span\n              aria-hidden='true'\n              className='bg-foreground/15 pointer-events-none absolute inset-y-0 w-px'\n              style={{ left: shownLeft }}\n            />\n          )}\n          <motion.span\n            aria-hidden='true'\n            initial={false}\n            animate={{ y: lastY }}\n            transition={transition}\n            className='bg-primary ring-card pointer-events-none absolute top-0 size-2.5 -translate-x-1/2 -translate-y-1/2 rounded-full ring-2'\n            style={{ left: lastLeft }}\n          />\n          {reading.isActive && (\n            <span\n              aria-hidden='true'\n              className='bg-card ring-primary pointer-events-none absolute size-2.5 -translate-x-1/2 -translate-y-1/2 rounded-full ring-2'\n              style={{ left: shownLeft, top: shownY }}\n            />\n          )}\n          <ChartBubble\n            left={shownLeft}\n            top={bubbleTop}\n            align={bubbleAlign}\n            isVisible={reading.isActive}\n          >\n            <span className='text-muted-foreground'>{shownPoint.label}</span>\n            <span className='text-[13px] font-medium tabular-nums'>\n              {shownValue}\n            </span>\n          </ChartBubble>\n        </div>\n        <span aria-hidden='true' />\n        <div aria-hidden='true' className='relative mt-2 h-4'>\n          {points.map((point, index) => {\n            const left = leftOf(index, count);\n            const isShownOnPhone = isPhoneLabel(index, count);\n            const isLast = index === lastIndex;\n\n            return (\n              <span\n                key={point.label}\n                className={cn(\n                  'text-muted-foreground absolute top-0 -translate-x-1/2 text-[11px] whitespace-nowrap tabular-nums',\n                  !isShownOnPhone && 'hidden sm:block',\n                  isLast && 'text-foreground font-medium'\n                )}\n                style={{ left }}\n              >\n                {point.axisLabel}\n              </span>\n            );\n          })}\n        </div>\n      </div>\n      <span aria-live='polite' className='sr-only'>\n        {reading.isReadingByKeys && readingText}\n      </span>\n      <div className='sr-only'>\n        <table>\n          <caption>{title}</caption>\n          <thead>\n            <tr>\n              <th scope='col'>Period</th>\n              <th scope='col'>{valueHeading}</th>\n            </tr>\n          </thead>\n          <tbody>\n            {points.map((point) => (\n              <tr key={point.label}>\n                <th scope='row'>{point.label}</th>\n                <td>{formatValue(point.value)}</td>\n              </tr>\n            ))}\n          </tbody>\n        </table>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/dashboards-01/trend-chart.tsx"
    },
    {
      "path": "registry/ndeko/blocks/dashboards/dashboards-01/chart-kit.tsx",
      "content": "'use client';\n\nimport { useState } from 'react';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nconst NICE_FACTORS = [1, 2, 5, 10];\n\nexport function niceScale(maxValue: number, maxLines: number) {\n  const safeMax = Math.max(maxValue, 1);\n  const roughStep = safeMax / maxLines;\n  const logarithm = Math.log10(roughStep);\n  const exponent = Math.floor(logarithm);\n  const magnitude = 10 ** exponent;\n  const factor = NICE_FACTORS.find((candidate) => {\n    const candidateStep = candidate * magnitude;\n    return candidateStep >= roughStep;\n  });\n  const safeFactor = factor ?? 10;\n  const step = safeFactor * magnitude;\n  const lineCount = Math.ceil(safeMax / step);\n  const top = lineCount * step;\n  const tickCount = lineCount + 1;\n  const ticks = Array.from({ length: tickCount }, (_, index) => {\n    return index * step;\n  });\n  return { top, ticks };\n}\n\nexport function columnCenterOf(index: number, count: number) {\n  const center = index + 0.5;\n  return center / count;\n}\n\nexport function percentOf(share: number) {\n  const percent = share * 100;\n  return `${percent}%`;\n}\n\nfunction columnIndexAt(event: React.PointerEvent<HTMLElement>, count: number) {\n  const box = event.currentTarget.getBoundingClientRect();\n  const offset = event.clientX - box.left;\n  const share = offset / box.width;\n  const rawIndex = Math.floor(share * count);\n  const lastIndex = count - 1;\n  const clampedHigh = Math.min(rawIndex, lastIndex);\n  return Math.max(clampedHigh, 0);\n}\n\nfunction steppedIndexOf(key: string, current: number, count: number) {\n  const lastIndex = count - 1;\n  if (key === 'ArrowRight') {\n    const next = current + 1;\n    return Math.min(next, lastIndex);\n  }\n  if (key === 'ArrowLeft') {\n    const previous = current - 1;\n    return Math.max(previous, 0);\n  }\n  if (key === 'Home') {\n    return 0;\n  }\n  if (key === 'End') {\n    return lastIndex;\n  }\n  return null;\n}\n\n/**\n * One reading position for a chart: the pointer column wins while it is over the plot,\n * the arrow keys move it while the plot has keyboard focus.\n */\nexport function useActiveIndex(count: number, defaultIndex: number) {\n  const [pointerIndex, setPointerIndex] = useState<number | null>(null);\n  const [keyIndex, setKeyIndex] = useState<number | null>(null);\n  const [lastIndex, setLastIndex] = useState(defaultIndex);\n  const activeIndex = pointerIndex ?? keyIndex;\n  const isActive = activeIndex !== null;\n  const isReadingByKeys = keyIndex !== null;\n  const wantedIndex = activeIndex ?? lastIndex;\n  const lastColumn = count - 1;\n  const highestIndex = Math.max(lastColumn, 0);\n  const shownIndex = Math.min(wantedIndex, highestIndex);\n\n  function pointAt(event: React.PointerEvent<HTMLElement>) {\n    const index = columnIndexAt(event, count);\n    setPointerIndex(index);\n    setLastIndex(index);\n  }\n\n  function leave(event: React.PointerEvent<HTMLElement>) {\n    if (event.pointerType === 'mouse') {\n      setPointerIndex(null);\n    }\n  }\n\n  function focus(event: React.FocusEvent<HTMLElement>) {\n    const isKeyboardFocus = event.currentTarget.matches(':focus-visible');\n    if (isKeyboardFocus) {\n      setKeyIndex(lastIndex);\n    }\n  }\n\n  function blur() {\n    setKeyIndex(null);\n    setPointerIndex(null);\n  }\n\n  function step(event: React.KeyboardEvent<HTMLElement>) {\n    if (event.key === 'Escape') {\n      setKeyIndex(null);\n      return;\n    }\n    const current = keyIndex ?? lastIndex;\n    const next = steppedIndexOf(event.key, current, count);\n    if (next === null) {\n      return;\n    }\n    event.preventDefault();\n    setPointerIndex(null);\n    setKeyIndex(next);\n    setLastIndex(next);\n  }\n\n  const handlers = {\n    onPointerMove: pointAt,\n    onPointerDown: pointAt,\n    onPointerLeave: leave,\n    onFocus: focus,\n    onBlur: blur,\n    onKeyDown: step,\n  };\n\n  return { shownIndex, isActive, isReadingByKeys, handlers };\n}\n\ntype BubbleAlign = 'start' | 'center' | 'end';\n\nconst BUBBLE_ALIGN: Record<BubbleAlign, string> = {\n  start: '-translate-x-3',\n  center: '-translate-x-1/2',\n  end: '-translate-x-[calc(100%-0.75rem)]',\n};\n\n/** A point in the first or last third of the plot keeps its bubble inside the plot on a phone. */\nconst START_SHARE = 1 / 3;\nconst END_SHARE = 2 / 3;\n\nexport function bubbleAlignOf(index: number, count: number): BubbleAlign {\n  const lastIndex = Math.max(count - 1, 1);\n  const share = index / lastIndex;\n  if (share < START_SHARE) {\n    return 'start';\n  }\n  if (share > END_SHARE) {\n    return 'end';\n  }\n  return 'center';\n}\n\ntype ChartBubbleProps = {\n  left: string;\n  top: number;\n  align: BubbleAlign;\n  isVisible: boolean;\n  children: React.ReactNode;\n};\n\n/** The one value bubble of a chart. It stays mounted so it can fade out where it was. */\nexport function ChartBubble({\n  left,\n  top,\n  align,\n  isVisible,\n  children,\n}: ChartBubbleProps) {\n  const position = { left, top };\n\n  return (\n    <div\n      aria-hidden='true'\n      className='pointer-events-none absolute z-10 w-0'\n      style={position}\n    >\n      <div\n        className={cn(\n          'surface-raised flex w-max -translate-y-full flex-col gap-0.5 rounded-lg px-2.5 py-1.5 text-xs whitespace-nowrap',\n          'origin-bottom transition-[opacity,scale] duration-[125ms] ease-(--ease-out-strong)',\n          BUBBLE_ALIGN[align],\n          !isVisible && 'scale-[0.97] opacity-0'\n        )}\n      >\n        {children}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/dashboards-01/chart-kit.tsx"
    },
    {
      "path": "registry/ndeko/blocks/dashboards/dashboards-01/report-frame.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useEffect, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  CheckIcon,\n  DownloadIcon,\n  LoaderCircleIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Tabs, TabsList, TabsTab } from '@/registry/ndeko/ui/tabs';\n\nexport const REPORT_SURFACE =\n  'bg-card hairline-ring ring-border rounded-xl shadow-[0_1px_2px_rgb(0_0_0/0.04)] dark:bg-foreground/[0.03]';\n\nconst FIRST_LOAD_MS = 900;\n\nconst UPDATE_MS = 450;\n\nconst EXPORTED_NOTICE_MS = 1600;\n\nconst FORMULA_PREFIXES = ['=', '+', '-', '@'];\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst NOTE_IN: Transition = { duration: 0.2, ease: [0.23, 1, 0.32, 1] };\n\nconst NOTE_OUT: Transition = { duration: 0.12, ease: [0.23, 1, 0.32, 1] };\n\nconst SWAP_VARIANTS: Variants = {\n  enter: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n  visible: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n};\n\nconst NOTE_VARIANTS: Variants = {\n  enter: { opacity: 0, x: -4 },\n  visible: { opacity: 1, x: 0, transition: NOTE_IN },\n  exit: { opacity: 0, transition: NOTE_OUT },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1, transition: NOTE_IN },\n  exit: { opacity: 0, transition: NOTE_OUT },\n};\n\nfunction swapVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return SWAP_VARIANTS;\n}\n\nfunction noteVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return NOTE_VARIANTS;\n}\n\nfunction loadDelayOf(isFirstLoad: boolean) {\n  if (isFirstLoad) {\n    return FIRST_LOAD_MS;\n  }\n  return UPDATE_MS;\n}\n\nfunction loadedKeyOf<Query>(\n  loaded: Query | null,\n  keyOf: (query: Query) => string\n) {\n  if (loaded === null) {\n    return null;\n  }\n  return keyOf(loaded);\n}\n\n/**\n * Stands in for a request: the first load shows a skeleton, a later change keeps the\n * previous result on screen until the next one arrives.\n */\nexport function useSimulatedLoad<Query>(\n  initialQuery: Query,\n  keyOf: (query: Query) => string\n) {\n  const [requested, setRequested] = useState(initialQuery);\n  const [loaded, setLoaded] = useState<Query | null>(null);\n  const isFirstLoad = loaded === null;\n  const delay = loadDelayOf(isFirstLoad);\n  const requestedKey = keyOf(requested);\n  const loadedKey = loadedKeyOf(loaded, keyOf);\n  const isUpdating = loadedKey !== null && loadedKey !== requestedKey;\n\n  useEffect(() => {\n    const timer = window.setTimeout(() => setLoaded(requested), delay);\n    return () => window.clearTimeout(timer);\n  }, [requested, delay]);\n\n  return { requested, loaded, isFirstLoad, isUpdating, request: setRequested };\n}\n\nexport type PeriodOption<Id extends string> = { id: Id; label: string };\n\ntype ReportToolbarProps = {\n  title: string;\n  meta: string;\n  children?: React.ReactNode;\n};\n\nexport function ReportToolbar({ title, meta, children }: ReportToolbarProps) {\n  return (\n    <div className='hairline-b border-border flex flex-wrap items-center gap-x-3 gap-y-2 px-4 py-3 md:px-6'>\n      <div className='flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5'>\n        <h1 className='truncate text-lg font-semibold text-balance'>{title}</h1>\n        <span className='text-muted-foreground text-xs tabular-nums'>\n          {meta}\n        </span>\n      </div>\n      <div className='ml-auto flex items-center gap-2'>{children}</div>\n    </div>\n  );\n}\n\nfunction UpdatingNote({ isUpdating }: { isUpdating: boolean }) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const variants = noteVariantsOf(shouldReduceMotion);\n\n  return (\n    <span role='status' className='text-muted-foreground flex text-xs'>\n      <AnimatePresence initial={false}>\n        {isUpdating && (\n          <motion.span\n            key='updating'\n            variants={variants}\n            initial='enter'\n            animate='visible'\n            exit='exit'\n            className='flex items-center gap-1.5'\n          >\n            <LoaderCircleIcon className='size-3.5 animate-spin' />\n            Updating\n          </motion.span>\n        )}\n      </AnimatePresence>\n    </span>\n  );\n}\n\ntype PeriodSwitchProps<Id extends string> = {\n  label: string;\n  options: PeriodOption<Id>[];\n  value: Id;\n  isUpdating: boolean;\n  onValueChange: (id: Id) => void;\n};\n\nexport function PeriodSwitch<Id extends string>({\n  label,\n  options,\n  value,\n  isUpdating,\n  onValueChange,\n}: PeriodSwitchProps<Id>) {\n  function changeValue(nextValue: unknown) {\n    const option = options.find((candidate) => candidate.id === nextValue);\n    if (option) {\n      onValueChange(option.id);\n    }\n  }\n\n  return (\n    <div className='flex flex-wrap items-center gap-x-3 gap-y-2'>\n      <Tabs value={value} onValueChange={changeValue}>\n        <TabsList variant='segmented' aria-label={label}>\n          {options.map((option) => (\n            <TabsTab key={option.id} value={option.id}>\n              {option.label}\n            </TabsTab>\n          ))}\n        </TabsList>\n      </Tabs>\n      <UpdatingNote isUpdating={isUpdating} />\n    </div>\n  );\n}\n\nfunction exportGlyphOf(isExported: boolean) {\n  if (isExported) {\n    return { key: 'exported', icon: <CheckIcon /> };\n  }\n  return { key: 'export', icon: <DownloadIcon /> };\n}\n\nfunction exportLabelOf(isExported: boolean) {\n  if (isExported) {\n    return 'Downloaded';\n  }\n  return 'Export CSV';\n}\n\ntype ExportButtonProps = {\n  disabled?: boolean;\n  onExport: () => void;\n};\n\nexport function ExportButton({ disabled, onExport }: ExportButtonProps) {\n  const [isExported, setIsExported] = useState(false);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const variants = swapVariantsOf(shouldReduceMotion);\n  const glyph = exportGlyphOf(isExported);\n  const label = exportLabelOf(isExported);\n\n  useEffect(() => {\n    if (!isExported) {\n      return;\n    }\n    const timer = window.setTimeout(\n      () => setIsExported(false),\n      EXPORTED_NOTICE_MS\n    );\n    return () => window.clearTimeout(timer);\n  }, [isExported]);\n\n  function exportReport() {\n    onExport();\n    setIsExported(true);\n  }\n\n  return (\n    <Button variant='outline' disabled={disabled} onClick={exportReport}>\n      <AnimatePresence mode='popLayout' initial={false}>\n        <motion.span\n          key={glyph.key}\n          variants={variants}\n          initial='enter'\n          animate='visible'\n          exit='exit'\n          transition={SWAP_TRANSITION}\n          className='flex'\n        >\n          {glyph.icon}\n        </motion.span>\n      </AnimatePresence>\n      <AnimatePresence mode='popLayout' initial={false}>\n        <motion.span\n          key={label}\n          variants={variants}\n          initial='enter'\n          animate='visible'\n          exit='exit'\n          transition={SWAP_TRANSITION}\n        >\n          {label}\n        </motion.span>\n      </AnimatePresence>\n    </Button>\n  );\n}\n\n/** Spreadsheet apps run a cell that starts with these characters as a formula. */\nfunction neutralizedCellOf(value: string) {\n  const startsLikeFormula = FORMULA_PREFIXES.some((prefix) =>\n    value.startsWith(prefix)\n  );\n  if (startsLikeFormula) {\n    return `'${value}`;\n  }\n  return value;\n}\n\nfunction csvCellOf(value: string) {\n  const neutralized = neutralizedCellOf(value);\n  const escaped = neutralized.replaceAll('\"', '\"\"');\n  return `\"${escaped}\"`;\n}\n\nfunction csvLineOf(row: string[]) {\n  const cells = row.map(csvCellOf);\n  return cells.join(',');\n}\n\n/** Builds the file in the browser and hands it to the download bar: nothing leaves the page. */\nexport function downloadCsv(fileName: string, rows: string[][]) {\n  const lines = rows.map(csvLineOf);\n  const text = lines.join('\\n');\n  const file = new Blob([text], { type: 'text/csv;charset=utf-8' });\n  const url = URL.createObjectURL(file);\n  const link = document.createElement('a');\n  link.href = url;\n  link.download = fileName;\n  link.click();\n  window.setTimeout(() => URL.revokeObjectURL(url), 0);\n}\n",
      "type": "registry:component",
      "target": "components/blocks/dashboards-01/report-frame.tsx"
    },
    {
      "path": "registry/ndeko/blocks/dashboards/dashboards-01/figures.ts",
      "content": "import {\n  METRICS,\n  PERIODS,\n  SERIES,\n  type MetricDefinition,\n  type MetricId,\n  type Period,\n  type PeriodId,\n} from './data';\n\nconst NUMBER_FORMAT = new Intl.NumberFormat('en');\n\nexport type MetricFigure = {\n  metric: MetricDefinition;\n  total: number;\n  hint: string;\n};\n\nexport function periodOf(periodId: PeriodId) {\n  const period = PERIODS.find((candidate) => candidate.id === periodId);\n  if (period) {\n    return period;\n  }\n  return PERIODS[0];\n}\n\nexport function metricOf(metricId: MetricId) {\n  const metric = METRICS.find((candidate) => candidate.id === metricId);\n  if (metric) {\n    return metric;\n  }\n  return METRICS[0];\n}\n\nfunction sumOf(values: number[]) {\n  return values.reduce((total, value) => total + value, 0);\n}\n\nfunction totalOf(metric: MetricDefinition, values: number[]) {\n  const sum = sumOf(values);\n  if (metric.aggregate === 'sum') {\n    return sum;\n  }\n  const average = sum / values.length;\n  return Math.round(average);\n}\n\nexport function formatMetric(metric: MetricDefinition, value: number) {\n  const digits = NUMBER_FORMAT.format(value);\n  return `${digits}${metric.suffix}`;\n}\n\nfunction aggregateLineOf(metric: MetricDefinition, period: Period) {\n  const count = period.points.length;\n  if (metric.aggregate === 'sum') {\n    return `Sum of ${count} ${period.unitPlural}`;\n  }\n  return `Average of ${count} ${period.unitPlural}`;\n}\n\nfunction percentChangeOf(total: number, previousTotal: number) {\n  const difference = total - previousTotal;\n  const ratio = difference / previousTotal;\n  const percent = ratio * 100;\n  return Math.round(percent);\n}\n\nfunction percentLineOf(percent: number, previous: string) {\n  if (percent === 0) {\n    return `same as ${previous}`;\n  }\n  if (percent > 0) {\n    return `up ${percent}% on ${previous}`;\n  }\n  const drop = Math.abs(percent);\n  return `down ${drop}% on ${previous}`;\n}\n\nfunction pointsWordOf(points: number) {\n  if (points === 1) {\n    return 'point';\n  }\n  return 'points';\n}\n\nfunction pointsLineOf(difference: number, previous: string) {\n  if (difference === 0) {\n    return `same as ${previous}`;\n  }\n  const points = Math.abs(difference);\n  const word = pointsWordOf(points);\n  if (difference > 0) {\n    return `up ${points} ${word} on ${previous}`;\n  }\n  return `down ${points} ${word} on ${previous}`;\n}\n\nfunction reviewLineOf(difference: number, previous: string) {\n  if (difference === 0) {\n    return `as fast as ${previous}`;\n  }\n  const hours = Math.abs(difference);\n  if (difference < 0) {\n    return `${hours}h faster than ${previous}`;\n  }\n  return `${hours}h slower than ${previous}`;\n}\n\nfunction changeLineOf(\n  metric: MetricDefinition,\n  total: number,\n  previousTotal: number,\n  period: Period\n) {\n  const count = period.points.length;\n  const previous = `the previous ${count}`;\n  if (metric.change === 'percent') {\n    const percent = percentChangeOf(total, previousTotal);\n    return percentLineOf(percent, previous);\n  }\n  const difference = total - previousTotal;\n  if (metric.change === 'points') {\n    return pointsLineOf(difference, previous);\n  }\n  return reviewLineOf(difference, previous);\n}\n\nexport function figuresOf(periodId: PeriodId): MetricFigure[] {\n  const period = periodOf(periodId);\n  return METRICS.map((metric) => {\n    const series = SERIES[periodId][metric.id];\n    const total = totalOf(metric, series.values);\n    const aggregateLine = aggregateLineOf(metric, period);\n    const changeLine = changeLineOf(\n      metric,\n      total,\n      series.previousTotal,\n      period\n    );\n    return {\n      metric,\n      total,\n      hint: `${aggregateLine}, ${changeLine}`,\n    };\n  });\n}\n\nexport function chartPointsOf(periodId: PeriodId, metricId: MetricId) {\n  const period = periodOf(periodId);\n  const series = SERIES[periodId][metricId];\n  return period.points.map((point, index) => ({\n    axisLabel: point.axisLabel,\n    label: point.label,\n    value: series.values[index],\n  }));\n}\n\nexport function csvRowsOf(periodId: PeriodId) {\n  const period = periodOf(periodId);\n  const headings = METRICS.map((metric) => metric.csvHeading);\n  const header = ['Period', ...headings];\n  const rows = period.points.map((point, index) => {\n    const cells = METRICS.map((metric) => {\n      const value = SERIES[periodId][metric.id].values[index];\n      return String(value);\n    });\n    return [point.label, ...cells];\n  });\n  return [header, ...rows];\n}\n",
      "type": "registry:component",
      "target": "components/blocks/dashboards-01/figures.ts"
    },
    {
      "path": "registry/ndeko/blocks/dashboards/dashboards-01/data.ts",
      "content": "export type PeriodId = 'days' | 'weeks' | 'months';\n\nexport type MetricId = 'tracked' | 'closed' | 'billable' | 'review';\n\nexport type PeriodPoint = {\n  axisLabel: string;\n  label: string;\n};\n\nexport type Period = {\n  id: PeriodId;\n  switchLabel: string;\n  label: string;\n  unitPlural: string;\n  perUnit: string;\n  fileSlug: string;\n  points: PeriodPoint[];\n};\n\nexport type MetricDefinition = {\n  id: MetricId;\n  label: string;\n  chartTitle: string;\n  csvHeading: string;\n  aggregate: 'sum' | 'average';\n  change: 'percent' | 'points' | 'hours-lower-is-better';\n  suffix: string;\n};\n\nexport type MetricSeries = {\n  values: number[];\n  previousTotal: number;\n};\n\nexport const WORKSPACE = {\n  name: 'Tidewell Studio',\n  peopleCount: 14,\n};\n\nexport const PERIODS: Period[] = [\n  {\n    id: 'days',\n    switchLabel: 'Days',\n    label: 'Last 12 working days',\n    unitPlural: 'working days',\n    perUnit: 'per working day',\n    fileSlug: 'last-12-working-days',\n    points: [\n      { axisLabel: '20 Oct', label: 'Tuesday 20 October' },\n      { axisLabel: '21 Oct', label: 'Wednesday 21 October' },\n      { axisLabel: '22 Oct', label: 'Thursday 22 October' },\n      { axisLabel: '23 Oct', label: 'Friday 23 October' },\n      { axisLabel: '26 Oct', label: 'Monday 26 October' },\n      { axisLabel: '27 Oct', label: 'Tuesday 27 October' },\n      { axisLabel: '28 Oct', label: 'Wednesday 28 October' },\n      { axisLabel: '29 Oct', label: 'Thursday 29 October' },\n      { axisLabel: '30 Oct', label: 'Friday 30 October' },\n      { axisLabel: '2 Nov', label: 'Monday 2 November' },\n      { axisLabel: '3 Nov', label: 'Tuesday 3 November' },\n      { axisLabel: '4 Nov', label: 'Wednesday 4 November' },\n    ],\n  },\n  {\n    id: 'weeks',\n    switchLabel: 'Weeks',\n    label: 'Last 12 weeks',\n    unitPlural: 'weeks',\n    perUnit: 'per week',\n    fileSlug: 'last-12-weeks',\n    points: [\n      { axisLabel: 'W33', label: 'Week 33, 10 to 16 August' },\n      { axisLabel: 'W34', label: 'Week 34, 17 to 23 August' },\n      { axisLabel: 'W35', label: 'Week 35, 24 to 30 August' },\n      { axisLabel: 'W36', label: 'Week 36, 31 August to 6 September' },\n      { axisLabel: 'W37', label: 'Week 37, 7 to 13 September' },\n      { axisLabel: 'W38', label: 'Week 38, 14 to 20 September' },\n      { axisLabel: 'W39', label: 'Week 39, 21 to 27 September' },\n      { axisLabel: 'W40', label: 'Week 40, 28 September to 4 October' },\n      { axisLabel: 'W41', label: 'Week 41, 5 to 11 October' },\n      { axisLabel: 'W42', label: 'Week 42, 12 to 18 October' },\n      { axisLabel: 'W43', label: 'Week 43, 19 to 25 October' },\n      { axisLabel: 'W44', label: 'Week 44, 26 October to 1 November' },\n    ],\n  },\n  {\n    id: 'months',\n    switchLabel: 'Months',\n    label: 'Last 12 months',\n    unitPlural: 'months',\n    perUnit: 'per month',\n    fileSlug: 'last-12-months',\n    points: [\n      { axisLabel: 'Nov', label: 'November 2025' },\n      { axisLabel: 'Dec', label: 'December 2025' },\n      { axisLabel: 'Jan', label: 'January 2026' },\n      { axisLabel: 'Feb', label: 'February 2026' },\n      { axisLabel: 'Mar', label: 'March 2026' },\n      { axisLabel: 'Apr', label: 'April 2026' },\n      { axisLabel: 'May', label: 'May 2026' },\n      { axisLabel: 'Jun', label: 'June 2026' },\n      { axisLabel: 'Jul', label: 'July 2026' },\n      { axisLabel: 'Aug', label: 'August 2026' },\n      { axisLabel: 'Sep', label: 'September 2026' },\n      { axisLabel: 'Oct', label: 'October 2026' },\n    ],\n  },\n];\n\nexport const METRICS: MetricDefinition[] = [\n  {\n    id: 'tracked',\n    label: 'Tracked time',\n    chartTitle: 'Hours tracked',\n    csvHeading: 'Tracked time (hours)',\n    aggregate: 'sum',\n    change: 'percent',\n    suffix: 'h',\n  },\n  {\n    id: 'closed',\n    label: 'Tasks closed',\n    chartTitle: 'Tasks closed',\n    csvHeading: 'Tasks closed',\n    aggregate: 'sum',\n    change: 'percent',\n    suffix: '',\n  },\n  {\n    id: 'billable',\n    label: 'Billable share',\n    chartTitle: 'Billable share of tracked time',\n    csvHeading: 'Billable share (%)',\n    aggregate: 'average',\n    change: 'points',\n    suffix: '%',\n  },\n  {\n    id: 'review',\n    label: 'Time in review',\n    chartTitle: 'Average time in review',\n    csvHeading: 'Time in review (hours)',\n    aggregate: 'average',\n    change: 'hours-lower-is-better',\n    suffix: 'h',\n  },\n];\n\nexport const SERIES: Record<PeriodId, Record<MetricId, MetricSeries>> = {\n  days: {\n    tracked: {\n      values: [78, 84, 81, 69, 88, 91, 86, 72, 80, 93, 89, 85],\n      previousTotal: 948,\n    },\n    closed: {\n      values: [14, 17, 12, 9, 19, 21, 16, 11, 15, 22, 18, 17],\n      previousTotal: 176,\n    },\n    billable: {\n      values: [66, 71, 69, 64, 72, 74, 70, 65, 68, 75, 73, 71],\n      previousTotal: 67,\n    },\n    review: {\n      values: [9, 7, 11, 14, 8, 6, 9, 12, 10, 7, 8, 9],\n      previousTotal: 11,\n    },\n  },\n  weeks: {\n    tracked: {\n      values: [402, 418, 436, 391, 447, 452, 438, 429, 461, 455, 470, 444],\n      previousTotal: 5120,\n    },\n    closed: {\n      values: [71, 78, 84, 66, 90, 88, 79, 83, 95, 87, 102, 91],\n      previousTotal: 1046,\n    },\n    billable: {\n      values: [63, 65, 68, 61, 70, 69, 67, 66, 71, 70, 72, 69],\n      previousTotal: 66,\n    },\n    review: {\n      values: [16, 14, 13, 18, 12, 11, 13, 12, 10, 11, 9, 10],\n      previousTotal: 15,\n    },\n  },\n  months: {\n    tracked: {\n      values: [\n        1710, 1520, 1880, 1840, 1795, 1905, 1870, 1610, 1490, 1930, 1985, 2010,\n      ],\n      previousTotal: 20180,\n    },\n    closed: {\n      values: [312, 268, 344, 351, 330, 372, 365, 290, 274, 381, 398, 412],\n      previousTotal: 3720,\n    },\n    billable: {\n      values: [61, 58, 64, 63, 62, 66, 65, 59, 57, 67, 68, 69],\n      previousTotal: 61,\n    },\n    review: {\n      values: [22, 25, 19, 18, 17, 16, 15, 19, 21, 14, 12, 11],\n      previousTotal: 21,\n    },\n  },\n};\n",
      "type": "registry:component",
      "target": "components/blocks/dashboards-01/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "dashboards"
  ],
  "type": "registry:block"
}