{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "spotify-card",
  "title": "Spotify Card",
  "description": "A track card with cover art, a link to Spotify and a preview clip that spins a record while it plays.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "@corsair-ui/utils",
    "@corsair-ui/spotify-track"
  ],
  "files": [
    {
      "path": "registry/default/ui/spotify-card.tsx",
      "content": "\"use client\";\n\nimport { PauseIcon, PlayIcon } from \"lucide-react\";\nimport { useEffect, useRef, useState, type ComponentProps } from \"react\";\n\nimport type { SpotifyTrack } from \"@/registry/default/lib/spotify-track\";\nimport { cn } from \"@/registry/default/lib/utils\";\n\n// The Spotify logo.\nconst SPOTIFY_LOGO =\n  \"M12 0C5.4 0 0 5.4 0 12s5.4 12 12 12 12-5.4 12-12S18.66 0 12 0zm5.521 17.34c-.24.359-.66.48-1.021.24-2.82-1.74-6.36-2.101-10.561-1.141-.418.122-.779-.179-.899-.539-.12-.421.18-.78.54-.9 4.56-1.021 8.52-.6 11.64 1.32.42.18.479.659.301 1.02zm1.44-3.3c-.301.42-.841.6-1.262.3-3.239-1.98-8.159-2.58-11.939-1.38-.479.12-1.02-.12-1.14-.6-.12-.48.12-1.021.6-1.141C9.6 9.9 15 10.561 18.72 12.84c.361.181.54.78.241 1.2zm.12-3.36C15.24 8.4 8.82 8.16 5.16 9.301c-.6.179-1.2-.181-1.38-.721-.18-.601.18-1.2.72-1.381 4.26-1.26 11.28-1.02 15.721 1.621.539.3.719 1.02.419 1.56-.299.421-1.02.599-1.559.3z\";\n\n// One preview at a time: starting a card stops whichever was playing.\nlet current: HTMLAudioElement | null = null;\n\ninterface SpotifyCardProps extends Omit<ComponentProps<\"article\">, \"children\"> {\n  /** Track details, e.g. from `getSpotifyTrack` on the server. */\n  track: SpotifyTrack;\n  /** Preview volume, from 0 to 1. */\n  volume?: number;\n}\n\n/**\n * A compact card for a Spotify track: cover art over a glow of its own\n * colours, title and artist, and a link to open it in Spotify. When the\n * track has a preview clip, the cover plays it: a record slides out and\n * turns while it plays, and only one card plays at a time. The data comes\n * in as props, so fetch it on the server with `getSpotifyTrack`.\n *\n * @example\n * const track = await getSpotifyTrack(\"https://open.spotify.com/track/…\");\n * return <SpotifyCard track={track} />;\n */\n/** Plays or pauses a preview, making sure it is the only one playing. */\nfunction playOrPause(player: HTMLAudioElement, volume: number, onRefused: () => void) {\n  player.volume = Math.min(Math.max(volume, 0), 1);\n  if (!player.paused) {\n    player.pause();\n    return;\n  }\n  if (current && current !== player) current.pause();\n  current = player;\n  void player.play().catch(onRefused);\n}\n\nfunction SpotifyCard({ track, volume = 0.4, className, ...props }: SpotifyCardProps) {\n  const audio = useRef<HTMLAudioElement | null>(null);\n  const stop = useRef<() => void>(() => {});\n  const [playing, setPlaying] = useState(false);\n  const [progress, setProgress] = useState(0);\n\n  // Silence the preview when the card goes away.\n  useEffect(() => () => stop.current(), []);\n\n  const toggle = () => {\n    if (!track.audio) return;\n    if (!audio.current) {\n      const player = new Audio(track.audio);\n      player.addEventListener(\"play\", () => setPlaying(true));\n      player.addEventListener(\"pause\", () => setPlaying(false));\n      player.addEventListener(\"ended\", () => setProgress(0));\n      player.addEventListener(\"timeupdate\", () =>\n        setProgress(player.duration ? player.currentTime / player.duration : 0)\n      );\n      stop.current = () => {\n        player.pause();\n        if (current === player) current = null;\n      };\n      audio.current = player;\n    }\n    playOrPause(audio.current, volume, () => setPlaying(false));\n  };\n\n  const cover = track.image ? (\n    <img\n      src={track.image}\n      alt=\"\"\n      width={80}\n      height={80}\n      className={cn(\n        \"relative z-10 size-20 rounded-lg object-cover shadow-lg transition-transform duration-300 ease-out motion-reduce:transition-none\",\n        playing && \"-translate-x-1\"\n      )}\n    />\n  ) : (\n    <span className=\"bg-muted relative z-10 size-20 rounded-lg\" />\n  );\n\n  return (\n    <article\n      data-slot=\"spotify-card\"\n      data-state={playing ? \"playing\" : \"idle\"}\n      aria-label={`${track.title} by ${track.artist}`}\n      className={cn(\n        \"relative isolate flex w-full max-w-sm items-center gap-4 overflow-hidden rounded-2xl border bg-neutral-950 p-3 pr-4 text-white\",\n        className\n      )}\n      {...props}\n    >\n      {track.image ? (\n        // The cover itself, blurred into a glow of its colours.\n        <img\n          src={track.image}\n          alt=\"\"\n          aria-hidden=\"true\"\n          className=\"absolute inset-0 -z-10 size-full scale-150 object-cover opacity-60 blur-2xl saturate-150\"\n        />\n      ) : null}\n      <span\n        aria-hidden=\"true\"\n        className=\"absolute inset-0 -z-10 bg-[image:linear-gradient(90deg,rgb(0_0_0/0.15),rgb(0_0_0/0.7))]\"\n      />\n\n      <div className=\"group/cover relative shrink-0\">\n        {track.audio ? (\n          <>\n            {/* The record: grooves are a repeating radial gradient, so there is nothing to load. */}\n            <span aria-hidden=\"true\" className=\"absolute inset-y-0 left-1.5 flex items-center\">\n              <span\n                data-slot=\"spotify-card-record\"\n                className={cn(\n                  \"size-[4.4rem] transition-transform duration-500 ease-out motion-reduce:transition-none\",\n                  // Behind the cover at rest, peeking out on hover, half out while it plays.\n                  playing\n                    ? \"translate-x-6\"\n                    : \"translate-x-0 group-focus-within/cover:translate-x-3 group-hover/cover:translate-x-3\"\n                )}\n              >\n                <span\n                  className={cn(\n                    \"relative block size-full rounded-full bg-[image:repeating-radial-gradient(circle,#111_0,#111_2px,#1d1d1d_3px,#111_4px)] shadow-md motion-safe:animate-spin\",\n                    !playing && \"[animation-play-state:paused]\"\n                  )}\n                  style={{ animationDuration: \"2.4s\" }}\n                >\n                  <span className=\"absolute inset-[34%] rounded-full bg-[image:radial-gradient(circle,#0b0b0b_0_18%,var(--spotify-card-label,#d9b06a)_19%)]\" />\n                </span>\n              </span>\n            </span>\n            <button\n              type=\"button\"\n              onClick={toggle}\n              aria-pressed={playing}\n              aria-label={`Play preview of ${track.title}`}\n              className=\"relative block cursor-pointer rounded-lg outline-none focus-visible:ring-[3px] focus-visible:ring-white/60\"\n            >\n              {cover}\n              <span\n                aria-hidden=\"true\"\n                className={cn(\n                  \"absolute inset-0 z-20 grid place-items-center rounded-lg bg-black/35 opacity-0 transition-opacity duration-200 group-focus-within/cover:opacity-100 group-hover/cover:opacity-100\",\n                  playing && \"opacity-100\"\n                )}\n              >\n                <span className=\"grid size-9 place-items-center rounded-full bg-white text-black shadow\">\n                  {playing ? (\n                    <PauseIcon className=\"size-4 fill-current\" />\n                  ) : (\n                    <PlayIcon className=\"size-4 translate-x-px fill-current\" />\n                  )}\n                </span>\n              </span>\n            </button>\n          </>\n        ) : (\n          cover\n        )}\n      </div>\n\n      <div className=\"relative z-10 grid min-w-0 flex-1 gap-0.5\">\n        <p className=\"truncate text-sm font-semibold\">{track.title}</p>\n        <p className=\"truncate text-sm text-white/70\">{track.artist}</p>\n        {track.audio ? (\n          <span\n            aria-hidden=\"true\"\n            className=\"mt-2 block h-0.5 overflow-hidden rounded-full bg-white/20\"\n          >\n            <span\n              className=\"block h-full origin-left rounded-full bg-white/80\"\n              style={{ transform: `scaleX(${progress})` }}\n            />\n          </span>\n        ) : null}\n      </div>\n\n      <a\n        href={track.link}\n        target=\"_blank\"\n        rel=\"noopener noreferrer\"\n        aria-label=\"Open in Spotify\"\n        className=\"relative z-10 shrink-0 self-start rounded-full text-white/80 outline-none hover:text-white focus-visible:ring-[3px] focus-visible:ring-white/60\"\n      >\n        <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" className=\"size-5 fill-current\">\n          <path d={SPOTIFY_LOGO} />\n        </svg>\n      </a>\n    </article>\n  );\n}\n\n/** The card's size and shape while a track loads. */\nfunction SpotifyCardSkeleton({ className, ...props }: ComponentProps<\"div\">) {\n  return (\n    <div\n      role=\"status\"\n      aria-label=\"Loading track\"\n      data-slot=\"spotify-card-skeleton\"\n      className={cn(\"flex w-full max-w-sm items-center gap-4 rounded-2xl border p-3\", className)}\n      {...props}\n    >\n      <div className=\"bg-muted size-20 shrink-0 animate-pulse rounded-lg\" />\n      <div className=\"grid flex-1 gap-2\">\n        <div className=\"bg-muted h-3.5 w-32 animate-pulse rounded\" />\n        <div className=\"bg-muted h-3.5 w-20 animate-pulse rounded\" />\n      </div>\n    </div>\n  );\n}\n\nexport { SpotifyCard, SpotifyCardSkeleton, type SpotifyCardProps };\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}