{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "video-accordion",
  "title": "Video Accordion",
  "author": "AlgorizeTech",
  "description": "Horizontal panels that expand on selection to play a video, with poster fallbacks. Use it for product feature showcases.",
  "dependencies": [],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/blocks/VideoAccordionBlock.tsx",
      "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport React, { useEffect, useRef, useState } from \"react\";\n\n/** GSAP's power3.out, sampled into a CSS `linear()` curve. */\nconst EASE_POWER3_OUT =\n  \"linear(0, .0963, .1855, .2679, .3439, .4138, .478, .5367, .5904, .6392, .6836, .7237, .7599, .7924, .8215, .8474, .8704, .8907, .9085, .924, .9375, .9491, .959, .9674, .9744, .9802, .985, .9888, .9919, .9943, .9961, .9974, .9984, .9991, .9995, .9998, .9999, 1, 1, 1, 1)\";\n\nexport interface AccordionPanel {\n  id: string;\n  title: string;\n  description: string;\n  videoSrc: string;\n  posterUrl?: string; // High quality fallback image\n}\n\nexport interface VideoAccordionProps\n  extends React.HTMLAttributes<HTMLDivElement> {\n  panels: AccordionPanel[];\n  defaultActiveId?: string; // Optional: starts with one expanded\n}\n\nexport const VideoAccordion = React.forwardRef<\n  HTMLDivElement,\n  VideoAccordionProps\n>(({ panels, defaultActiveId, className, ...props }, ref) => {\n  // Allows null so we can have a \"resting state\" where no text is shown\n  const [activeId, setActiveId] = useState<string | null>(\n    defaultActiveId || null,\n  );\n\n  const containerRef = useRef<HTMLDivElement>(null);\n  const panelRefs = useRef<(HTMLDivElement | null)[]>([]);\n  const videoRefs = useRef<(HTMLVideoElement | null)[]>([]);\n  const settled = useRef(false);\n\n  React.useImperativeHandle(ref, () => containerRef.current as HTMLDivElement);\n\n  // Core Layout & Video Playback Engine\n  useEffect(() => {\n    // Settle the painted `flex-1` rest state once, so a default-active panel\n    // still grows open on mount instead of appearing already open.\n    if (!settled.current) {\n      void containerRef.current?.offsetWidth;\n      settled.current = true;\n    }\n\n    panels.forEach((panel, index) => {\n      const panelEl = panelRefs.current[index];\n      const videoEl = videoRefs.current[index];\n      const isActive = activeId === panel.id;\n\n      // 1. Animate the Flexbox Layout (Expansion)\n      if (panelEl) {\n        panelEl.style.transition = `flex-grow 0.8s ${EASE_POWER3_OUT}`;\n        panelEl.style.flexGrow = isActive ? \"5\" : \"1\"; // 5x wider than inactive rails\n      }\n\n      // 2. Handle Video Playback (Only play active/hovered panel, pause others)\n      if (videoEl) {\n        videoEl.muted = true;\n        if (isActive) {\n          const playPromise = videoEl.play();\n          if (playPromise !== undefined) {\n            playPromise.catch(() => {});\n          }\n        } else {\n          videoEl.pause();\n        }\n      }\n\n      // 3. Text visibility is rendered below: the rise transitions, the\n      // opacity switches at once.\n    });\n  }, [activeId, panels]);\n\n  return (\n    <div\n      ref={containerRef}\n      onMouseLeave={() => setActiveId(null)} // Resets to a clean, text-free state when mouse leaves\n      className={cn(\n        // Responsive: Vertical stack on mobile, horizontal rail on md+\n        \"flex flex-col md:flex-row w-full h-[600px] md:h-[500px] gap-2 md:gap-3 overflow-hidden\",\n        className,\n      )}\n      {...props}\n    >\n      {panels.map((panel, index) => {\n        const isActive = activeId === panel.id;\n\n        return (\n          <div\n            key={panel.id}\n            ref={(el) => {\n              panelRefs.current[index] = el;\n            }}\n            onMouseEnter={() => {\n              setActiveId(panel.id);\n              const vid = videoRefs.current[index];\n              if (vid) {\n                vid.muted = true;\n                vid.play().catch(() => {});\n              }\n            }}\n            onMouseLeave={() => {\n              const vid = videoRefs.current[index];\n              if (vid) {\n                vid.pause();\n              }\n            }}\n            onClick={() => {\n              setActiveId(panel.id);\n              const vid = videoRefs.current[index];\n              if (vid) {\n                vid.muted = true;\n                vid.play().catch(() => {});\n              }\n            }}\n            className=\"relative overflow-hidden rounded-2xl cursor-pointer group min-h-[60px] md:min-w-[60px] flex-1 basis-0 bg-zinc-900\"\n          >\n            {/* Background Video Layer with Poster fallback when paused */}\n            <video\n              ref={(el) => {\n                videoRefs.current[index] = el;\n              }}\n              src={panel.videoSrc}\n              poster={panel.posterUrl}\n              muted\n              loop\n              playsInline\n              preload=\"auto\"\n              className={cn(\n                \"absolute inset-0 w-full h-full object-cover transition-transform duration-1000 opacity-100\",\n                isActive ? \"scale-105\" : \"scale-100\",\n              )}\n            />\n\n            {/* Cinematic Overlay (Dark universally for best video contrast) */}\n            <div\n              className={cn(\n                \"absolute inset-0 transition-all duration-700 pointer-events-none\",\n                isActive\n                  ? \"bg-gradient-to-t from-black/90 via-black/20 to-transparent\"\n                  : \"bg-black/50 backdrop-blur-[2px]\",\n              )}\n            />\n\n            {/* Content Payload (Hidden on inactive via inline styles to prevent First-Paint flicker) */}\n            <div className=\"absolute inset-x-0 bottom-0 p-5 md:p-6 flex flex-col justify-end pointer-events-none\">\n              <h3\n                style={{\n                  opacity: isActive ? 1 : 0,\n                  transform: isActive ? \"translateY(0)\" : \"translateY(20px)\",\n                  transition: `transform 0.6s ${EASE_POWER3_OUT}`,\n                }}\n                className=\"text-white font-semibold tracking-tight text-xl md:text-3xl mb-2 whitespace-normal leading-tight\"\n              >\n                {panel.title}\n              </h3>\n              <p\n                style={{\n                  opacity: isActive ? 1 : 0,\n                  transform: isActive ? \"translateY(0)\" : \"translateY(20px)\",\n                  // Slight delay between title and desc\n                  transition: `transform 0.6s ${EASE_POWER3_OUT} 0.05s`,\n                }}\n                className=\"text-white/80 text-sm md:text-base leading-relaxed max-w-lg whitespace-normal line-clamp-3 md:line-clamp-none\"\n              >\n                {panel.description}\n              </p>\n            </div>\n          </div>\n        );\n      })}\n    </div>\n  );\n});\nVideoAccordion.displayName = \"VideoAccordion\";",
      "type": "registry:component",
      "target": "components/custom/blocks/VideoAccordionBlock.tsx"
    }
  ],
  "docs": "Named exports: VideoAccordion, AccordionPanel. Panels take { id, title, description?, videoSrc, posterUrl? }; `defaultActiveId` sets the initially open one. Videos load per panel — keep them short and muted, since autoplay with sound is blocked by browsers.",
  "categories": [
    "media",
    "marketing"
  ],
  "type": "registry:component"
}
