"use client";

import React, { useState } from "react";
import Image from "next/image";
import Link from "next/link";
import { FaDownload, FaEnvelope, FaChevronRight, FaArrowRight } from "react-icons/fa6";
import {
  LuLayers,
  LuThermometer,
  LuFlame,
  LuActivity,
  LuShieldAlert,
  LuInfo,
} from "react-icons/lu";
import Breadcrumb from "@/components/Common/Breadcrumb";

interface CableLayer {
  id: string;
  name: string;
  materialSpec: string;
  benefit: string;
}

export default function PolycabIceaCableDetail() {
  const [activeLayerId, setActiveLayerId] = useState<string>("layer-1");

  const coreSpecs = [
    { label: "Standard Metric", val: "ICEA S-93-639", desc: "MV Power Cable Compliance" },
    { label: "Voltage Range", val: "5 kV to 36 kV", desc: "High Tension Adaptability" },
    { label: "Insulation Core", val: "EPR Thermoset (105°C)", desc: "Elevated Thermal Endurance" },
    { label: "Fire Profile", val: "Halogen Free FR", desc: "Low-Smoke Acid Safety" }
  ];

  const layerData: CableLayer[] = [
    {
      id: "layer-1",
      name: "01. Core Conductor",
      materialSpec: "High conductivity annealed plain stranded compacted aluminium / copper",
      benefit: "Produced in-house using state-of-the-art machinery to guarantee maximum electrical conductance and absolute geometric uniformity."
    },
    {
      id: "layer-2",
      name: "02. Conductor Screen",
      materialSpec: "Extruded layer of cross-linkable semi-conducting compound",
      benefit: "Eliminates sharp structural points on the conductor surface and nullifies the chance of electrical discharge at the conductor-insulation interface."
    },
    {
      id: "layer-3",
      name: "03. Primary Insulation",
      materialSpec: "In-house developed high insulation resistance Ethylene Propylene Rubber (EPR)",
      benefit: "Engineered for superior thermal endurance up to 105°C. High-performance XLPE insulation is also available on demand."
    },
    {
      id: "layer-4",
      name: "04. Non-Metallic Insulation Screen",
      materialSpec: "Extruded layer of cross-linkable semi-conducting compound",
      benefit: "Applied in a simultaneous triple-extrusion process alongside the conductor screen and insulation to completely eliminate micro-voids, maximizing cable life."
    },
    {
      id: "layer-5",
      name: "05. Metallic Shield Matrix",
      materialSpec: "Helically applied copper tape screen",
      benefit: "Provides an efficient low-resistance path to carry fault currents safely. Corrugated or round wire copper screening is optional."
    },
    {
      id: "layer-6",
      name: "06. Laying Up & Core Fillers",
      materialSpec: "Laid up together with in-house developed fillers",
      benefit: "For 3-core variants, insulated elements are nested with specialized fillers to preserve perfect circularity. Includes an optional ground wire for earthing."
    },
    {
      id: "layer-7",
      name: "07. Structural Binding Tape",
      materialSpec: "High-tensile wrapping tape",
      benefit: "Helically applied over the 3-core laid-up element assembly to lock the bundle securely before final sheathing phases."
    },
    {
      id: "layer-8",
      name: "08. Mechanical Armor (Optional)",
      materialSpec: "Heavy-duty protective metallic armoring layer",
      benefit: "Furnishes robust physical impact defense and serves concurrently as a reliable return path for ground earth fault currents."
    },
    {
      id: "layer-9",
      name: "09. Outer Protect Sheath",
      materialSpec: "In-house developed thermoplastic compound",
      benefit: "Formulated to resist heavy mechanical friction and climate hazards while ensuring exceptionally low emissions of toxic smoke and corrosive gases during fire exposure."
    }
  ];

  // FIXED: Explicit lookup fallback defaults to the first single object rather than the array
  const activeLayer = (layerData.find((l) => l.id === activeLayerId) || layerData) as CableLayer;
  return (
    <>
      <Breadcrumb pageName="Polycab ICEA S-93-639 MV HT Cables" />

      {/* Main Container: Absolute clean white background */}
      <div className="min-h-screen bg-white text-slate-800 py-12 lg:py-16 selection:bg-cyan-500 selection:text-white">
        <div className="container mx-auto px-4 max-w-7xl xl:max-w-[1300px] space-y-12 lg:space-y-16">

          {/* ─── SECTION 1: HERO DISPLAY (CYAN ACCENT & WHITE BG) ─── */}
          <div className="bg-white rounded-2xl border border-cyan-100 shadow-sm overflow-hidden">
            <div className="grid grid-cols-1 lg:grid-cols-12">

              {/* Product Visual Frame */}
              <div className="lg:col-span-5 bg-cyan-50/30 p-8 lg:p-12 flex flex-col justify-between border-b lg:border-b-0 lg:border-r border-cyan-100/70 relative min-h-[380px]">
                <div>
                  <span className="text-cyan-600 text-[11px] font-bold tracking-widest uppercase bg-cyan-50 px-3 py-1.5 rounded-md border border-cyan-200/60">
                    High Temperature Series
                  </span>
                </div>

                <div className="relative w-full aspect-square max-w-[280px] md:max-w-[320px] mx-auto my-auto mix-blend-multiply">
                  <Image
                    src="/images/polycab/MV-Power-Cable-ICEA.png"
                    alt="Polycab ICEA S-93-639 medium voltage high tension power cable"
                    fill
                    priority
                    className="object-contain"
                    sizes="(max-width: 768px) 100vw, 400px"
                  />
                </div>

                <div className="pt-4 border-t border-cyan-100 flex items-center justify-between text-[11px] font-mono text-cyan-700/70">
                  <span>MODEL: POLYCAB-MV-HT</span>
                  <span>STANDARD: ICEA S-93-639</span>
                </div>
              </div>

              {/* Core Context Block */}
              <div className="lg:col-span-7 p-8 md:p-12 flex flex-col justify-between space-y-8 bg-white">
                <div className="space-y-4">
                  <h1 className="text-2xl md:text-3xl lg:text-4xl font-extrabold text-slate-900 tracking-tight leading-tight">
                    Polycab ICEA S-93-639 <br />
                    <span className="text-cyan-500">Medium Voltage Power Cables</span>
                  </h1>

                  <p className="text-slate-600 text-sm md:text-base leading-relaxed">
                    Polycab Medium Voltage High Tension (MV HT) power cables are precision engineered to meet the stringent benchmarks of the <strong className="text-slate-900 font-semibold">ICEA S-93-639 standard</strong>, covering diverse distribution networks graded from <strong className="text-slate-900 font-semibold">5 kV up to 36 kV</strong>.
                  </p>
                  <p className="text-slate-600 text-sm md:text-base leading-relaxed">
                    Built for deep environmental endurance, these distribution runs are highly versatile—ideal for installation inside structural conduits, open trays, routing troughs, cable ducts, or via <strong className="text-slate-900 font-semibold">direct burial across both wet and dry conditions</strong>.
                  </p>
                  <p className="text-slate-600 text-sm md:text-base leading-relaxed">
                    Equipped with premium <strong className="text-slate-900 font-semibold">Ethylene Propylene Rubber (EPR) thermoset insulation</strong> as standard, they operate comfortably under continuous thermal loads hitting <strong className="text-slate-900 font-semibold">105°C</strong>.
                  </p>
                </div>

                <div className="flex flex-wrap gap-3 pt-2">
                  <Link
                    href="https://realswitchgears.com/assets/images/products/polycab-cable/mv-power-cable/pdf/MV-Power-Cable-ICEA.pdf"
                    target="_blank"
                    className="inline-flex items-center gap-2 bg-cyan-500 hover:bg-cyan-600 text-white text-xs md:text-sm font-semibold px-5 py-3 rounded-xl transition-all shadow-md shadow-cyan-500/10"
                  >
                    <FaDownload className="w-3.5 h-3.5" /> Technical Catalog
                  </Link>
                  <Link
                    href="/contact"
                    className="inline-flex items-center gap-2 bg-white hover:bg-cyan-50 text-cyan-600 text-xs md:text-sm font-semibold px-5 py-3 rounded-xl transition-all border border-cyan-200 shadow-sm"
                  >
                    Send Specs Enquiry <FaEnvelope className="w-3.5 h-3.5 text-cyan-400" />
                  </Link>
                </div>
              </div>

            </div>
          </div>

          {/* ─── SECTION 2: GRIDDED METRICS COMPACT DISPLAY ─────── */}
          <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
            {coreSpecs.map((spec, idx) => (
              <div key={idx} className="bg-white border border-cyan-100 p-5 rounded-xl shadow-sm hover:border-cyan-300 transition-colors">
                <span className="text-[10px] text-cyan-600 font-bold uppercase tracking-wider block mb-1">
                  {spec.label}
                </span>
                <span className="text-base font-bold text-slate-900 block tracking-tight">
                  {spec.val}
                </span>
                <span className="text-xs text-slate-500 mt-0.5 block">
                  {spec.desc}
                </span>
              </div>
            ))}
          </div>

          {/* ─── SECTION 3: IMMERSIVE LIGHT EXPLORER LAYOUT ── */}
          <div className="bg-white rounded-2xl border border-cyan-100 shadow-sm p-6 md:p-8">

            <div className="flex flex-col md:flex-row md:items-center justify-between gap-4 mb-8 pb-5 border-b border-cyan-100">
              <div className="flex items-center gap-3.5">
                <div className="p-2.5 bg-cyan-50 text-cyan-600 rounded-xl border border-cyan-100">
                  <LuLayers className="w-5 h-5" />
                </div>
                <div>
                  <h2 className="text-lg md:text-xl font-bold text-slate-900">Cross-Sectional Material Profile</h2>
                  <p className="text-xs text-slate-500 mt-0.5">
                    Interactive engineering breakdown of the cable&apos;s 9 key protective and structural layers.
                  </p>
                </div>
              </div>
            </div>

            <div className="grid grid-cols-1 lg:grid-cols-12 gap-6 items-start">
              {/* Left Column Selectors */}
              <div className="lg:col-span-4 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-1 gap-1.5">
                {layerData.map((layer) => (
                  <button
                    key={layer.id}
                    onClick={() => setActiveLayerId(layer.id)}
                    className={`w-full text-left px-4 py-3 rounded-lg border text-xs font-semibold transition-all flex items-center justify-between ${activeLayerId === layer.id
                      ? "bg-cyan-50 text-cyan-700 border-cyan-300 font-bold shadow-sm"
                      : "bg-white text-slate-600 border-transparent hover:bg-cyan-50/50 hover:text-cyan-600"
                      }`}
                  >
                    <span className="truncate">{layer.name}</span>
                    <FaChevronRight className={`w-2.5 h-2.5 transition-transform ${activeLayerId === layer.id ? "text-cyan-600 translate-x-0.5" : "text-slate-300"
                      }`} />
                  </button>
                ))}
              </div>

              {/* Right Column Canvas Area */}
              <div className="lg:col-span-8 bg-cyan-50/20 border border-cyan-100 rounded-xl p-6 md:p-8 min-h-[300px] flex flex-col justify-between relative">
                <div className="space-y-5">
                  <div className="space-y-1">
                    <span className="text-[10px] font-mono font-bold tracking-widest text-cyan-600 uppercase block">
                      Active Layer Specification
                    </span>
                    <h3 className="text-xl font-extrabold text-slate-900 tracking-tight">
                      {activeLayer.name.substring(4)}
                    </h3>
                  </div>

                  <div className="p-4 bg-white rounded-lg border border-cyan-100 space-y-1 shadow-xs">
                    <span className="text-[10px] font-bold text-cyan-600 block uppercase tracking-wider">
                      Composition & Compound:
                    </span>
                    <p className="text-xs md:text-sm font-medium text-slate-800 leading-relaxed">
                      {activeLayer.materialSpec}
                    </p>
                  </div>

                  <div className="space-y-1">
                    <span className="text-[10px] font-bold text-slate-400 block uppercase tracking-wider">
                      Performance & Operational Benefit:
                    </span>
                    <p className="text-xs md:text-sm text-slate-600 leading-relaxed font-medium">
                      {activeLayer.benefit}
                    </p>
                  </div>
                </div>

                <div className="mt-6 pt-4 border-t border-cyan-100 flex flex-wrap gap-4 items-center justify-between text-[10px] font-mono text-slate-400">
                  <span className="flex items-center gap-1.5 text-cyan-600 font-semibold">
                    <LuInfo className="w-3.5 h-3.5" /> High-Purity Compounding Matrix
                  </span>
                  <span className="text-cyan-600/70">ICEA S-93-639 COMPLIANT</span>
                </div>
              </div>
            </div>

          </div>

          {/* ─── SECTION 4: PRODUCT HIGHLIGHT CARDS ─── */}
          <div className="grid grid-cols-1 md:grid-cols-3 gap-6">
            <div className="bg-white border border-cyan-100 rounded-xl p-5 shadow-sm flex gap-4 items-start hover:border-cyan-300 transition-colors">
              <div className="p-2 bg-cyan-50 text-cyan-500 rounded-lg shrink-0 border border-cyan-100">
                <LuThermometer className="w-5 h-5" />
              </div>
              <div className="space-y-1">
                <h4 className="text-sm font-bold text-slate-900">105°C Continuous Thermals</h4>
                <p className="text-xs text-slate-500 leading-relaxed">
                  Premium EPR thermoset insulation handles elevated high-load distribution runs comfortably over standard 90°C compounds.
                </p>
              </div>
            </div>

            <div className="bg-white border border-cyan-100 rounded-xl p-5 shadow-sm flex gap-4 items-start hover:border-cyan-300 transition-colors">
              <div className="p-2 bg-cyan-50 text-cyan-500 rounded-lg shrink-0 border border-cyan-100">
                <LuFlame className="w-5 h-5" />
              </div>
              <div className="space-y-1">
                <h4 className="text-sm font-bold text-slate-900">Low Smoke & Acid Safety</h4>
                <p className="text-xs text-slate-500 leading-relaxed">
                  Advanced thermoplastic outers restrict harmful emissions and corrosive gas output if exposed to severe fires.
                </p>
              </div>
            </div>

            <div className="bg-white border border-cyan-100 rounded-xl p-5 shadow-sm flex gap-4 items-start hover:border-cyan-300 transition-colors">
              <div className="p-2 bg-cyan-50 text-cyan-500 rounded-lg shrink-0 border border-cyan-100">
                <LuActivity className="w-5 h-5" />
              </div>
              <div className="space-y-1">
                <h4 className="text-sm font-bold text-slate-900">Dual Submersion Endurance</h4>
                <p className="text-xs text-slate-500 leading-relaxed">
                  Extruded materials provide long life cycles and protect circuits reliably within both wet and dry installations.
                </p>
              </div>
            </div>
          </div>

          {/* ─── SECTION 5: CLEAN OUTRO / CTA BLOCK ───────── */}

          <div className="flex flex-col sm:flex-row justify-center items-center gap-4 w-full">
            <Link
              href="https://realswitchgears.com/assets/images/products/polycab-cable/lv-power-cable/pdf/LV-Power-Cable-IS-1.pdf"
              target="_blank"
              className="inline-flex items-center justify-center gap-2 bg-slate-100 hover:bg-slate-200 text-slate-900 text-xs font-bold px-8 py-4 rounded-full transition-all w-full sm:w-auto uppercase tracking-wider border border-slate-200 shadow-xs"
            >
              <FaDownload className="w-3.5 h-3.5" />
              View Technical PDF
            </Link>

            <Link
              href="/contact"
              className="inline-flex items-center justify-center gap-2 bg-cyan-500 hover:bg-cyan-600 text-white text-xs xl:text-sm font-bold px-8 sm:px-10 py-4 rounded-full transition-all duration-200 active:scale-95 shadow-md shadow-cyan-500/10 w-full sm:w-auto uppercase tracking-wider"
            >
              Send Enquiry
              <FaArrowRight className="w-3.5 h-3.5 transition-transform group-hover:translate-x-0.5" />
            </Link>
          </div>
        </div>
      </div>
    </>
  );
}