{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shared-expense",
  "title": "Shared Expense",
  "type": "registry:block",
  "files": [
    {
      "path": "packages/registry-native/blocks/shared-expense/SharedExpense.tsx",
      "content": "import { useWindowDimensions, View, type ViewProps } from 'react-native'\nimport { Check } from 'lucide-react-native'\nimport { Button } from '@/components/ui/button'\nimport { Icon } from '@/components/ui/icon'\nimport { List, ListItem, ListItemContent, ListItemTitle, ListSeparator } from '@/components/ui/list'\nimport { Text } from '@/components/ui/text'\nimport { cn } from '@/lib/utils'\n\nconst defaultLabels = {\n  total: 'Total to split',\n  participants: 'Who is sharing?',\n  empty: 'No participants are available for this expense.',\n  select: 'Select someone to split this expense.',\n  staleSelection: 'Some selected people are unavailable. Review the list before continuing.',\n  invalidTotal: 'Enter a valid expense total to continue.',\n  review: 'Review split',\n}\n\nexport interface SharedExpenseParticipant {\n  id: string\n  name: string\n}\n\nexport interface SharedExpenseShare {\n  id: string\n  amountMinor: number\n}\n\nexport interface SharedExpenseProps extends Omit<ViewProps, 'children'> {\n  className?: string\n  title: string\n  /** Nonnegative, safe integer in the currency's smallest unit. */\n  amountMinor: number | null\n  /** Unique stable IDs and order. Any rounding remainder goes to the first selected rows in this order. */\n  participants: readonly SharedExpenseParticipant[]\n  selectedIds: readonly string[]\n  onSelectionChange: (ids: string[]) => void\n  onReview: (shares: SharedExpenseShare[]) => void\n  formatMinor: (amountMinor: number) => string\n  labels?: Partial<typeof defaultLabels>\n}\n\nexport function SharedExpense({\n  className,\n  title,\n  amountMinor,\n  participants,\n  selectedIds,\n  onSelectionChange,\n  onReview,\n  formatMinor,\n  labels,\n  ...props\n}: SharedExpenseProps) {\n  const copy = { ...defaultLabels, ...labels }\n  const { fontScale } = useWindowDimensions()\n  const stacked = fontScale >= 1.35\n  const selected = new Set(selectedIds)\n  const included = participants.filter(({ id }) => selected.has(id))\n  const validTotal = amountMinor !== null && Number.isSafeInteger(amountMinor) && amountMinor >= 0\n  const staleSelection = included.length !== selected.size\n  const shares = new Map<string, number>()\n\n  if (validTotal && included.length && !staleSelection) {\n    const remainder = amountMinor % included.length\n    const share = (amountMinor - remainder) / included.length\n    included.forEach(({ id }, index) => shares.set(id, share + Number(index < remainder)))\n  }\n  const message = !validTotal\n    ? copy.invalidTotal\n    : !participants.length\n      ? copy.empty\n      : staleSelection\n        ? copy.staleSelection\n        : copy.select\n\n  function toggle(id: string) {\n    // A deliberate change reconciles selections from a previous participant list.\n    const next = new Set(included.map((participant) => participant.id))\n    if (!next.delete(id)) next.add(id)\n    onSelectionChange(\n      participants.filter((participant) => next.has(participant.id)).map((participant) => participant.id),\n    )\n  }\n\n  return (\n    <View {...props} className={cn('gap-4', className)}>\n      <View className=\"gap-1 border-b border-border pb-4\">\n        <Text size=\"lg\" accessibilityRole=\"header\" className=\"font-semibold\">\n          {title}\n        </Text>\n        <Text size=\"sm\" variant=\"muted\">\n          {copy.total}\n        </Text>\n        {validTotal ? (\n          <Text size=\"title\" style={{ fontVariant: ['tabular-nums'] }}>\n            {formatMinor(amountMinor)}\n          </Text>\n        ) : null}\n      </View>\n      <Text accessibilityRole=\"header\" className=\"font-semibold\">\n        {copy.participants}\n      </Text>\n      {participants.length ? (\n        <List>\n          {participants.map(({ id, name }, index) => {\n            const share = shares.get(id)\n            const formatted = share === undefined ? undefined : formatMinor(share)\n            const shareText = formatted ? <Text style={{ fontVariant: ['tabular-nums'] }}>{formatted}</Text> : null\n            const checked = selected.has(id)\n\n            return (\n              <View key={id}>\n                {index ? <ListSeparator /> : null}\n                <ListItem\n                  accessibilityRole=\"checkbox\"\n                  accessibilityLabel={formatted ? `${name}, ${formatted}` : name}\n                  accessibilityState={{ checked }}\n                  onPress={() => toggle(id)}\n                  className=\"px-3\"\n                >\n                  <View\n                    aria-hidden\n                    className={cn(\n                      'size-6 shrink-0 items-center justify-center rounded border border-muted-foreground',\n                      checked && 'border-primary bg-primary',\n                    )}\n                  >\n                    {checked ? <Icon icon={Check} size={16} className=\"text-primary-foreground\" /> : null}\n                  </View>\n                  <ListItemContent>\n                    <ListItemTitle>{name}</ListItemTitle>\n                    {stacked ? shareText : null}\n                  </ListItemContent>\n                  {stacked ? null : shareText}\n                </ListItem>\n              </View>\n            )\n          })}\n        </List>\n      ) : null}\n      {!shares.size ? (\n        <Text size=\"sm\" variant=\"muted\">\n          {message}\n        </Text>\n      ) : null}\n      <Button\n        disabled={!shares.size}\n        accessibilityLabel={copy.review}\n        onPress={() => {\n          if (shares.size) onReview(Array.from(shares, ([id, amountMinor]) => ({ id, amountMinor })))\n        }}\n      >\n        {copy.review}\n      </Button>\n    </View>\n  )\n}\n",
      "type": "registry:block",
      "target": "~/components/blocks/shared-expense/SharedExpense.tsx"
    },
    {
      "path": "packages/registry-native/blocks/shared-expense/index.ts",
      "content": "export { SharedExpense } from './SharedExpense'\nexport type { SharedExpenseParticipant, SharedExpenseProps, SharedExpenseShare } from './SharedExpense'\n",
      "type": "registry:block",
      "target": "~/components/blocks/shared-expense/index.ts"
    }
  ],
  "dependencies": [
    "lucide-react-native"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/button.json",
    "https://native.uipkge.dev/r/native/icon.json",
    "https://native.uipkge.dev/r/native/list.json",
    "https://native.uipkge.dev/r/native/text.json",
    "https://native.uipkge.dev/r/native/utils.json"
  ],
  "description": "Equal expense splitting with selectable participants and exact rounding in minor currency units.",
  "categories": [
    "finance"
  ]
}