"use client";

import { Sparkles, ExternalLink, Send, MessageSquare } from "lucide-react";

interface GridAdProps {
  type: "telegram" | "mschat";
}

export function GridAdCard({ type }: GridAdProps) {
  const isTelegram = type === "telegram";

  const data = isTelegram
    ? {
        title: "MTBR Telegram",
        subtitle: "Canal Officiel & Exclusivités 🔥",
        description: "Rejoins notre communauté Telegram @madetobreakrules pour ne rien rater des nouveautés !",
        btnText: "REJOINDRE TELEGRAM",
        url: "https://t.me/madetobreakrules",
        badge: "TELEGRAM OFFICIEL",
        badgeColor: "bg-[#e05a68]/20 border-[#e05a68]/50 text-rose-300",
        gradient: "from-[#8c2432] to-[#e05a68]",
        hoverBorder: "group-hover:border-[#e05a68]",
        btnBg: "bg-[#e05a68] text-white hover:bg-[#c93f52]",
        icon: Send,
        img: "https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe?w=800&q=80",
      }
    : {
        title: "Discord Communauté",
        subtitle: "Discord.gg/mtbr 💬",
        description: "Rejoins le Discord officiel MTBR pour discuter et échanger avec la communauté !",
        btnText: "REJOINDRE DISCORD",
        url: "https://discord.gg/mtbr",
        badge: "DISCORD MTBR",
        badgeColor: "bg-[#5865F2]/20 border-[#5865F2]/50 text-[#a5b4fc]",
        gradient: "from-[#5c1922] to-[#8c2432]",
        hoverBorder: "group-hover:border-[#5865F2]",
        btnBg: "bg-[#5865F2] text-white hover:opacity-90",
        icon: MessageSquare,
        img: "https://images.unsplash.com/photo-1579546929518-9e396f3cc809?w=800&q=80",
      };

  const Icon = data.icon;

  const handleClick = (e: React.MouseEvent) => {
    e.preventDefault();
    window.open(data.url, "_blank");
  };

  return (
    <div
      onClick={handleClick}
      className="group block cursor-pointer select-none relative w-full h-full min-h-[220px]"
    >
      <div className={`relative aspect-video w-full rounded-xl md:rounded-2xl overflow-hidden mb-2.5 p-4 bg-[#0a0814] border border-white/10 shadow-lg ${data.hoverBorder} transition-all duration-300 flex flex-col justify-between group-hover:scale-[1.02]`}>
        
        {/* Background Image with Overlay */}
        <img
          src={data.img}
          alt={data.title}
          className="absolute inset-0 w-full h-full object-cover opacity-40 group-hover:opacity-60 transition-opacity duration-300"
        />
        <div className="absolute inset-0 bg-gradient-to-t from-black/90 via-black/40 to-transparent" />

        {/* Top Badges */}
        <div className="flex items-center justify-between z-10">
          <div className={`backdrop-blur-md text-[10px] font-black px-2.5 py-1 rounded-full uppercase tracking-wider flex items-center gap-1 border ${data.badgeColor}`}>
            <Sparkles size={11} /> {data.badge}
          </div>
          <div className="bg-emerald-500/20 border border-emerald-400/40 backdrop-blur-md text-emerald-300 text-[10px] font-extrabold px-2 py-0.5 rounded-full flex items-center gap-1.5">
            <span className="w-1.5 h-1.5 rounded-full bg-emerald-400 animate-ping" /> EN LIGNE
          </div>
        </div>

        {/* Middle Content */}
        <div className="z-10 my-auto pt-2">
          <div className="flex items-center gap-2 mb-1">
            <div className={`w-7 h-7 rounded-lg bg-gradient-to-br ${data.gradient} flex items-center justify-center text-white shadow-md`}>
              <Icon size={14} className="fill-white/20" />
            </div>
            <h3 className="font-black text-sm md:text-base text-white tracking-wide uppercase line-clamp-1 group-hover:text-amber-300 transition-colors drop-shadow">
              {data.title}
            </h3>
          </div>
          <p className="text-xs text-white/80 font-medium line-clamp-2 leading-relaxed drop-shadow">
            {data.description}
          </p>
        </div>

        {/* Bottom CTA Button */}
        <div className="z-10 pt-2 flex items-center justify-between border-t border-white/15">
          <span className="text-[11px] text-white/70 font-semibold truncate max-w-[120px]">
            Partenaire Officiel
          </span>
          <span className={`text-xs font-black px-3 py-1 rounded-lg transition-all flex items-center gap-1 shadow-md ${data.btnBg}`}>
            {data.btnText} <ExternalLink size={12} />
          </span>
        </div>
      </div>
    </div>
  );
}
