{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "user-video-control",
  "title": "User Video Control",
  "description": "Camera toggle with preview tile and camera picker in a split-button dropdown.",
  "dependencies": [
    "@pipecat-ai/client-js@^1.14.0",
    "@pipecat-ai/client-react@^1.9.0",
    "lucide-react@^1.41.0"
  ],
  "registryDependencies": [
    "button",
    "button-group",
    "@pipecat/device-select"
  ],
  "files": [
    {
      "path": "src/components/user-video-control.tsx",
      "content": "\"use client\";\n\nimport type { DeviceErrorReason } from \"@pipecat-ai/client-js\";\nimport {\n  type OptionalMediaDeviceInfo,\n  PipecatClientCamToggle,\n  PipecatClientVideo,\n  useMediaState,\n} from \"@pipecat-ai/client-react\";\nimport {\n  ChevronDownIcon,\n  Loader2Icon,\n  VideoIcon,\n  VideoOffIcon,\n} from \"lucide-react\";\n\nimport {\n  DeviceDropdownContent,\n  DeviceDropdownTrigger,\n  DeviceDropdownView,\n  usePipecatDevices,\n} from \"@/components/pipecat/device-select\";\nimport { Button } from \"@/components/ui/button\";\nimport { ButtonGroup } from \"@/components/ui/button-group\";\nimport { cn } from \"@/lib/utils\";\n\ntype ButtonProps = React.ComponentProps<typeof Button>;\n\n// Camera on keeps the plain button surface; camera off styles per variant\n// while off (data-state also flips for consumer styling), matching the\n// user audio control: solid variants fill with the inactive color, outline\n// keeps its border + tint (nova's destructive-button idiom), secondary\n// tints without a border, ghost only recolors content. Unknown\n// (consumer-added) variants get the ghost treatment.\nconst INACTIVE_VARIANT_CLASSES: Record<string, string> = {\n  default: \"bg-inactive text-inactive-foreground hover:bg-inactive/80\",\n  outline:\n    \"border-inactive/30 bg-inactive/10 text-inactive hover:bg-inactive/20 hover:text-inactive dark:bg-inactive/20\",\n  secondary:\n    \"bg-inactive/10 text-inactive hover:bg-inactive/20 dark:bg-inactive/20\",\n  ghost: \"text-inactive hover:text-inactive\",\n};\n\nfunction inactiveClasses(variant: ButtonProps[\"variant\"]): string {\n  return (\n    INACTIVE_VARIANT_CLASSES[variant ?? \"default\"] ??\n    INACTIVE_VARIANT_CLASSES.ghost!\n  );\n}\n\n// Nova's icon-* sizes render a square button; the toggle responds by going\n// icon-only (no label, no min-width).\nfunction isIconSize(size: ButtonProps[\"size\"]): boolean {\n  return typeof size === \"string\" && size.startsWith(\"icon\");\n}\n\n// Nova's icon sizes mirror the text sizes by suffix (sm ↔ icon-sm), so the\n// picker trigger derives its size from the control's mechanically.\nfunction iconSize(size: ButtonProps[\"size\"]): ButtonProps[\"size\"] {\n  if (isIconSize(size)) return size;\n  return !size || size === \"default\"\n    ? \"icon\"\n    : (`icon-${size}` as ButtonProps[\"size\"]);\n}\n\nexport interface UserVideoControlViewProps {\n  /** Whether the camera is currently enabled. */\n  isCamEnabled?: boolean;\n  /** Called when the user clicks the camera toggle. */\n  onToggleCam?: () => void;\n  /** Disables the control and shows a spinner (e.g. while devices initialize). */\n  isLoading?: boolean;\n  /** Content shown next to the spinner while loading. Spinner only by default. */\n  loadingText?: React.ReactNode;\n  /**\n   * When set, the control renders disabled with this message instead of the\n   * toggle (camera blocked, in use, not found, …). Takes precedence over the\n   * interactive state; isLoading takes precedence over both.\n   */\n  unavailableText?: React.ReactNode;\n  /** Cameras offered in the picker. */\n  cams?: MediaDeviceInfo[];\n  /** Currently selected camera, matched by deviceId. */\n  selectedCam?: OptionalMediaDeviceInfo;\n  /** Called with the deviceId when the user picks a camera. */\n  onCamChange?: (deviceId: string) => void;\n  /** Hide the camera picker dropdown. */\n  noDevicePicker?: boolean;\n  /** Render only the toggle button, without the video preview tile. */\n  noVideo?: boolean;\n  /** Video element rendered in the tile while the camera is on. */\n  video?: React.ReactNode;\n  /** Label shown while the camera is on. */\n  activeText?: React.ReactNode;\n  /** Label shown while the camera is off. */\n  inactiveText?: React.ReactNode;\n  /** Hide the camera icon. */\n  noIcon?: boolean;\n  /** Button variant for the toggle and picker trigger. */\n  variant?: ButtonProps[\"variant\"];\n  /**\n   * Button size for the toggle; the picker trigger scales with it. Icon\n   * sizes (\"icon\", \"icon-sm\", …) render the toggle icon-only: the label\n   * is hidden.\n   */\n  size?: ButtonProps[\"size\"];\n  /** Classes for the tile, or for the ButtonGroup when noVideo is set. */\n  className?: string;\n  /** Extra content rendered inside the toggle, after the label. */\n  children?: React.ReactNode;\n}\n\n/** Camera toggle and device picker with an optional preview. Loading takes precedence over unavailability. */\nexport function UserVideoControlView({\n  isCamEnabled = false,\n  onToggleCam,\n  isLoading = false,\n  loadingText,\n  unavailableText,\n  cams,\n  selectedCam,\n  onCamChange,\n  noDevicePicker = false,\n  noVideo = false,\n  video,\n  activeText,\n  inactiveText,\n  noIcon = false,\n  variant = \"outline\",\n  size = \"default\",\n  className,\n  children,\n}: UserVideoControlViewProps) {\n  const iconOnly = isIconSize(size);\n  const stateText = iconOnly\n    ? undefined\n    : isCamEnabled\n      ? activeText\n      : inactiveText;\n\n  let toggle: React.ReactNode;\n  if (isLoading || unavailableText) {\n    toggle = (\n      <ButtonGroup\n        data-slot=\"user-video-control\"\n        className={noVideo ? className : undefined}\n      >\n        <Button\n          variant={variant}\n          size={size}\n          disabled\n          aria-busy={isLoading || undefined}\n          data-state={isLoading ? \"loading\" : \"unavailable\"}\n          aria-label={\n            !iconOnly\n              ? undefined\n              : isLoading\n                ? \"Camera loading\"\n                : typeof unavailableText === \"string\"\n                  ? unavailableText\n                  : \"Camera unavailable\"\n          }\n          className={cn(\"grow\", !iconOnly && \"min-w-32\")}\n        >\n          {isLoading ? (\n            <>\n              <Loader2Icon className=\"animate-spin\" />\n              {!iconOnly && loadingText}\n            </>\n          ) : (\n            <>\n              {!noIcon && <VideoOffIcon />}\n              {!iconOnly && unavailableText}\n            </>\n          )}\n        </Button>\n        {/* Keep the (disabled) picker trigger while loading so the split\n            button doesn't collapse; it stays hidden for unavailable, which\n            is a terminal state until permissions change. */}\n        {isLoading && !noDevicePicker && (\n          <Button\n            variant={variant}\n            size={iconSize(size)}\n            disabled\n            aria-label=\"Camera devices\"\n          >\n            <ChevronDownIcon />\n          </Button>\n        )}\n      </ButtonGroup>\n    );\n  } else {\n    toggle = (\n      <ButtonGroup\n        data-slot=\"user-video-control\"\n        className={noVideo ? className : undefined}\n      >\n        <Button\n          variant={variant}\n          size={size}\n          data-state={isCamEnabled ? \"active\" : \"inactive\"}\n          aria-pressed={isCamEnabled}\n          aria-label={\n            stateText\n              ? undefined\n              : isCamEnabled\n                ? \"Turn off camera\"\n                : \"Turn on camera\"\n          }\n          onClick={onToggleCam}\n          className={cn(\n            // Fills a group given a width; content-sized groups are unaffected.\n            \"grow\",\n            !isCamEnabled && inactiveClasses(variant),\n            !iconOnly && \"min-w-32\",\n          )}\n        >\n          {!noIcon && (isCamEnabled ? <VideoIcon /> : <VideoOffIcon />)}\n          {stateText}\n          {children}\n        </Button>\n        {!noDevicePicker && (\n          <DeviceDropdownView\n            kind=\"videoinput\"\n            devices={cams}\n            selectedDevice={selectedCam}\n            onDeviceChange={onCamChange}\n          >\n            <DeviceDropdownTrigger\n              render={\n                <Button\n                  variant={variant}\n                  size={iconSize(size)}\n                  aria-label=\"Camera devices\"\n                >\n                  <ChevronDownIcon />\n                </Button>\n              }\n            />\n            <DeviceDropdownContent />\n          </DeviceDropdownView>\n        )}\n      </ButtonGroup>\n    );\n  }\n\n  if (noVideo) return toggle;\n\n  return (\n    <div\n      data-slot=\"user-video-tile\"\n      className={cn(\n        \"bg-muted relative aspect-video overflow-hidden rounded-xl\",\n        className,\n      )}\n    >\n      <div className={cn(\"absolute inset-0\", !isCamEnabled && \"hidden\")}>\n        {video}\n      </div>\n      <div className=\"absolute bottom-2 left-2\">{toggle}</div>\n    </div>\n  );\n}\n\n/** Short, user-facing message for a camera device error. */\nfunction camErrorText(reason: DeviceErrorReason): string {\n  switch (reason) {\n    case \"blocked\":\n      return \"Camera blocked\";\n    case \"already-in-use\":\n      return \"Camera in use\";\n    case \"not-found\":\n      return \"No camera\";\n    case \"not-supported\":\n      return \"Video not supported\";\n    case \"unknown\":\n    default:\n      return \"Camera unavailable\";\n  }\n}\n\nexport interface UserVideoControlProps extends Omit<\n  UserVideoControlViewProps,\n  | \"isCamEnabled\"\n  | \"onToggleCam\"\n  | \"cams\"\n  | \"selectedCam\"\n  | \"onCamChange\"\n  | \"video\"\n  | \"isLoading\"\n  | \"unavailableText\"\n> {\n  /** Replaces the automatically derived device-error message. */\n  unavailableText?: React.ReactNode;\n  /** Props for the underlying PipecatClientVideo element. */\n  videoProps?: Partial<React.ComponentProps<typeof PipecatClientVideo>>;\n}\n\n/** Requires PipecatClientProvider; manages camera state, devices, and preview. */\nexport function UserVideoControl({\n  unavailableText,\n  videoProps,\n  ...props\n}: UserVideoControlProps) {\n  const {\n    devices: cams,\n    selectedDevice: selectedCam,\n    updateDevice: onCamChange,\n  } = usePipecatDevices(\"videoinput\");\n\n  // \"uninitialized\" is deliberately not treated as loading: it also covers\n  // post-init setups where the transport didn't acquire the camera (e.g.\n  // enableCam false). In those cases nothing is in flight, so the control\n  // just renders off.\n  const { cam } = useMediaState();\n  const isLoading = cam.state === \"initializing\";\n  const derivedUnavailable =\n    cam.state === \"error\" ? camErrorText(cam.reason) : undefined;\n\n  return (\n    <PipecatClientCamToggle>\n      {({ isCamEnabled, onClick }) => (\n        <UserVideoControlView\n          isCamEnabled={isCamEnabled}\n          onToggleCam={onClick}\n          isLoading={isLoading}\n          unavailableText={unavailableText ?? derivedUnavailable}\n          cams={cams}\n          selectedCam={selectedCam}\n          onCamChange={onCamChange}\n          video={\n            <PipecatClientVideo\n              participant=\"local\"\n              className=\"h-full w-full object-cover\"\n              {...videoProps}\n            />\n          }\n          {...props}\n        />\n      )}\n    </PipecatClientCamToggle>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/pipecat/user-video-control.tsx"
    }
  ],
  "cssVars": {
    "theme": {
      "color-inactive": "var(--inactive-background)",
      "color-inactive-foreground": "var(--inactive-foreground)"
    },
    "light": {
      "inactive-background": "oklch(0.702 0.189 22.23)",
      "inactive-foreground": "oklch(0.971 0.013 17.38)"
    },
    "dark": {
      "inactive-background": "oklch(0.702 0.189 22.23)",
      "inactive-foreground": "oklch(0.971 0.013 17.38)"
    }
  },
  "docs": "Render inside a PipecatClientProvider. Use noVideo for a plain toggle without the preview tile.",
  "categories": [
    "voice"
  ],
  "type": "registry:component"
}