"use client"; import { useState, useEffect } from "react"; import { useLanguage } from "@/contexts/LanguageContext"; import { contentVideosApi, ContentVideoPublic } from "@/lib/api"; import { Youtube, Play, X } from "lucide-react"; interface YouTubeVideoDisplayProps { entityType: "project" | "solution" | "product"; entityId: number; } export default function YouTubeVideoDisplay({ entityType, entityId, }: YouTubeVideoDisplayProps) { const { locale } = useLanguage(); const [videos, setVideos] = useState([]); const [loading, setLoading] = useState(true); const [playingVideo, setPlayingVideo] = useState(null); useEffect(() => { const fetchVideos = async () => { try { const data = await contentVideosApi.getForEntity(entityType, entityId, locale); setVideos(data); } catch (error) { console.error("Failed to fetch videos:", error); } finally { setLoading(false); } }; fetchVideos(); }, [entityType, entityId, locale]); if (loading || videos.length === 0) { return null; } return ( <> {/* Video Section */}

{locale === "ko" ? "관련 영상" : locale === "en" ? "Related Videos" : locale === "ja" ? "関連動画" : "相关视频"}

{videos.map((video) => (
setPlayingVideo(video)} > {/* Thumbnail */}
{video.title} { (e.target as HTMLImageElement).src = `https://img.youtube.com/vi/${video.youtube_id}/hqdefault.jpg`; }} /> {/* Play button overlay */}
{/* Title */}

{video.title}

{video.description && (

{video.description}

)}
))}
{/* Video Modal */} {playingVideo && (
setPlayingVideo(null)} >
e.stopPropagation()} > {/* Close button */} {/* Video iframe */}