{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "subscription-overview",
  "title": "Subscription Overview",
  "type": "registry:block",
  "files": [
    {
      "path": "packages/registry-native/blocks/subscription-overview/SubscriptionOverview.tsx",
      "content": "import * as React from 'react'\nimport { FlatList, View, type ViewProps } from 'react-native'\nimport { Badge } from '@/components/ui/badge'\nimport { ListItem, ListItemContent, ListItemDescription, ListItemTitle, ListSeparator } from '@/components/ui/list'\nimport { SegmentedControl, SegmentedControlItem } from '@/components/ui/segmented-control'\nimport { Text } from '@/components/ui/text'\nimport { cn } from '@/lib/utils'\n\ntype BillingInterval = 'week' | 'month' | 'year'\ntype SubscriptionStatus = 'active' | 'trial' | 'ending' | 'expired'\n\nexport interface SubscriptionOverviewEntry {\n  id: string\n  name: string\n  plan?: string\n  /** Non-negative recurring amount in major currency units. */\n  amount: number\n  currency: string\n  interval: BillingInterval\n  status: SubscriptionStatus\n  /** Renewal, trial end, or access end, depending on status. Unix milliseconds. */\n  periodEndsAt?: number\n}\n\nconst defaultLabels = {\n  current: 'Current',\n  expired: 'Expired',\n  active: 'Active',\n  trial: 'Free trial',\n  ending: 'Ending',\n  nextCharge: 'Next charge',\n  emptyCurrent: 'No current subscriptions',\n  emptyExpired: 'No expired subscriptions',\n  price: (amount: string, interval: BillingInterval) => `${amount} / ${interval}`,\n  renewsOn: (date: string) => `Renews ${date}`,\n  trialEndsOn: (date: string) => `Trial ends ${date}`,\n  endsOn: (date: string) => `Access ends ${date}`,\n  expiredOn: (date: string) => `Expired ${date}`,\n}\n\nexport interface SubscriptionOverviewProps extends ViewProps {\n  className?: string\n  /** Pass an empty array for an account without subscriptions. */\n  entries?: readonly SubscriptionOverviewEntry[]\n  locale?: string\n  /** Reference timestamp for the next charge. Defaults to the current time at render. */\n  now?: number\n  labels?: Partial<typeof defaultLabels>\n  header?: React.ReactNode\n  onEntryPress?: (entry: SubscriptionOverviewEntry) => void\n}\n\nfunction sampleEntries(now: number): SubscriptionOverviewEntry[] {\n  const renewal = new Date(now)\n  renewal.setDate(renewal.getDate() + 3)\n  return [\n    {\n      id: 'sample-1',\n      name: 'Harbor Storage',\n      plan: '100 GB',\n      amount: 3.99,\n      currency: 'USD',\n      interval: 'month',\n      status: 'active',\n      periodEndsAt: renewal.getTime(),\n    },\n    {\n      id: 'sample-2',\n      name: 'Field Notes',\n      plan: 'Personal',\n      amount: 24,\n      currency: 'USD',\n      interval: 'year',\n      status: 'expired',\n    },\n  ]\n}\n\nfunction periodEnd(entry: SubscriptionOverviewEntry) {\n  return entry.periodEndsAt !== undefined && Number.isFinite(new Date(entry.periodEndsAt).getTime())\n    ? entry.periodEndsAt\n    : undefined\n}\n\nfunction currencyCode(entry: SubscriptionOverviewEntry) {\n  const currency = entry.currency.trim().toUpperCase()\n  return /^[A-Z]{3}$/.test(currency) ? currency : undefined\n}\n\nexport function SubscriptionOverview({\n  className,\n  entries,\n  header,\n  locale,\n  now = Date.now(),\n  labels,\n  onEntryPress,\n  ...props\n}: SubscriptionOverviewProps) {\n  const copy = { ...defaultLabels, ...labels }\n  const [sample] = React.useState(() => sampleEntries(now))\n  const [view, setView] = React.useState<'current' | 'expired'>('current')\n  const dateFormat = React.useMemo(() => new Intl.DateTimeFormat(locale, { dateStyle: 'medium' }), [locale])\n  const eligible = (entries ?? sample)\n    .filter((entry) => (entry.status === 'expired') === (view === 'expired'))\n    .sort((a, b) =>\n      view === 'expired'\n        ? (periodEnd(b) ?? -Infinity) - (periodEnd(a) ?? -Infinity)\n        : (periodEnd(a) ?? Infinity) - (periodEnd(b) ?? Infinity),\n    )\n  const upcoming =\n    view === 'current'\n      ? eligible.find((entry) => {\n          const date = periodEnd(entry)\n          return (\n            (entry.status === 'active' || entry.status === 'trial') &&\n            Number.isFinite(entry.amount) &&\n            entry.amount > 0 &&\n            !!currencyCode(entry) &&\n            date !== undefined &&\n            date >= now\n          )\n        })\n      : undefined\n\n  function displayPrice(entry: SubscriptionOverviewEntry) {\n    const amount = entry.amount\n    const currency = currencyCode(entry)\n    if (!currency || !Number.isFinite(amount) || amount < 0) return undefined\n    return copy.price(new Intl.NumberFormat(locale, { style: 'currency', currency }).format(amount), entry.interval)\n  }\n\n  return (\n    <View {...props} className={cn('min-h-0 flex-1 bg-background', className)}>\n      <FlatList\n        data={upcoming ? eligible.filter((entry) => entry.id !== upcoming.id) : eligible}\n        keyExtractor={(entry) => entry.id}\n        contentContainerStyle={{ paddingBottom: 16 }}\n        ListHeaderComponent={\n          <View className=\"gap-4 pb-4\">\n            {header}\n            <SegmentedControl\n              value={view}\n              onValueChange={(value) => {\n                if (value === 'current' || value === 'expired') setView(value)\n              }}\n            >\n              <SegmentedControlItem value=\"current\">{copy.current}</SegmentedControlItem>\n              <SegmentedControlItem value=\"expired\">{copy.expired}</SegmentedControlItem>\n            </SegmentedControl>\n            {upcoming ? (\n              <ListItem\n                accessible\n                accessibilityLabel={[\n                  copy.nextCharge,\n                  upcoming.name,\n                  displayPrice(upcoming),\n                  dateFormat.format(periodEnd(upcoming)!),\n                  upcoming.status === 'trial' && copy.trial,\n                ]\n                  .filter(Boolean)\n                  .join(', ')}\n                onPress={onEntryPress ? () => onEntryPress(upcoming) : undefined}\n                className=\"flex-col items-start gap-1 rounded-2xl border border-border bg-card px-5 py-4\"\n              >\n                <Text size=\"sm\" variant=\"muted\">\n                  {copy.nextCharge}\n                </Text>\n                <Text size=\"xl\" style={{ fontVariant: ['tabular-nums'] }}>\n                  {displayPrice(upcoming)}\n                </Text>\n                <Text>{upcoming.name}</Text>\n                <Text size=\"sm\" variant=\"muted\">\n                  {upcoming.status === 'trial'\n                    ? copy.trialEndsOn(dateFormat.format(periodEnd(upcoming)!))\n                    : dateFormat.format(periodEnd(upcoming)!)}\n                </Text>\n              </ListItem>\n            ) : null}\n          </View>\n        }\n        ListEmptyComponent={\n          upcoming ? undefined : (\n            <View className=\"items-center rounded-xl border border-border px-4 py-8\">\n              <Text className=\"text-center font-medium\">\n                {view === 'current' ? copy.emptyCurrent : copy.emptyExpired}\n              </Text>\n            </View>\n          )\n        }\n        ItemSeparatorComponent={ListSeparator}\n        renderItem={({ item }) => {\n          const timestamp = periodEnd(item)\n          const date = timestamp === undefined ? undefined : dateFormat.format(timestamp)\n          const describeDate = {\n            active: copy.renewsOn,\n            trial: copy.trialEndsOn,\n            ending: copy.endsOn,\n            expired: copy.expiredOn,\n          }[item.status]\n          const dateDescription = date ? describeDate(date) : undefined\n          const price = displayPrice(item)\n          return (\n            <ListItem\n              accessible\n              accessibilityLabel={[item.name, item.plan, copy[item.status], price, dateDescription]\n                .filter(Boolean)\n                .join(', ')}\n              onPress={onEntryPress ? () => onEntryPress(item) : undefined}\n              className=\"items-start px-0\"\n            >\n              <ListItemContent className=\"gap-2\">\n                <View className=\"flex-row flex-wrap items-center justify-between gap-x-2 gap-y-1\">\n                  <ListItemTitle className=\"min-w-0 shrink\">{item.name}</ListItemTitle>\n                  <Badge variant={item.status === 'trial' ? 'info' : 'outline'} text={copy[item.status]} />\n                </View>\n                {item.plan ? <ListItemDescription>{item.plan}</ListItemDescription> : null}\n                <View className=\"flex-row flex-wrap gap-x-3 gap-y-1\">\n                  {price ? (\n                    <Text size=\"sm\" style={{ fontVariant: ['tabular-nums'] }}>\n                      {price}\n                    </Text>\n                  ) : null}\n                  {dateDescription ? (\n                    <Text size=\"sm\" variant=\"muted\">\n                      {dateDescription}\n                    </Text>\n                  ) : null}\n                </View>\n              </ListItemContent>\n            </ListItem>\n          )\n        }}\n      />\n    </View>\n  )\n}\n",
      "type": "registry:block",
      "target": "~/components/blocks/subscription-overview/SubscriptionOverview.tsx"
    },
    {
      "path": "packages/registry-native/blocks/subscription-overview/index.ts",
      "content": "export {\n  SubscriptionOverview,\n  type SubscriptionOverviewEntry,\n  type SubscriptionOverviewProps,\n} from './SubscriptionOverview'\n",
      "type": "registry:block",
      "target": "~/components/blocks/subscription-overview/index.ts"
    }
  ],
  "dependencies": [],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/badge.json",
    "https://native.uipkge.dev/r/native/list.json",
    "https://native.uipkge.dev/r/native/segmented-control.json",
    "https://native.uipkge.dev/r/native/text.json"
  ],
  "description": "A native list of current and expired subscriptions with a next-charge preview, localized prices, and renewal and access dates.",
  "categories": [
    "finance"
  ]
}