"use client";

import Link from "next/link";
import { Play, Info, VolumeX, Volume2 } from "lucide-react";
import { useState } from "react";
import { motion } from "framer-motion";

export function HeroVideo({ media }: { media: any }) {
  const [isMuted, setIsMuted] = useState(true);

  if (!media) return null;

  return (
    <div className="relative w-full h-[60vh] md:h-[70vh] lg:h-[80vh] overflow-hidden bg-[#050508] mb-12">
      {/* Video Background */}
      <div className="absolute inset-0 w-full h-full">
        {media.previewUrl ? (
          <video
            autoPlay
            loop
            muted={isMuted}
            playsInline
            className="object-cover w-full h-full opacity-70 scale-105"
            src={media.previewUrl}
          />
        ) : (
          <img
            src={media.thumbnailUrl || "/placeholder.jpg"}
            alt={media.title}
            className="object-cover w-full h-full opacity-50"
          />
        )}
      </div>

      {/* Gradient Overlays for smooth blending */}
      <div className="absolute inset-0 bg-gradient-to-r from-[#050508] via-[#050508]/60 to-transparent" />
      <div className="absolute inset-0 bg-gradient-to-t from-[#050508] via-transparent to-transparent" />

      {/* Content */}
      <div className="absolute bottom-0 left-0 w-full p-8 md:p-16 lg:p-24 flex flex-col justify-end h-full">
        <motion.div 
          initial={{ opacity: 0, y: 20 }}
          animate={{ opacity: 1, y: 0 }}
          transition={{ duration: 0.8, delay: 0.2 }}
          className="max-w-2xl"
        >
          {media.category && (
            <span className="inline-block px-3 py-1 bg-[#e05a68]/20 text-[#e05a68] font-black text-xs uppercase tracking-widest rounded-full mb-4">
              {media.category.name}
            </span>
          )}
          
          <h1 className="text-4xl md:text-6xl font-black text-white leading-tight mb-4 drop-shadow-2xl line-clamp-2">
            {media.title}
          </h1>
          
          <p className="text-lg text-[#aaaaaa] mb-8 line-clamp-3 max-w-xl font-medium drop-shadow-lg">
            {media.description || "Découvrez cette vidéo exclusive et bien d'autres sur MTBR. Une expérience unique en qualité HD."}
          </p>

          <div className="flex items-center gap-4">
            <Link 
              href={`/video/${media.id}`}
              className="flex items-center gap-2 px-8 py-4 bg-white text-black rounded-lg font-black text-lg hover:bg-gray-200 hover:scale-105 transition-all"
            >
              <Play size={24} fill="currentColor" />
              Lecture
            </Link>
            
            <Link 
              href={`/video/${media.id}`}
              className="flex items-center gap-2 px-8 py-4 bg-[#33334d]/60 backdrop-blur-md text-white rounded-lg font-bold text-lg hover:bg-[#33334d]/80 transition-all"
            >
              <Info size={24} />
              Plus d'infos
            </Link>
          </div>
        </motion.div>
      </div>

      {/* Volume Toggle */}
      {media.previewUrl && (
        <button 
          onClick={() => setIsMuted(!isMuted)}
          className="absolute bottom-16 right-8 md:bottom-24 md:right-16 w-12 h-12 rounded-full border border-white/30 flex items-center justify-center text-white hover:bg-white/10 backdrop-blur-md transition-colors z-20"
        >
          {isMuted ? <VolumeX size={20} /> : <Volume2 size={20} />}
        </button>
      )}
    </div>
  );
}
