"use client";

import React, { useState } from "react";
import Link from "next/link";
import { ProductData, CorridorDataParsed } from "@/lib/types";
import { RFQModal } from "../RFQModal";
import { ShieldCheck, Award, CheckCircle2, ChevronRight, Gauge, Wrench, FileCheck, Layers, Hammer, ShieldAlert } from "lucide-react";

interface Props {
  product: ProductData;
  corridors: CorridorDataParsed[];
  corridor?: CorridorDataParsed;
}

export function MiningPolyurethaneTemplate({ product, corridors, corridor }: Props) {
  const [isRfqOpen, setIsRfqOpen] = useState(false);
  const [selectedHardness, setSelectedHardness] = useState("95 Shore A (Heavy Load Wheels & Rollers)");

  const puGrades: Record<string, { dinAbrasion: string; tearStrength: string; loadPerWheel: string; recommendedUse: string }> = {
    "70 Shore A (Resilient Scrapers & Liners)": {
      dinAbrasion: "22 mm³ loss (5x better than Natural Rubber)",
      tearStrength: "65 kN/m (ASTM D624 Die C)",
      loadPerWheel: "850 kg @ 10 km/h",
      recommendedUse: "Conveyor belt secondary scrapers, chute impact beds, hydrocyclone liners",
    },
    "85 Shore A (Mining Screens & Couplers)": {
      dinAbrasion: "18 mm³ loss (7x better than Steel)",
      tearStrength: "85 kN/m (ASTM D624 Die C)",
      loadPerWheel: "2,200 kg @ 10 km/h",
      recommendedUse: "Vibrating mining screen panels, flexible drive couplers, railway buffer pads",
    },
    "95 Shore A (Heavy Load Wheels & Rollers)": {
      dinAbrasion: "14 mm³ loss (Ultra-Wear Resistant)",
      tearStrength: "110 kN/m (ASTM D624 Die C)",
      loadPerWheel: "5,500 kg @ 10 km/h",
      recommendedUse: "Heavy duty AGV wheels, polyurethane fork-lift tires, pipeline cleaning pigs",
    },
    "75 Shore D (Extreme Impact Bushings)": {
      dinAbrasion: "11 mm³ loss (Sub-Steel Wear)",
      tearStrength: "145 kN/m (ASTM D624 Die C)",
      loadPerWheel: "12,000 kg (Static Bolster)",
      recommendedUse: "Suspension pivot bushings, structural rail isolators, high-pressure piston seals",
    },
  };

  const imageSrc = product.image ? (product.image.startsWith("http") ? product.image : `/uploaded_files/${product.image}`) : "/uploaded_files/4484f5fa686d05.jpg";

  return (
    <div className="bg-[#121316] text-amber-50 min-h-screen selection:bg-amber-400 selection:text-black">
      {/* 1. Heavy Industrial & Mining Polyurethane Hero */}
      <section className="relative overflow-hidden py-16 lg:py-24 border-b border-amber-900/40 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-amber-950/30 via-[#121316] to-[#0a0a0c]">
        {/* Caution stripe motif */}
        <div className="absolute top-0 left-0 right-0 h-1.5 bg-[repeating-linear-gradient(45deg,#f59e0b,#f59e0b_15px,#000_15px,#000_30px)]"></div>

        <div className="max-w-7xl mx-auto px-4 relative z-10 pt-4">
          <div className="flex items-center gap-2 text-xs font-mono font-bold text-amber-400 uppercase tracking-widest mb-3">
            <Hammer className="w-4 h-4 text-amber-400" />
            <span>Heavy Mining, Railway, Slurry Pipelines & Cast Polyurethane Division</span>
          </div>

          <div className="grid grid-cols-1 lg:grid-cols-12 gap-8 items-center">
            <div className="lg:col-span-8 space-y-4">
              <h1 className="text-3xl sm:text-5xl font-black tracking-tight text-white leading-tight font-sans">
                {product.name} {corridor ? `• Exporting to ${corridor.countryName}` : ""}
              </h1>
              <p className="text-sm sm:text-base text-zinc-300 max-w-2xl leading-relaxed">
                {product.shortDescription}
              </p>

              {/* Heavy Duty Metric Badges */}
              <div className="flex flex-wrap gap-2.5 pt-2 font-mono text-xs">
                <span className="px-3 py-1.5 rounded-lg bg-amber-950/80 border border-amber-500/50 text-amber-300 font-bold">
                  Abrasion Loss: DIN 53516 &lt; 15 mm³
                </span>
                <span className="px-3 py-1.5 rounded-lg bg-zinc-900 border border-zinc-700 text-zinc-200 font-bold">
                  Hardness Range: 60 Shore A to 75 Shore D
                </span>
                <span className="px-3 py-1.5 rounded-lg bg-yellow-950/60 border border-yellow-500/40 text-yellow-300 font-bold">
                  Polymer Type: Hot-Cast MDI / TDI Prepolymer
                </span>
              </div>

              <div className="pt-4 flex flex-wrap gap-4">
                <button
                  onClick={() => setIsRfqOpen(true)}
                  className="px-7 py-3.5 rounded-xl bg-amber-500 hover:bg-amber-400 text-black font-black text-sm shadow-xl shadow-amber-950/60 transition-all flex items-center gap-2"
                >
                  <ShieldAlert className="w-4 h-4 text-black" />
                  Request Polyurethane Quotation
                </button>
                <Link
                  href="#abrasion-benchmark"
                  title="Navigate to Polyurethane Abrasion Benchmark"
                  className="px-6 py-3.5 rounded-xl border border-zinc-700 hover:border-amber-400 bg-zinc-900/80 text-zinc-200 hover:text-white font-semibold text-sm transition-all"
                >
                  DIN 53516 Abrasion Benchmarker &darr;
                </Link>
              </div>
            </div>

            <div className="lg:col-span-4">
              <div className="relative rounded-2xl bg-zinc-900/90 border-2 border-amber-500/40 p-4 shadow-2xl backdrop-blur-xl">
                <div className="aspect-[4/3] rounded-xl overflow-hidden bg-black/50 flex items-center justify-center relative">
                  {/* eslint-disable-next-line @next/next/no-img-element */}
                  <img
                    src={imageSrc}
                    alt={product.name}
                    className="w-full h-full object-contain p-4 transition-transform duration-500 hover:scale-105"
                  />
                  <div className="absolute top-3 left-3 px-2 py-1 rounded bg-amber-500 text-black font-mono text-[10px] font-black">
                    HS: {product.hsCode}
                  </div>
                </div>

                <div className="mt-4 pt-3 border-t border-zinc-800 grid grid-cols-2 gap-2 text-xs">
                  <div>
                    <span className="text-zinc-500 block text-[10px] uppercase font-mono">Tear Resistance</span>
                    <span className="font-bold text-amber-400">&gt; 85 kN/m</span>
                  </div>
                  <div>
                    <span className="text-zinc-500 block text-[10px] uppercase font-mono">Continuous Temp</span>
                    <span className="font-bold text-zinc-200">{product.operatingTemp}</span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>

      {/* 2. Interactive DIN 53516 Abrasion Benchmarker */}
      <section id="abrasion-benchmark" className="py-16 bg-[#16181d] border-b border-zinc-800">
        <div className="max-w-7xl mx-auto px-4">
          <div className="max-w-3xl mb-8">
            <span className="text-xs font-mono font-bold text-amber-400 uppercase tracking-wider block mb-1">
              Industrial Tribology & Wear Benchmarking
            </span>
            <h2 className="text-2xl sm:text-3xl font-extrabold text-white">
              DIN 53516 Abrasion Volume Loss vs Shore Hardness
            </h2>
            <p className="text-sm text-zinc-400 mt-2">
              Compare Horiaki hot-cast polyurethane formulation grades to select the optimal balance between high elongation and severe sliding abrasion resistance.
            </p>
          </div>

          <div className="grid grid-cols-1 lg:grid-cols-12 gap-8 items-start">
            <div className="lg:col-span-5 space-y-3">
              <label className="text-xs font-mono uppercase text-zinc-400 block font-semibold">
                Select Polyurethane Durometer Grade:
              </label>
              {Object.keys(puGrades).map((gradeKey) => (
                <button
                  key={gradeKey}
                  onClick={() => setSelectedHardness(gradeKey)}
                  className={`w-full text-left p-4 rounded-xl border transition-all flex items-center justify-between ${
                    selectedHardness === gradeKey
                      ? "bg-amber-950/60 border-amber-400 text-white shadow-lg shadow-amber-950/40"
                      : "bg-zinc-900/60 border-zinc-800 text-zinc-400 hover:border-zinc-700 hover:text-zinc-200"
                  }`}
                >
                  <span className="font-bold text-sm">{gradeKey}</span>
                  <ChevronRight className={`w-4 h-4 ${selectedHardness === gradeKey ? "text-amber-400" : "text-zinc-600"}`} />
                </button>
              ))}
            </div>

            <div className="lg:col-span-7">
              <div className="rounded-2xl bg-zinc-950 border border-zinc-800 p-6 shadow-xl relative overflow-hidden">
                <div className="absolute top-0 right-0 px-4 py-1.5 bg-amber-500/20 border-b border-l border-amber-400/40 text-amber-300 font-mono text-[11px] font-bold rounded-bl-xl">
                  Grade: {selectedHardness.split(" ")[0]} {selectedHardness.split(" ")[1]}
                </div>

                <h3 className="text-lg font-bold text-white mb-6 flex items-center gap-2">
                  <Gauge className="w-5 h-5 text-amber-400" />
                  Wear Life & Mechanical Load Capability
                </h3>

                <div className="grid grid-cols-1 sm:grid-cols-2 gap-4 mb-6">
                  <div className="p-4 rounded-xl bg-zinc-900 border border-zinc-800">
                    <span className="text-[11px] font-mono uppercase text-zinc-400 block">DIN 53516 Volume Loss</span>
                    <span className="text-lg font-mono font-black text-amber-400">
                      {puGrades[selectedHardness].dinAbrasion}
                    </span>
                    <p className="text-[11px] text-zinc-500 mt-1">Lower mm³ equals longer service lifetime</p>
                  </div>

                  <div className="p-4 rounded-xl bg-zinc-900 border border-zinc-800">
                    <span className="text-[11px] font-mono uppercase text-zinc-400 block">Tear Strength (Die C)</span>
                    <span className="text-lg font-mono font-black text-white">
                      {puGrades[selectedHardness].tearStrength}
                    </span>
                    <p className="text-[11px] text-zinc-500 mt-1">Resists gouging from sharp quartz or iron ore</p>
                  </div>

                  <div className="p-4 rounded-xl bg-zinc-900 border border-zinc-800">
                    <span className="text-[11px] font-mono uppercase text-zinc-400 block">Rated Dynamic Load</span>
                    <span className="text-lg font-mono font-black text-yellow-400">
                      {puGrades[selectedHardness].loadPerWheel}
                    </span>
                    <p className="text-[11px] text-zinc-500 mt-1">No flat-spotting under static parking loads</p>
                  </div>

                  <div className="p-4 rounded-xl bg-zinc-900 border border-zinc-800">
                    <span className="text-[11px] font-mono uppercase text-zinc-400 block">Primary Industrial Application</span>
                    <span className="text-xs font-semibold text-zinc-200">
                      {puGrades[selectedHardness].recommendedUse}
                    </span>
                  </div>
                </div>

                <div className="p-3.5 rounded-xl bg-amber-950/40 border border-amber-600/30 text-xs text-amber-200/90 flex items-start gap-2.5">
                  <ShieldCheck className="w-4 h-4 text-amber-400 shrink-0 mt-0.5" />
                  <span>
                    <strong>Polyether vs. Polyester Compounding:</strong> Polyether grades provide zero hydrolysis degradation in wet slurry or deep mine water; Polyester grades deliver maximum tensile resistance in dry oil/hydrocarbon environments.
                  </span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>

      {/* 3. Cast Molded Capabilities */}
      <section className="py-16 bg-[#121316] border-b border-zinc-800">
        <div className="max-w-7xl mx-auto px-4">
          <div className="text-center max-w-3xl mx-auto mb-12">
            <span className="text-xs font-mono font-bold text-amber-400 uppercase tracking-widest block mb-2">
              Custom Polyurethane Manufacturing
            </span>
            <h2 className="text-2xl sm:text-4xl font-extrabold text-white">
              Centrifugal, Vacuum & Open Cast Polyurethane
            </h2>
            <p className="text-sm text-zinc-400 mt-2">
              From heavy pipeline pigs to 500 mm diameter drive rollers with CNC-machined steel cores.
            </p>
          </div>

          <div className="grid grid-cols-1 md:grid-cols-4 gap-6">
            {[
              {
                title: "Steel Core Bonding",
                desc: "Surface degreasing, abrasive grit blasting, and Chemlok adhesive bonding achieving 100% elastomer tear before bond failure.",
                metric: "ASTM D429 > 14 MPa",
              },
              {
                title: "High-Volume Rollers",
                desc: "Precision CNC cylindrical grinding to ± 0.05 mm concentricity for conveyor pull rollers and laminating machines.",
                metric: "Concentricity: ±0.05mm",
              },
              {
                title: "Hydrocyclone Liners",
                desc: "Severe duty slurry liners outlasting Ni-Hard iron and white chrome cast iron by up to 400% in gold/copper beneficiation.",
                metric: "Life: 4x Ni-Hard",
              },
              {
                title: "Pipeline Cleaning Pigs",
                desc: "Bi-directional discs, cup pigs, and scraper pigs for crude oil and multi-product hydrocarbon pipeline de-watering.",
                metric: "Pipeline: 2\" to 48\"",
              },
            ].map((card, idx) => (
              <div key={idx} className="rounded-2xl bg-zinc-900/60 border border-zinc-800 p-5 space-y-3">
                <span className="px-2.5 py-1 rounded bg-amber-500/20 text-amber-400 font-mono text-[11px] font-bold">
                  {card.metric}
                </span>
                <h3 className="text-base font-bold text-white">{card.title}</h3>
                <p className="text-xs text-zinc-400 leading-relaxed">{card.desc}</p>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* 4. Specifications Table */}
      <section className="py-16 bg-[#16181d] border-b border-zinc-800">
        <div className="max-w-7xl mx-auto px-4">
          <div className="grid grid-cols-1 lg:grid-cols-12 gap-8 items-start">
            <div className="lg:col-span-7">
              <h2 className="text-2xl font-black text-white mb-6 flex items-center gap-2">
                <Layers className="w-5 h-5 text-amber-400" />
                Physical & Mechanical Property Matrix
              </h2>

              <div className="overflow-hidden rounded-xl border border-zinc-800">
                <table className="w-full text-xs text-left">
                  <thead className="bg-zinc-900 text-zinc-400 uppercase font-mono">
                    <tr>
                      <th className="p-3">Mechanical Parameter</th>
                      <th className="p-3">Horiaki Certified Values</th>
                    </tr>
                  </thead>
                  <tbody className="divide-y divide-zinc-800 text-zinc-300 font-mono">
                    <tr>
                      <td className="p-3 text-zinc-400">Polymer Base</td>
                      <td className="p-3 font-semibold text-white">Cast Polyurethane (MDI / TDI Ether or Ester)</td>
                    </tr>
                    <tr>
                      <td className="p-3 text-zinc-400">Hardness Shore Range</td>
                      <td className="p-3 font-semibold text-white">{product.hardnessShore}</td>
                    </tr>
                    <tr>
                      <td className="p-3 text-zinc-400">Operating Temperature</td>
                      <td className="p-3 font-semibold text-white">{product.operatingTemp}</td>
                    </tr>
                    <tr>
                      <td className="p-3 text-zinc-400">Rebound Resilience (DIN 53512)</td>
                      <td className="p-3 font-semibold text-white">45% to 65% (Grade dependent)</td>
                    </tr>
                    <tr>
                      <td className="p-3 text-zinc-400">Elongation at Break (ASTM D412)</td>
                      <td className="p-3 font-semibold text-white">400% to 650%</td>
                    </tr>
                    <tr>
                      <td className="p-3 text-zinc-400">Compression Set (22h @ 70°C)</td>
                      <td className="p-3 font-semibold text-white">&lt; 25% (ASTM D395 Method B)</td>
                    </tr>
                    {Object.entries(product.specs || {}).map(([key, val]) => (
                      <tr key={key}>
                        <td className="p-3 text-zinc-400 capitalize">{key.replace(/([A-Z])/g, " $1")}</td>
                        <td className="p-3 font-semibold text-white">{String(val)}</td>
                      </tr>
                    ))}
                  </tbody>
                </table>
              </div>
            </div>

            <div className="lg:col-span-5 space-y-4">
              <h2 className="text-xl font-black text-white flex items-center gap-2">
                <Award className="w-5 h-5 text-amber-400" />
                Industry Applications
              </h2>

              <div className="grid grid-cols-1 gap-2.5">
                {[
                  { title: "Mining & Mineral Beneficiation", desc: "Slurry pump impellers, flotation rotors, trommel screen panels." },
                  { title: "Railways & Rolling Stock", desc: "Draft gear pads, center pivot liners, side bearer buffers." },
                  { title: "Oil & Gas Pipeline Infrastructure", desc: "Pipeline pigs, polyurethane pig cups, roller cradles for pipe laying." },
                  { title: "Material Handling & Intralogistics", desc: "Heavy forklift wheels, AGV drive tires, conveyor belt scrapers." },
                ].map((item, idx) => (
                  <div key={idx} className="p-3.5 rounded-xl bg-zinc-900 border border-zinc-800">
                    <h3 className="text-sm font-bold text-amber-300">{item.title}</h3>
                    <p className="text-xs text-zinc-400 mt-1">{item.desc}</p>
                  </div>
                ))}
              </div>
            </div>
          </div>
        </div>
      </section>

      {/* 5. Destination Corridor Logistics */}
      {corridor && (
        <section className="py-16 bg-[#0e0f12] border-b border-zinc-800">
          <div className="max-w-7xl mx-auto px-4">
            <div className="p-8 rounded-2xl bg-gradient-to-br from-zinc-900 to-black border border-amber-950/60">
              <div className="flex flex-col md:flex-row md:items-center justify-between gap-4 mb-6">
                <div>
                  <span className="text-xs font-mono font-bold text-amber-400 uppercase">
                    Polyurethane Export Corridor: India to {corridor.countryName}
                  </span>
                  <h3 className="text-2xl font-black text-white mt-1">
                    FCL / LCL Ocean Shipments to {corridor.seaports.map((p) => p.name).join(", ")}
                  </h3>
                </div>
                <div className="text-right">
                  <span className="text-xs text-zinc-500 font-mono block">Ocean Transit from Chennai Port</span>
                  <span className="text-xl font-bold text-amber-400 font-mono">
                    {corridor.seaports[0]?.transitDays || "16-22 Days"}
                  </span>
                </div>
              </div>

              <div className="grid grid-cols-1 md:grid-cols-3 gap-4 text-xs font-mono">
                <div className="p-4 rounded-xl bg-zinc-950/80 border border-zinc-800">
                  <span className="text-zinc-500 block text-[10px] uppercase">Compliance Framework</span>
                  <span className="font-bold text-zinc-200">{corridor.complianceStandards.join(", ")}</span>
                </div>
                <div className="p-4 rounded-xl bg-zinc-950/80 border border-zinc-800">
                  <span className="text-zinc-500 block text-[10px] uppercase">Mining & Rail Hubs</span>
                  <span className="font-bold text-zinc-200">{corridor.industrialClusters.slice(0, 3).join(", ")}</span>
                </div>
                <div className="p-4 rounded-xl bg-zinc-950/80 border border-zinc-800">
                  <span className="text-zinc-500 block text-[10px] uppercase">IncoTerms & Dispatch</span>
                  <span className="font-bold text-amber-300">{corridor.b2bTerms.incoTerms.join(" / ")}</span>
                </div>
              </div>
            </div>
          </div>
        </section>
      )}

      {/* 6. Lead Generation Footer */}
      <section className="py-16 bg-gradient-to-b from-[#16181d] to-black">
        <div className="max-w-4xl mx-auto px-4 text-center space-y-6">
          <h2 className="text-3xl sm:text-4xl font-black text-white">
            Custom Polyurethane Casting for Heavy Duty Industry
          </h2>
          <p className="text-sm text-zinc-400 max-w-xl mx-auto">
            Horiaki India Private Limited designs and casts custom polyurethane parts with rapid in-house tooling, CNC metal cores, and laboratory-verified DIN 53516 wear performance.
          </p>
          <div className="flex flex-wrap justify-center gap-4 pt-2">
            <button
              onClick={() => setIsRfqOpen(true)}
              className="px-8 py-4 rounded-xl bg-amber-500 hover:bg-amber-400 text-black font-black text-sm shadow-xl shadow-amber-950 transition-all flex items-center gap-2"
            >
              <ShieldAlert className="w-4 h-4 text-black" />
              Request Custom PU Part Quotation
            </button>
            <a
              href="https://wa.me/919840023478?text=Hello%20Horiaki%20Polyurethane%20Team%2C%20I%20need%20a%20quotation%20for%20custom%20polyurethane%20products"
              target="_blank"
              rel="noopener noreferrer"
              title="Chat with Horiaki Polyurethane Team on WhatsApp"
              className="px-8 py-4 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white font-bold text-sm shadow-xl shadow-emerald-950 transition-all"
            >
              Chat on WhatsApp for Technical Drawings
            </a>
          </div>
        </div>
      </section>

      <RFQModal
        isOpen={isRfqOpen}
        onClose={() => setIsRfqOpen(false)}
        productName={product.name}
        countryName={corridor?.countryName}
      />
    </div>
  );
}
