{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "media-chapter-list",
  "title": "Media Chapter List",
  "type": "registry:block",
  "files": [
    {
      "path": "packages/registry-native/blocks/media-chapter-list/MediaChapterList.tsx",
      "content": "import * as React from 'react'\nimport { FlatList, View, useWindowDimensions, type ViewProps } from 'react-native'\nimport { ListItem, ListItemContent, ListItemDescription, ListItemTitle, ListSeparator } from '@/components/ui/list'\nimport { Text } from '@/components/ui/text'\nimport { cn } from '@/lib/utils'\n\nexport interface MediaChapter {\n  id: string\n  title: string\n  startSeconds: number\n  detail?: string\n}\n\nconst defaultLabels = {\n  title: 'Chapters',\n  empty: 'No chapters available.',\n  current: 'Current chapter',\n  duration: (value: string) => `Duration, ${value}`,\n  startsAt: (value: string) => `Starts at ${value}`,\n}\n\nexport interface MediaChapterListProps extends Omit<ViewProps, 'children'> {\n  className?: string\n  /** Media duration. Every valid chapter begins before this timestamp. */\n  duration: number\n  /** The caller's current playback position in seconds. */\n  position?: number\n  /** A controlled current chapter, overriding position when supplied. Null means none. */\n  currentId?: string | null\n  /** IDs and start times must be distinct. Invalid entries are omitted. */\n  chapters?: readonly MediaChapter[]\n  onSeek?: (id: string, startSeconds: number) => void\n  disabled?: boolean\n  header?: React.ReactNode\n  labels?: Partial<typeof defaultLabels>\n  formatTime?: (seconds: number) => string\n  formatAccessibleTime?: (seconds: number) => string\n}\n\nfunction hoursMinutesSeconds(seconds: number) {\n  const whole = Math.floor(seconds)\n  return [Math.floor(whole / 3600), Math.floor(whole / 60) % 60, whole % 60]\n}\n\nfunction clock(seconds: number) {\n  const [hour, minute, second] = hoursMinutesSeconds(seconds)\n  const rest = String(second).padStart(2, '0')\n  return hour ? `${hour}:${String(minute).padStart(2, '0')}:${rest}` : `${minute}:${rest}`\n}\n\nfunction speak(seconds: number) {\n  const [hour, minute, second] = hoursMinutesSeconds(seconds)\n  const parts = [\n    hour ? `${hour} ${hour === 1 ? 'hour' : 'hours'}` : '',\n    minute ? `${minute} ${minute === 1 ? 'minute' : 'minutes'}` : '',\n    second ? `${second} ${second === 1 ? 'second' : 'seconds'}` : '',\n  ]\n  return parts.filter(Boolean).join(', ') || '0 seconds'\n}\n\nfunction validChapters(chapters: readonly MediaChapter[], duration: number) {\n  const ids = new Set<string>()\n  const starts = new Set<number>()\n  const ordered = chapters\n    .filter(\n      (chapter) =>\n        chapter.id.trim() && chapter.title.trim() && chapter.startSeconds >= 0 && chapter.startSeconds < duration,\n    )\n    .sort((left, right) => left.startSeconds - right.startSeconds)\n  return ordered.filter((chapter) => {\n    if (ids.has(chapter.id) || starts.has(chapter.startSeconds)) return false\n    ids.add(chapter.id)\n    starts.add(chapter.startSeconds)\n    return true\n  })\n}\n\nexport function MediaChapterList({\n  className,\n  duration,\n  position,\n  currentId,\n  chapters = [],\n  onSeek,\n  disabled = false,\n  header,\n  labels,\n  formatTime = clock,\n  formatAccessibleTime = speak,\n  ...props\n}: MediaChapterListProps) {\n  const copy = { ...defaultLabels, ...labels }\n  const safeDuration = Number.isFinite(duration) && duration > 0 && duration <= Number.MAX_SAFE_INTEGER ? duration : 0\n  const ordered = React.useMemo(() => validChapters(chapters, safeDuration), [chapters, safeDuration])\n  const { width, fontScale } = useWindowDimensions()\n  const stack = width < 360 || fontScale >= 1.4\n  let selected = currentId\n  if (currentId === undefined && position !== undefined && Number.isFinite(position) && position >= 0) {\n    for (const chapter of ordered) {\n      if (chapter.startSeconds > position) break\n      selected = chapter.id\n    }\n  }\n\n  return (\n    <View {...props} className={cn('min-h-0 flex-1', className)}>\n      <FlatList\n        data={ordered}\n        keyExtractor={(chapter) => chapter.id}\n        ItemSeparatorComponent={ListSeparator}\n        contentContainerStyle={{ paddingBottom: 16 }}\n        ListHeaderComponent={\n          <View className=\"gap-3 pb-3\">\n            {header}\n            <View className=\"flex-row flex-wrap items-baseline justify-between gap-2\">\n              <Text size=\"xl\" accessibilityRole=\"header\">\n                {copy.title}\n              </Text>\n              {safeDuration ? (\n                <Text\n                  size=\"sm\"\n                  variant=\"muted\"\n                  accessibilityLabel={copy.duration(formatAccessibleTime(safeDuration))}\n                  style={{ fontVariant: ['tabular-nums'] }}\n                >\n                  {formatTime(safeDuration)}\n                </Text>\n              ) : null}\n            </View>\n          </View>\n        }\n        ListEmptyComponent={<Text className=\"rounded-xl border border-border px-4 py-6 text-center\">{copy.empty}</Text>}\n        renderItem={({ item }) => {\n          const current = item.id === selected\n          return (\n            <ListItem\n              accessible\n              accessibilityLabel={[\n                item.title,\n                copy.startsAt(formatAccessibleTime(item.startSeconds)),\n                item.detail,\n                current && !onSeek ? copy.current : undefined,\n              ]\n                .filter(Boolean)\n                .join(', ')}\n              accessibilityState={{ selected: current && !!onSeek }}\n              disabled={disabled && !!onSeek}\n              onPress={\n                onSeek\n                  ? () => {\n                      if (!disabled) onSeek(item.id, item.startSeconds)\n                    }\n                  : undefined\n              }\n              className={cn(current && 'rounded-lg bg-muted', stack && 'flex-col items-start')}\n            >\n              <ListItemContent>\n                <ListItemTitle className={current ? 'font-semibold' : undefined}>{item.title}</ListItemTitle>\n                {item.detail ? <ListItemDescription>{item.detail}</ListItemDescription> : null}\n                {current ? (\n                  <Text size=\"sm\" className=\"font-medium\">\n                    {copy.current}\n                  </Text>\n                ) : null}\n              </ListItemContent>\n              <Text size=\"sm\" variant=\"muted\" style={{ fontVariant: ['tabular-nums'] }}>\n                {formatTime(item.startSeconds)}\n              </Text>\n            </ListItem>\n          )\n        }}\n      />\n    </View>\n  )\n}\n",
      "type": "registry:block",
      "target": "~/components/blocks/media-chapter-list/MediaChapterList.tsx"
    },
    {
      "path": "packages/registry-native/blocks/media-chapter-list/index.ts",
      "content": "export { MediaChapterList, type MediaChapter, type MediaChapterListProps } from './MediaChapterList'\n",
      "type": "registry:block",
      "target": "~/components/blocks/media-chapter-list/index.ts"
    }
  ],
  "dependencies": [],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/list.json",
    "https://native.uipkge.dev/r/native/text.json"
  ],
  "description": "A native chapter list with playback position, exact seek requests, and accessible current-chapter state.",
  "categories": [
    "media",
    "navigation"
  ]
}