"use client";

import React, { useState } from "react";
import Image from "next/image";
import Link from "next/link";
import {
  FaDownload,
  FaEnvelope,
  FaCircleCheck,
  FaChevronRight,
  FaBoltLightning
} from "react-icons/fa6";
import {
  LuShieldAlert,
  LuLeaf,
  LuFlame,
  LuGauge,
  LuActivity
} from "react-icons/lu";

// Core highlights type definition
interface HighlightCard {
  icon: React.ReactNode;
  title: string;
  description: string;
}

// Product data mapping for variants grid
interface WireVariant {
  id: string;
  code: string;
  title: string;
  image: string;
  description: string;
  specs: {
    conductor: string;
    insulation: string;
    specialProperty: string;
  };
}

export default function PolycabWiresDetail() {
  const [activeTab, setActiveTab] = useState<string>("all");

  const coreHighlights: HighlightCard[] = [
    {
      icon: <LuGauge className="w-5 h-5 text-amber-600" />,
      title: "1100V Industrial Class",
      description: "Heavy-duty PVC insulated multi-stranded configurations engineered reliably up to 1100 Volts."
    },
    {
      icon: <LuLeaf className="w-5 h-5 text-emerald-600" />,
      title: "The Power of Green",
      description: "Eco-friendly, energy-efficient, and fully recyclable lines built for modern sustainable Green Buildings."
    },
    {
      icon: <LuShieldAlert className="w-5 h-5 text-blue-600" />,
      title: "RoHS Compliant Safety",
      description: "Conforms to strict European safety norms with low toxic gas emission profiles under intense thermal duress."
    }
  ];

  const wireVariants: WireVariant[] = [
    {
      id: "fr",
      code: "FR",
      title: "FR Flame Retardant",
      image: "https://realswitchgears.com/assets/images/products/polycab-wire/wire/FR.png",
      description: "Single core multi-stranded copper conductor, FR PVC insulated wires featuring specialized engineering for advanced fire-retardant performance.",
      specs: { conductor: "Multi-stranded Copper", insulation: "FR PVC Compound", specialProperty: "Self-Extinguishing" }
    },
    {
      id: "frls",
      code: "FRLS",
      title: "FRLS Flame Retardant Low Smoke Low Halogen",
      image: "https://realswitchgears.com/assets/images/products/polycab-wire/wire/FRLS.png",
      description: "Single core multi-stranded copper conductor, FRLS PVC insulated wire carefully mixed to offer excellent flame retardance alongside low smoke and reduced toxic halogen emissions.",
      specs: { conductor: "Multi-stranded Copper", insulation: "FRLS PVC Compound", specialProperty: "Low Smoke / Low Halogen" }
    },
    {
      id: "frzh",
      code: "FRZH",
      title: "FRZH Flame Retardant Zero Halogen",
      image: "https://realswitchgears.com/assets/images/products/polycab-wire/wire/FRZH.png",
      description: "Single core multi-stranded copper conductor, FRZH insulated wire offering robust environmental safety, zero toxic emissions, and strict RoHS compliance.",
      specs: { conductor: "Multi-stranded Copper", insulation: "FRZH Halogen-Free", specialProperty: "Zero Halogen / RoHS Compliant" }
    },
    {
      id: "frlf",
      code: "FRLF",
      title: "FRLF Flame Retardant Lead Free",
      image: "https://realswitchgears.com/assets/images/products/polycab-wire/wire/FRLF.png",
      description: "Single core multi-stranded copper conductors, FRLF PVC insulated wire prioritizing toxic-free insulation safety to proudly support the ongoing green revolution.",
      specs: { conductor: "Multi-stranded Copper", insulation: "Lead-Free FR PVC", specialProperty: "100% Lead-Free Composition" }
    },
    {
      id: "hrfr",
      code: "HRFR",
      title: "HR FR-LSH Lead Free",
      image: "https://realswitchgears.com/assets/images/products/polycab-wire/wire/HRFR.png",
      description: "Polycab single core heat resistant, flame retardant, low smoke PVC insulated industrial cable. Rated for 1100V voltage grade deployments utilizing ultra-flexible conductors.",
      specs: { conductor: "High Flexibility Copper", insulation: "HR-FR PVC Compound", specialProperty: "High Thermal Resistance" }
    },
    {
      id: "frfs",
      code: "FRFS",
      title: "FRFS Flame Retardant Fire Survival",
      image: "https://realswitchgears.com/assets/images/products/polycab-wire/wire/FRFS.png",
      description: "Single core multi-stranded copper conductor wrapped in advanced fire-barrier mica tape. Ensures continuous electrical circuit integrity for up to 3 hours at 950°C during active fire hazards.",
      specs: { conductor: "Mica Tape + Copper", insulation: "Special Fire Compound", specialProperty: "3-Hour Integrity @ 950°C" }
    }
  ];

  const filteredVariants = activeTab === "all"
    ? wireVariants
    : wireVariants.filter(v => v.id === activeTab);

  return (
    <div className="min-h-screen bg-slate-50 text-slate-800 py-12 lg:py-20 selection:bg-emerald-100 selection:text-emerald-950">
      <div className="container mx-auto px-4 max-w-7xl">

        {/* ─── HERO & IMMERSIVE VIDEO MEDIA SECTION ────────────────── */}
        <div className="grid grid-cols-1 lg:grid-cols-12 gap-8 lg:gap-12 items-center mb-16">

          {/* Left Column: Context Content */}
          <div className="lg:col-span-6 space-y-6 order-2 lg:order-1">
            <div className="inline-flex items-center gap-1.5 rounded-full bg-emerald-50 border border-emerald-200 px-4 py-1.5 text-xs font-bold tracking-wider text-emerald-800 uppercase">
              Industrial Grade Core Wire Series
            </div>

            <h1 className="text-3xl md:text-4xl lg:text-5xl font-black tracking-tight text-slate-900 leading-none">
              Polycab Green Wires <br />
              <span className="text-emerald-600 text-2xl md:text-3xl font-extrabold block mt-2">
                PVC Insulated Industrial Cables
              </span>
            </h1>

            <p className="text-slate-600 text-sm md:text-base leading-relaxed font-medium">
              With the sharp rise in global warming, modern development demands wiring solutions that are genuinely eco-friendly, completely safe, and capable of high performance. By combining breakthrough engineering with meticulously selected raw materials, Polycab Green Wires conform to rigorous European norms for environmental sustainability and cable safety.
            </p>

            {/* Core Specs Snapshot Array */}
            <div className="grid grid-cols-2 gap-3 bg-white border border-slate-200 p-4 rounded-2xl shadow-xs">
              <div className="bg-slate-50 border border-slate-100 p-3 rounded-xl">
                <span className="text-[10px] text-slate-400 font-bold uppercase tracking-wider block mb-0.5">Gauge Cross Section</span>
                <span className="text-xs md:text-sm font-black text-slate-900">0.75 sq.mm to 16 sq.mm</span>
              </div>
              <div className="bg-slate-50 border border-slate-100 p-3 rounded-xl">
                <span className="text-[10px] text-slate-400 font-bold uppercase tracking-wider block mb-0.5">Voltage Capacity</span>
                <span className="text-xs md:text-sm font-black text-slate-900">1100 Volts Rated</span>
              </div>
            </div>

            {/* Explicit Actions Segment */}
            <div className="flex flex-wrap gap-4 pt-2">
              <Link
                href="#"
                className="inline-flex items-center gap-2 bg-slate-900 hover:bg-slate-800 text-white text-xs font-bold px-6 py-3.5 rounded-xl transition-all group"
              >
                <FaDownload className="w-3.5 h-3.5 group-hover:translate-y-0.5 transition-transform" /> Download Catalogue
              </Link>
              <Link
                href="/contact"
                className="inline-flex items-center gap-2 bg-emerald-600 hover:bg-emerald-700 text-white text-xs font-bold px-6 py-3.5 rounded-xl transition-all shadow-sm"
              >
                <FaEnvelope className="w-3.5 h-3.5" /> Send Enquiry
              </Link>
            </div>
          </div>

          {/* Right Column: Video Integration Framework */}
          <div className="lg:col-span-6 order-1 lg:order-2">
            <div className="relative w-full aspect-video rounded-3xl overflow-hidden bg-slate-900 border border-slate-200 shadow-md group">
              <video
                controls
                muted
                playsInline
                className="w-full h-full object-cover"
                poster="https://realswitchgears.com/assets/images/products/polycab-wire/wire/bg-1.png"
              >
                <source src="https://polycab.com/wp-content/uploads/revslider/greenvideo/Polycab-Green-30s-SUBTITLED-1-1.mov" type="video/mp4" />
                Your browser does not support the video tag.
              </video>
            </div>
          </div>
        </div>

        {/* ─── VALUE PROPOSITION MATRICES ──────────────────────────── */}
        <div className="grid grid-cols-1 md:grid-cols-3 gap-6 mb-20">
          {coreHighlights.map((item, idx) => (
            <div key={idx} className="bg-white border border-slate-200/80 rounded-2xl p-5 shadow-xs space-y-3">
              <div className="p-2.5 bg-slate-50 border border-slate-100 rounded-xl w-fit">
                {item.icon}
              </div>
              <h3 className="text-sm font-black text-slate-900">{item.title}</h3>
              <p className="text-xs text-slate-500 font-medium leading-relaxed">{item.description}</p>
            </div>
          ))}
        </div>

        {/* ─── DUAL SPLIT BRAND SHOWCASE BLOCK ────────────────────── */}
        <div className="grid grid-cols-1 lg:grid-cols-12 gap-8 items-center bg-white border border-slate-200 rounded-3xl p-6 md:p-10 shadow-sm mb-20">
          <div className="lg:col-span-5 space-y-4">
            <span className="text-[10px] bg-slate-100 border border-slate-200 text-slate-600 px-2.5 py-1 rounded-md font-bold uppercase tracking-wider">
              Material Infrastructure
            </span>
            <h2 className="text-2xl font-black text-slate-900 tracking-tight">Eco-Conscious Cable Engineering</h2>
            <p className="text-slate-500 text-xs md:text-sm font-medium leading-relaxed">
              Polycab Green Wires are energy efficient, recyclable, RoHS compliant, have low smoke density, and emit fewer toxic gases in extreme fire situations, making them the preferred choice for green buildings.
            </p>

            {/* Auxiliary Supporting Inset Asset Thumbnails */}
            <div className="flex gap-3 pt-2">
              <div className="relative w-24 h-16 rounded-xl overflow-hidden border border-slate-200 bg-slate-50">
                <Image
                  src="https://realswitchgears.com/assets/images/products/polycab-wire/wire/1.png"
                  alt="Polycab production process close-up view"
                  fill
                  className="object-cover"
                />
              </div>
              <div className="relative w-24 h-16 rounded-xl overflow-hidden border border-slate-200 bg-slate-50">
                <Image
                  src="https://realswitchgears.com/assets/images/products/polycab-wire/wire/2.png"
                  alt="Polycab inner core architecture detail view"
                  fill
                  className="object-cover"
                />
              </div>
            </div>
          </div>

          <div className="lg:col-span-7">
            <div className="relative w-full aspect-[16/10] rounded-2xl overflow-hidden bg-slate-100 border border-slate-200">
              <Image
                src="https://realswitchgears.com/assets/images/products/polycab-wire/wire/3.png"
                alt="Polycab bundled industrial insulation series overview"
                fill
                priority
                className="object-cover"
                sizes="(max-width: 1024px) 100vw, 700px"
              />
            </div>
          </div>
        </div>

        {/* ─── INSULATION VARIANTS PRODUCT FILTERS & GRID ────────── */}
        <div className="mb-20">
          <div className="flex flex-col md:flex-row md:items-end justify-between border-b border-slate-200/60 pb-5 mb-8 gap-4">
            <div className="space-y-1">
              <h2 className="text-xl font-black text-slate-900 tracking-tight">Core Insulation Portfolio</h2>
              <p className="text-xs text-slate-500 font-medium">Energy efficient wires ranges configured across specific compound safety metrics.</p>
            </div>

            {/* Filter Tabs for quick exploration */}
            <div className="flex flex-wrap gap-1.5 bg-slate-200/60 p-1 rounded-xl w-fit text-xs font-bold">
              <button
                onClick={() => setActiveTab("all")}
                className={`px-3 py-1.5 rounded-lg transition-all ${activeTab === "all" ? "bg-white text-slate-900 shadow-xs" : "text-slate-500 hover:text-slate-800"}`}
              >
                All Variants
              </button>
              {wireVariants.map(v => (
                <button
                  key={v.id}
                  onClick={() => setActiveTab(v.id)}
                  className={`px-3 py-1.5 rounded-lg uppercase tracking-wider text-[11px] transition-all ${activeTab === v.id ? "bg-white text-slate-900 shadow-xs" : "text-slate-500 hover:text-slate-800"}`}
                >
                  {v.code}
                </button>
              ))}
            </div>
          </div>

          {/* Core Dynamic Variants Display Cards */}
          <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
            {filteredVariants.map((variant) => (
              <div
                key={variant.id}
                className="bg-white border border-slate-200 rounded-2xl p-5 flex flex-col justify-between shadow-xs transition-all hover:border-slate-300 group"
              >
                <div className="space-y-4">
                  {/* Next.js Optimized Card Media */}
                  <div className="relative w-full aspect-[16/10] rounded-xl overflow-hidden border border-slate-100 bg-slate-50">
                    <Image
                      src={variant.image}
                      alt={variant.title}
                      fill
                      className="object-cover group-hover:scale-102 transition-transform duration-500"
                      sizes="(max-width: 768px) 100vw, 380px"
                    />
                  </div>

                  <div className="space-y-1">
                    <div className="flex items-center gap-2">
                      <span className="text-[9px] font-extrabold px-1.5 py-0.5 rounded bg-amber-50 border border-amber-200 text-amber-800 uppercase tracking-wide">
                        {variant.code}
                      </span>
                    </div>
                    <h3 className="text-sm font-black text-slate-900 group-hover:text-emerald-600 transition-colors">
                      {variant.title}
                    </h3>
                    <p className="text-xs text-slate-500 font-medium leading-relaxed">
                      {variant.description}
                    </p>
                  </div>
                </div>

                {/* Micro Technical Properties Spec Table */}
                <div className="mt-5 pt-4 border-t border-slate-100 space-y-1.5 text-[11px]">
                  <div className="flex justify-between font-medium">
                    <span className="text-slate-400">Insulation:</span>
                    <span className="text-slate-700 font-semibold">{variant.specs.insulation}</span>
                  </div>
                  <div className="flex justify-between font-medium">
                    <span className="text-slate-400">Key Property:</span>
                    <span className="text-emerald-600 font-bold">{variant.specs.specialProperty}</span>
                  </div>
                </div>
              </div>
            ))}
          </div>
        </div>

        {/* ─── DYNAMIC CRITICAL SECURITY CALLOUT ──────────────────── */}
        <div className="bg-gradient-to-br from-slate-900 to-slate-800 text-white rounded-3xl p-6 md:p-10 shadow-xl mb-16 relative overflow-hidden">
          <div className="absolute right-0 top-0 h-full w-1/3 opacity-5 pointer-events-none hidden lg:block">
            <FaBoltLightning className="w-full h-full text-white" />
          </div>
          <div className="max-w-3xl space-y-3 relative z-10">
            <div className="inline-flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-amber-400">
              <LuActivity className="w-4 h-4 animate-pulse" /> Engineered Circuit Resilience
            </div>
            <h3 className="text-xl md:text-2xl font-black tracking-tight">
              FRFS Circuit Integrity Under Fire Conditions
            </h3>
            <p className="text-slate-300 text-xs md:text-sm leading-relaxed font-medium">
              Equipped with high-purity mica tape insulation matrices, our Flame Retardant Fire Survival (FRFS) industrial grade wires provide unyielding continuous line stability for 3 hours at 950°C. This ensures emergency backup panels, ventilation networks, and alarm grids stay online when safety demands it most.
            </p>
          </div>
        </div>

        {/* ─── CENTRALIZED DISTRIBUTION CALL TO ACTION ───────────── */}
        <div className="bg-white border border-slate-200 rounded-3xl p-6 md:p-12 text-center max-w-4xl mx-auto shadow-xs">
          <h3 className="text-xl md:text-2xl font-black text-slate-900 mb-2">
            Procure Polycab Heavy Duty Wiring Systems
          </h3>
          <p className="text-slate-500 text-xs md:text-sm max-w-xl mx-auto mb-6 font-medium">
            Connect with our logistics and supply desk to download itemized line specifications, request physical core samples, or calculate immediate wholesale freight quotes.
          </p>
          <div className="flex flex-col sm:flex-row justify-center items-center gap-3">
            <Link
              href="#"
              className="inline-flex items-center gap-2 bg-slate-100 hover:bg-slate-200 text-slate-900 text-xs font-bold px-6 py-3.5 rounded-xl transition-all w-full sm:w-auto justify-center border border-slate-200"
            >
              <FaDownload className="w-3.5 h-3.5" /> Download Cable Catalog
            </Link>
            <Link
              href="/contact"
              className="inline-flex items-center gap-2 bg-emerald-600 hover:bg-emerald-700 text-white text-xs font-bold px-6 py-3.5 rounded-xl transition-all duration-200 active:scale-98 shadow-md shadow-emerald-600/10 w-full sm:w-auto justify-center"
            >
              Submit Commercial Inquiry
              <FaChevronRight className="w-3 h-3" />
            </Link>
          </div>
        </div>

      </div >
    </div >
  );
}