{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "media-download-library",
  "title": "Media Download Library",
  "type": "registry:block",
  "files": [
    {
      "path": "packages/registry-native/blocks/media-download-library/MediaDownloadLibrary.tsx",
      "content": "import { Children, Fragment, isValidElement, type ReactNode } from 'react'\nimport { View, type ViewProps } from 'react-native'\nimport { CircleAlert, CircleCheck, Clock, Download } from 'lucide-react-native'\nimport { Button } from '@/components/ui/button'\nimport { Icon } from '@/components/ui/icon'\nimport { List, ListItem, ListItemContent, ListItemDescription, ListItemTitle } from '@/components/ui/list'\nimport { Progress } from '@/components/ui/progress'\nimport { Text } from '@/components/ui/text'\nimport { cn } from '@/lib/utils'\n\nexport interface MediaDownloadLibraryProps extends ViewProps {\n  className?: string\n  /** A bounded set of on-device rows. This inline block does not virtualize its content. */\n  children?: ReactNode\n  /** Caller-composed queued, active, and failed transfers. */\n  transfers?: ReactNode\n  actions?: ReactNode\n  transfersLabel?: string\n  downloadedLabel?: string\n  emptyMessage?: string\n}\n\nfunction hasRows(children: ReactNode): boolean {\n  return Children.toArray(children).some((child) =>\n    isValidElement<{ children?: ReactNode }>(child) && child.type === Fragment ? hasRows(child.props.children) : true,\n  )\n}\n\nexport function MediaDownloadLibrary({\n  children,\n  transfers,\n  actions,\n  transfersLabel = 'Transfers',\n  downloadedLabel = 'On this device',\n  emptyMessage = 'No downloads yet.',\n  className,\n  ...props\n}: MediaDownloadLibraryProps) {\n  return (\n    <View {...props} className={cn('gap-[20px]', className)}>\n      {hasRows(transfers) ? (\n        <View className=\"gap-[8px]\">\n          <Text className=\"font-semibold\">{transfersLabel}</Text>\n          <List className=\"gap-[4px]\">{transfers}</List>\n        </View>\n      ) : null}\n      <View className=\"gap-[8px]\">\n        <Text className=\"font-semibold\">{downloadedLabel}</Text>\n        {hasRows(children) ? (\n          <List className=\"gap-[4px]\">{children}</List>\n        ) : (\n          <Text variant=\"muted\">{emptyMessage}</Text>\n        )}\n        {actions}\n      </View>\n    </View>\n  )\n}\n\nexport type MediaDownloadState =\n  | { kind: 'queued' }\n  | { kind: 'downloading'; progress?: number }\n  | { kind: 'failed'; reason?: string }\n  | { kind: 'downloaded'; size?: string }\n\nconst statusIcons = { queued: Clock, downloading: Download, failed: CircleAlert, downloaded: CircleCheck }\nconst percentFormat = new Intl.NumberFormat(undefined, { style: 'percent', maximumFractionDigits: 0 })\n\nconst defaultLabels = {\n  queued: 'Waiting to download',\n  downloading: 'Downloading',\n  failed: 'Download failed',\n  downloaded: 'Available offline',\n  cancel: 'Cancel download',\n  retry: 'Retry download',\n  play: 'Play',\n  remove: 'Remove download',\n  downloadingProgress: (progress: number) => `Downloading · ${percentFormat.format(progress)}`,\n  actionForItem: (action: string, title: string) => `${action}, ${title}`,\n}\n\nexport interface MediaDownloadItemProps extends ViewProps {\n  className?: string\n  title: string\n  detail?: string\n  /** Download progress is a fraction from 0 to 1. Omit it for an indeterminate transfer. */\n  state: MediaDownloadState\n  onCancel?: () => void\n  onRetry?: () => void\n  onOpen?: () => void\n  /** The consumer owns confirmation or undo and removal of the underlying file. */\n  onRemove?: () => void\n  labels?: Partial<typeof defaultLabels>\n}\n\nexport function MediaDownloadItem({\n  title,\n  detail,\n  state,\n  onCancel,\n  onRetry,\n  onOpen,\n  onRemove,\n  labels,\n  className,\n  ...props\n}: MediaDownloadItemProps) {\n  const copy = { ...defaultLabels, ...labels }\n  const icon = statusIcons[state.kind]\n  const progress =\n    state.kind === 'downloading' && state.progress !== undefined && Number.isFinite(state.progress)\n      ? Math.max(0, Math.min(1, state.progress))\n      : undefined\n  const canCancel = onCancel && (state.kind === 'queued' || state.kind === 'downloading')\n  const canRetry = onRetry && state.kind === 'failed'\n  const canOpen = onOpen && state.kind === 'downloaded'\n  const canRemove = onRemove && state.kind === 'downloaded'\n\n  return (\n    <View {...props} className={cn('px-[4px] pb-[4px]', className)}>\n      <ListItem className=\"items-start px-[12px]\">\n        <View className=\"size-[40px] items-center justify-center rounded-md bg-muted\">\n          <Icon\n            icon={icon}\n            size={19}\n            className={state.kind === 'failed' ? 'text-destructive' : 'text-muted-foreground'}\n          />\n        </View>\n        <ListItemContent>\n          <ListItemTitle>{title}</ListItemTitle>\n          {detail ? <ListItemDescription>{detail}</ListItemDescription> : null}\n          <Text\n            size=\"sm\"\n            variant=\"muted\"\n            className={state.kind === 'failed' ? 'text-destructive' : undefined}\n            style={{ fontVariant: ['tabular-nums'] }}\n          >\n            {progress === undefined ? copy[state.kind] : copy.downloadingProgress(progress)}\n          </Text>\n          {state.kind === 'downloaded' && state.size ? <ListItemDescription>{state.size}</ListItemDescription> : null}\n          {state.kind === 'failed' && state.reason ? <ListItemDescription>{state.reason}</ListItemDescription> : null}\n          {state.kind === 'downloading' ? (\n            <Progress\n              accessibilityLabel={copy.actionForItem(copy.downloading, title)}\n              accessibilityState={{ busy: true }}\n              value={progress === undefined ? undefined : Math.round(progress * 100)}\n              className=\"mt-[4px]\"\n            />\n          ) : null}\n        </ListItemContent>\n      </ListItem>\n      {canCancel || canRetry || canOpen || canRemove ? (\n        <View className=\"flex-row flex-wrap items-center gap-[4px] px-[12px]\">\n          {canCancel ? (\n            <Button\n              size=\"sm\"\n              variant=\"ghost\"\n              accessibilityLabel={copy.actionForItem(copy.cancel, title)}\n              onPress={onCancel}\n            >\n              {copy.cancel}\n            </Button>\n          ) : null}\n          {canRetry ? (\n            <Button\n              size=\"sm\"\n              variant=\"outline\"\n              accessibilityLabel={copy.actionForItem(copy.retry, title)}\n              onPress={onRetry}\n            >\n              {copy.retry}\n            </Button>\n          ) : null}\n          {canOpen ? (\n            <Button\n              size=\"sm\"\n              variant=\"outline\"\n              accessibilityLabel={copy.actionForItem(copy.play, title)}\n              onPress={onOpen}\n            >\n              {copy.play}\n            </Button>\n          ) : null}\n          {canRemove ? (\n            <Button\n              size=\"sm\"\n              variant=\"ghost\"\n              accessibilityLabel={copy.actionForItem(copy.remove, title)}\n              onPress={onRemove}\n            >\n              {copy.remove}\n            </Button>\n          ) : null}\n        </View>\n      ) : null}\n    </View>\n  )\n}\n",
      "type": "registry:block",
      "target": "~/components/blocks/media-download-library/MediaDownloadLibrary.tsx"
    },
    {
      "path": "packages/registry-native/blocks/media-download-library/index.ts",
      "content": "export {\n  MediaDownloadItem,\n  MediaDownloadLibrary,\n  type MediaDownloadItemProps,\n  type MediaDownloadLibraryProps,\n  type MediaDownloadState,\n} from './MediaDownloadLibrary'\n",
      "type": "registry:block",
      "target": "~/components/blocks/media-download-library/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/progress.json",
    "https://native.uipkge.dev/r/native/text.json",
    "https://native.uipkge.dev/r/native/utils.json"
  ],
  "description": "A native offline library with caller-owned download progress, retry, cancel, playback, and removal.",
  "categories": [
    "media"
  ]
}