{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "poll-card",
  "title": "Poll Card",
  "type": "registry:block",
  "files": [
    {
      "path": "packages/registry-native/blocks/poll-card/PollCard.tsx",
      "content": "import { useRef, useState } from 'react'\nimport { View, type ViewProps } from 'react-native'\nimport { Alert, AlertDescription } from '@/components/ui/alert'\nimport { Button } from '@/components/ui/button'\nimport { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'\nimport { Text } from '@/components/ui/text'\nimport { useAnnouncement } from '@/lib/accessibility'\nimport { cn } from '@/lib/utils'\n\nconst defaultLabels = {\n  choices: 'Poll options',\n  closed: 'Voting has ended',\n  recorded: 'Your vote was recorded.',\n  empty: 'No choices are available.',\n  yourChoice: 'Your choice',\n  resultsUnavailable: 'Results aren’t available yet.',\n  vote: 'Submit vote',\n  voting: 'Submitting vote…',\n  failed: 'Couldn’t record your vote. Your choice is still selected.',\n  formatResult: (label: string, share: string) => `${label}, ${share} of votes`,\n  formatTotal: (count: number) => `${count} ${count === 1 ? 'vote' : 'votes'}`,\n}\n\nexport interface PollOption {\n  id: string\n  label: string\n  /** Optional caller-supplied vote count. Supply a valid count for every option to show results. */\n  votes?: number\n}\n\nexport interface PollCardProps extends Omit<ViewProps, 'children'> {\n  className?: string\n  question: string\n  /** Each option needs a stable, unique ID. */\n  options: readonly PollOption[]\n  closed?: boolean\n  voteId?: string | null\n  /** Return false or reject on failure. Update voteId after a successful request. */\n  onVote?: (id: string) => void | boolean | Promise<void | boolean>\n  locale?: string\n  labels?: Partial<typeof defaultLabels>\n}\n\nexport function PollCard({\n  className,\n  question,\n  options,\n  closed = false,\n  voteId = null,\n  onVote,\n  locale,\n  labels,\n  ...props\n}: PollCardProps) {\n  const copy = { ...defaultLabels, ...labels }\n  const [draft, setDraft] = useState<string | null>(null)\n  const [busy, setBusy] = useState(false)\n  const [error, setError] = useState(false)\n  const request = useRef(false)\n  const selected = options.find(({ id }) => id === draft)\n  const recorded = options.find(({ id }) => id === voteId)\n  const canVote = !closed && voteId === null && !!onVote\n  const total = options.reduce((sum, { votes }) => sum + (votes ?? Number.NaN), 0)\n  const hasResults =\n    Number.isSafeInteger(total) &&\n    options.every(({ votes }) => votes !== undefined && Number.isSafeInteger(votes) && votes >= 0)\n  const formatPercent = new Intl.NumberFormat(locale, { style: 'percent' })\n  const submitError = error && canVote && selected ? copy.failed : undefined\n  useAnnouncement(voteId !== null ? copy.recorded : submitError)\n\n  async function submit() {\n    if (!canVote || !selected || !onVote || request.current) return\n    request.current = true\n    setBusy(true)\n    setError(false)\n    try {\n      if ((await onVote(selected.id)) === false) setError(true)\n    } catch {\n      setError(true)\n    } finally {\n      request.current = false\n      setBusy(false)\n    }\n  }\n\n  return (\n    <View {...props} className={cn('gap-4 rounded-xl border border-border bg-card p-4', className)}>\n      <View className=\"gap-1\">\n        <Text size=\"lg\" accessibilityRole=\"header\" className=\"font-semibold\">\n          {question}\n        </Text>\n        {closed || voteId !== null ? (\n          <Text size=\"sm\" variant=\"muted\">\n            {closed ? copy.closed : copy.recorded}\n          </Text>\n        ) : null}\n      </View>\n      {options.length === 0 ? (\n        <Text variant=\"muted\">{copy.empty}</Text>\n      ) : canVote ? (\n        <>\n          <RadioGroup\n            accessibilityLabel={copy.choices}\n            value={selected?.id ?? ''}\n            disabled={busy}\n            onValueChange={(id) => {\n              if (request.current || !options.some((option) => option.id === id)) return\n              setError(false)\n              setDraft(id)\n            }}\n          >\n            {options.map(({ id, label }) => (\n              <RadioGroupItem key={id} value={id} label={label} />\n            ))}\n          </RadioGroup>\n          {submitError ? (\n            <Alert accessibilityRole=\"none\" variant=\"destructive\">\n              <AlertDescription>{submitError}</AlertDescription>\n            </Alert>\n          ) : null}\n          <Button\n            accessibilityLabel={busy ? copy.voting : copy.vote}\n            disabled={!selected}\n            loading={busy}\n            onPress={() => void submit()}\n          >\n            {busy ? copy.voting : copy.vote}\n          </Button>\n        </>\n      ) : hasResults ? (\n        <View className=\"gap-3\">\n          {options.map(({ id, label, votes }) => {\n            const share = total > 0 ? (votes ?? 0) / total : 0\n            const formatted = formatPercent.format(share)\n            const chosen = id === recorded?.id\n            return (\n              <View\n                key={id}\n                accessible\n                accessibilityLabel={copy.formatResult(label, formatted)}\n                accessibilityState={{ selected: chosen }}\n                className=\"gap-1.5\"\n              >\n                <View className=\"flex-row flex-wrap items-baseline justify-between gap-x-3 gap-y-1\">\n                  <Text className={chosen ? 'font-semibold' : undefined}>{label}</Text>\n                  <Text variant=\"muted\" style={{ fontVariant: ['tabular-nums'] }}>\n                    {formatted}\n                  </Text>\n                </View>\n                {chosen ? (\n                  <Text size=\"sm\" variant=\"muted\">\n                    {copy.yourChoice}\n                  </Text>\n                ) : null}\n                <View aria-hidden className=\"h-1.5 rounded-full bg-secondary\">\n                  <View className=\"h-full self-start rounded-full bg-primary\" style={{ width: `${share * 100}%` }} />\n                </View>\n              </View>\n            )\n          })}\n          <Text size=\"sm\" variant=\"muted\">\n            {copy.formatTotal(total)}\n          </Text>\n        </View>\n      ) : (\n        <Text variant=\"muted\">{copy.resultsUnavailable}</Text>\n      )}\n    </View>\n  )\n}\n",
      "type": "registry:block",
      "target": "~/components/blocks/poll-card/PollCard.tsx"
    },
    {
      "path": "packages/registry-native/blocks/poll-card/index.ts",
      "content": "export { PollCard } from './PollCard'\nexport type { PollCardProps, PollOption } from './PollCard'\n",
      "type": "registry:block",
      "target": "~/components/blocks/poll-card/index.ts"
    }
  ],
  "dependencies": [],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/accessibility.json",
    "https://native.uipkge.dev/r/native/alert.json",
    "https://native.uipkge.dev/r/native/button.json",
    "https://native.uipkge.dev/r/native/radio-group.json",
    "https://native.uipkge.dev/r/native/text.json",
    "https://native.uipkge.dev/r/native/utils.json"
  ],
  "description": "Single-choice mobile poll with explicit submission, retry, and accessible results.",
  "categories": [
    "workflow"
  ]
}