{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "usage-meter-01",
  "description": "An API quota with its status, when it resets and the usage it is on pace for, with the date it would hit the limit.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json",
    "https://www.dashboardblocks.com/r/radix/usage-meter.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/usage-meter/usage-meter-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { statusToneClasses } from '@/registry/components/dashboardblocks/status-label'\nimport {\n  UsageBar,\n  UsageKey,\n  UsageMeterLimit,\n  UsageMeterValue,\n  UsageStatusLabel,\n  formatUsage,\n  getDaysLeft,\n  getUsageStatus,\n  projectUsage,\n  usageStatusConfig,\n} from '@/registry/components/dashboardblocks/usage-meter'\nimport { formatDate } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\nimport { cn } from '@/lib/utils'\n\ninterface UsageMeter1Props extends BlockStateProps {\n  limit: number\n  /** Pass a fixed date, so the block renders the same on the server and in the browser. */\n  now: Date\n  periodEnd: Date\n  periodStart: Date\n  timeZone?: string\n  title: string\n  unit: string\n  /** Leave out to show the empty state. */\n  used?: number\n}\n\nconst DAY = 86_400_000\n\nconst exampleProps: UsageMeter1Props = {\n  limit: 10_000,\n  now: new Date(Date.UTC(2026, 8, 26)),\n  periodEnd: new Date(Date.UTC(2026, 9, 1)),\n  periodStart: new Date(Date.UTC(2026, 8, 1)),\n  title: 'API requests',\n  unit: 'requests',\n  used: 8_420,\n}\n\nconst UsageMeter1 = (props: UsageMeter1Props) => {\n  const {\n    limit,\n    now,\n    periodEnd,\n    periodStart,\n    errorMessage,\n    status: blockStatus,\n    timeZone = 'UTC',\n    title,\n    unit,\n    used = 0,\n  } = props\n  const state = getBlockState(blockStatus, props.used)\n\n  const daysElapsed = (now.getTime() - periodStart.getTime()) / DAY\n  const daysInPeriod = (periodEnd.getTime() - periodStart.getTime()) / DAY\n  const daysToReset = Math.ceil((periodEnd.getTime() - now.getTime()) / DAY)\n  const projected = projectUsage({ daysElapsed, daysInPeriod, used })\n  const status = getUsageStatus(used, limit)\n  const dailyRate = daysElapsed > 0 ? used / daysElapsed : 0\n  const daysToLimit = getDaysLeft(limit - used, dailyRate)\n  const hitsLimit = daysToLimit < daysToReset\n  const limitDate = new Date(now.getTime() + daysToLimit * DAY)\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-3 border-t pt-3 in-data-[slot=card]:first:border-t-0 in-data-[slot=card]:first:pt-0'>\n            <header className='flex items-baseline justify-between gap-3'>\n              <p className='text-muted-foreground text-sm'>{title}</p>\n              <UsageStatusLabel status={status} />\n            </header>\n            <div className='flex flex-wrap items-baseline gap-x-2'>\n              <UsageMeterValue>{formatUsage(used)}</UsageMeterValue>\n              <UsageMeterLimit>\n                of {formatUsage(limit)} {unit}\n              </UsageMeterLimit>\n            </div>\n            <UsageBar limit={limit} projected={projected} used={used} />\n            <BlockReady className='text-xs'>\n              <p className='text-muted-foreground flex flex-wrap justify-between gap-x-3 gap-y-1 text-xs'>\n                <span className='tabular-nums'>\n                  {formatUsage(Math.max(0, limit - used))} left\n                </span>\n                <span>\n                  Resets{' '}\n                  <time dateTime={periodEnd.toISOString()}>\n                    {formatDate(periodEnd, 'day', timeZone)}\n                  </time>\n                  , in {daysToReset} {daysToReset === 1 ? 'day' : 'days'}\n                </span>\n              </p>\n            </BlockReady>\n            {state !== 'empty' && state !== 'error' && (\n              <div className='border-t pt-3'>\n                <BlockReady className='text-sm'>\n                  <p className='text-muted-foreground text-sm'>\n                    <UsageKey\n                      className='mr-2'\n                      color={usageStatusConfig[hitsLimit ? 'over' : status].color}\n                      shape='projected'\n                    />\n                    On pace for{' '}\n                    <span\n                      className={cn(\n                        'font-medium tabular-nums',\n                        hitsLimit\n                          ? statusToneClasses[usageStatusConfig.over.tone]\n                          : 'text-foreground',\n                      )}\n                    >\n                      {formatUsage(Math.round(projected))} {unit}\n                    </span>{' '}\n                    by the reset.\n                    {hitsLimit && (\n                      <>\n                        {' '}\n                        At this rate you reach the limit around{' '}\n                        <time dateTime={limitDate.toISOString()}>\n                          {formatDate(limitDate, 'day', timeZone)}\n                        </time>\n                        .\n                      </>\n                    )}\n                  </p>\n                </BlockReady>\n              </div>\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { UsageMeter1, exampleProps as usageMeter1ExampleProps, type UsageMeter1Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/usage-meter/usage-meter-01.tsx"
    }
  ],
  "meta": {
    "shows": "An API quota with its status, when it resets and the usage it is on pace for, with the date it would hit the limit.",
    "size": "compact",
    "usedWith": [
      "usage-meter-06",
      "billing-01",
      "ai-usage-01"
    ],
    "component": "UsageMeter1",
    "props": "{ limit: number; now: Date; periodEnd: Date; periodStart: Date; timeZone?: string; title: string; unit: string; used?: number; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
