'use client';

import { useState, useEffect } from 'react';
import { cn } from '@/lib/utils';

// 배경 영상 목록
const BACKGROUND_VIDEOS = [
    '/background-videos/1.yard.mp4',
    '/background-videos/2.SN2635_LNGC_CARDIFF.mp4',
    '/background-videos/3.SN2628_CONT_WAN HAI.mp4',
    '/background-videos/4.SN2612_LNGC_KGL.mp4',
    '/background-videos/5.SN2596_LNGC_JP MORGAN.mp4',
    '/background-videos/6.2235_FLNG_ENI_CORAL.mp4',
    '/background-videos/7.2126_FLNG_PETRONAS.mp4',
];

interface VideoBackgroundProps {
    quote: string;
}

export function VideoBackground({ quote }: VideoBackgroundProps) {
    const [currentVideoIndex, setCurrentVideoIndex] = useState(0);

    // 컴포넌트 마운트 시 랜덤한 비디오 선택
    useEffect(() => {
        if (typeof window !== 'undefined') {
            setCurrentVideoIndex(Math.floor(Math.random() * BACKGROUND_VIDEOS.length));
        }
    }, []);

    // 비디오 종료 시 다음 비디오로 전환
    const handleVideoEnd = () => {
        setCurrentVideoIndex((prevIndex) => (prevIndex + 1) % BACKGROUND_VIDEOS.length);
    };

    return (
        <div className="relative hidden h-full flex-col p-10 text-white dark:border-r md:flex overflow-hidden">
            <div className="absolute inset-0">
                <video
                    key={currentVideoIndex}
                    autoPlay
                    muted
                    onEnded={handleVideoEnd}
                    className="w-full h-full object-cover"
                    playsInline
                >
                    <source src={BACKGROUND_VIDEOS[currentVideoIndex]} type="video/mp4" />
                </video>
                {/* 어두운 오버레이 */}
                <div className="absolute inset-0 bg-black/30"></div>
            </div>
            <div className="relative z-10 mt-auto">
                <blockquote className="space-y-2 backdrop-blur-sm bg-black/20 p-4 rounded-lg">
                    <p className="text-sm font-medium drop-shadow-lg">&ldquo;{quote}&rdquo;</p>
                </blockquote>
            </div>
            {/* 비디오 인디케이터 */}
            <div className="relative z-10 flex justify-center space-x-2 mb-4">
                {BACKGROUND_VIDEOS.map((_, index) => (
                    <div
                        key={index}
                        className={cn(
                            "w-2 h-2 rounded-full transition-all duration-300",
                            index === currentVideoIndex 
                                ? "bg-white w-8" 
                                : "bg-white/50 hover:bg-white/75 cursor-pointer"
                        )}
                        onClick={() => setCurrentVideoIndex(index)}
                    />
                ))}
            </div>
        </div>
    );
}

