"use client";
import React, { useState } from "react"
import sqlogoImg from '../../../../../public/assets/product-details/logo-02.png'
import detailsImg1 from '../../../../../public/assets/product-details/Certification.png'
import detailsImg2 from '../../../../../public/assets/product-details/color.png'
import detailsImg3 from '../../../../../public/assets/product-details/SQ-Electricals-logo.png'
import detailsImg4 from '../../../../../public/assets/product-details/Icon.png'
import Link from "next/link"

interface CableProduct {
  id: string
  name: string
  subtitle: string
  standards: string[]
  conductorType: string
  insulationMaterial: string
  availableColors: { name: string; hex: string }[]
  constructionCharacteristics: { label: string; value: string }[]
  dimensionalCharacteristics: { label: string; value: string }[]
  electricalCharacteristics: { label: string; value: string }[]
  mechanicalCharacteristics: { label: string; value: string }[]
  usageCharacteristics: { label: string; value: string }[]
  features: string[]
  installationConditions: string[]
}

const cableProducts: CableProduct[] = [
  {
    id: "1x0.5-re-bya",
    name: "1x0.5 re BYA Cable",
    subtitle: "100 meter Coil",
    standards: [
      "BS 6004, BDS IEC 60227-3, IEC 60332, IEC 61034 & IEC 60228",
      "✓ 1 Core Building Wire",
      "✓ 450/750V T11 PVC Insulated",
      "✓ Copper Conductor",
    ],
    conductorType: "Copper, Class 1",
    insulationMaterial: "PVC, T11",
    availableColors: [
      { name: "Red", hex: "#e02020" },
      { name: "Yellow", hex: "#f5c518" },
      { name: "Blue", hex: "#1a56d4" },
      { name: "Black", hex: "#1a1a1a" },
      { name: "Green", hex: "#1e8c3a" },
      { name: "Yellow-Green", hex: "#8db33a" },
    ],
    constructionCharacteristics: [
      { label: "Conductor flexibility", value: "Class 1" },
      { label: "Conductor material", value: "Copper" },
      { label: "Conductor shape", value: "Circular" },
      { label: "Insulation", value: "PVC (T11)" },
      { label: "Type of conductor", value: "Solid" },
    ],
    dimensionalCharacteristics: [
      { label: "Approximate weight", value: "1.0 kg/100 m" },
      { label: "Cable length", value: "100 m" },
      { label: "Conductor cross-section", value: "0.5 mm²" },
      { label: "Number & nominal diameter of wire", value: "1/0.80 no./mm" },
      { label: "Nominal insulation thickness", value: "0.6 mm" },
      { label: "Overall diameter", value: "1.9-2.3 mm" },
    ],
    electricalCharacteristics: [
      { label: "Minimum insulation resistance constant k at 20°C", value: "35 MΩ.km" },
      { label: "Maximum DC resistance of the conductor at 20°C", value: "36.0 Ω/km" },
      { label: "Rated voltage U₀/U", value: "450/750 V" },
      { label: "Current rating in conduit at 35°C", value: "8 A" },
      { label: "Current rating in air at 35°C", value: "11 A" },
    ],
    mechanicalCharacteristics: [
      { label: "Cable flexibility", value: "Rigid" },
      { label: "Minimum tensile strength", value: "12.5 N/mm²" },
      { label: "Minimum percentage elongation at break", value: "125%" },
    ],
    usageCharacteristics: [
      { label: "Minimum bending radius", value: "6 (xD)" },
    ],
    features: [
      "Operating Temperature",
      "Flame Retardant",
      "Maximum Short circuit",
      "Lead free",
      "Skin coated",
      "Rigid",
      "Resistance to Solar Radiation",
      "Test 1.5–2.5kV",
    ],
    installationConditions: ["Home Use", "Outdoor Installation", "Open air", "In conduit"],
  },
  {
    id: "1x1.5-re-bya",
    name: "1x1.5 re BYA Cable",
    subtitle: "100 meter Coil",
    standards: [
      "BS 6004, BDS IEC 60227-3, IEC 60332, IEC 61034 & IEC 60228",
      "✓ 1 Core Building Wire",
      "✓ 450/750V T11 PVC Insulated",
      "✓ Copper Conductor",
    ],
    conductorType: "Copper, Class 1",
    insulationMaterial: "PVC, T11",
    availableColors: [
      { name: "Red", hex: "#e02020" },
      { name: "Yellow", hex: "#f5c518" },
      { name: "Blue", hex: "#1a56d4" },
      { name: "Black", hex: "#1a1a1a" },
      { name: "Green", hex: "#1e8c3a" },
    ],
    constructionCharacteristics: [
      { label: "Conductor flexibility", value: "Class 1" },
      { label: "Conductor material", value: "Copper" },
      { label: "Conductor shape", value: "Circular" },
      { label: "Insulation", value: "PVC (T11)" },
      { label: "Type of conductor", value: "Solid" },
    ],
    dimensionalCharacteristics: [
      { label: "Approximate weight", value: "1.5 kg/100 m" },
      { label: "Cable length", value: "100 m" },
      { label: "Conductor cross-section", value: "1.5 mm²" },
      { label: "Number & nominal diameter of wire", value: "1/1.38 no./mm" },
      { label: "Nominal insulation thickness", value: "0.7 mm" },
      { label: "Overall diameter", value: "3.0-3.4 mm" },
    ],
    electricalCharacteristics: [
      { label: "Minimum insulation resistance constant k at 20°C", value: "35 MΩ.km" },
      { label: "Maximum DC resistance of the conductor at 20°C", value: "12.1 Ω/km" },
      { label: "Rated voltage U₀/U", value: "450/750 V" },
      { label: "Current rating in conduit at 35°C", value: "13 A" },
      { label: "Current rating in air at 35°C", value: "17 A" },
    ],
    mechanicalCharacteristics: [
      { label: "Cable flexibility", value: "Rigid" },
      { label: "Minimum tensile strength", value: "12.5 N/mm²" },
      { label: "Minimum percentage elongation at break", value: "125%" },
    ],
    usageCharacteristics: [
      { label: "Minimum bending radius", value: "6 (xD)" },
    ],
    features: [
      "Operating Temperature",
      "Flame Retardant",
      "Maximum Short circuit",
      "Lead free",
      "Skin coated",
      "Rigid",
      "Resistance to Solar Radiation",
      "Test 1.5–2.5kV",
    ],
    installationConditions: ["Home Use", "Outdoor Installation", "Open air", "In conduit"],
  },
]

function getProductById(id: string): CableProduct | undefined {
  return cableProducts.find((p) => p.id === id)
}

const PRODUCT_ID = "1x0.5-re-bya"

// 3D Interactive Model Component
function Interactive3DModel() {
  const [rotation, setRotation] = useState(0)
  const [isHovered, setIsHovered] = useState(false)

  return (
    <div className="relative">
      <div 
        className="relative w-full aspect-square max-w-[400px] mx-auto bg-gradient-to-br from-gray-100 to-gray-200 rounded-2xl overflow-hidden shadow-inner"
        onMouseEnter={() => setIsHovered(true)}
        onMouseLeave={() => setIsHovered(false)}
      >
        <div className="absolute inset-0 flex items-center justify-center">
          <svg 
            viewBox="0 0 400 400" 
            className="w-full h-full p-8 transition-transform duration-300"
            style={{ 
              transform: `rotate(${rotation}deg) scale(${isHovered ? 1.05 : 1})`,
              transition: 'transform 0.3s ease'
            }}
          >
            <ellipse cx="200" cy="200" rx="160" ry="180" fill="#2e8b57" opacity="0.1" />
            
            <rect x="120" y="60" width="160" height="280" rx="30" fill="#e8e8e8" stroke="#ccc" strokeWidth="2" />
            
            <rect x="140" y="80" width="120" height="240" rx="20" fill="#f0c040" opacity="0.3" />
            
            <rect x="165" y="100" width="70" height="200" rx="10" fill="#b87333" opacity="0.5" />
            
            <rect x="185" y="120" width="30" height="160" rx="5" fill="#7a4510" />
            
            <rect x="120" y="60" width="160" height="280" rx="30" fill="url(#cableGradient)" opacity="0.5" />
            
            {[0, 1, 2, 3, 4].map((i) => (
              <circle 
                key={i}
                cx={200 + (i % 2 === 0 ? -40 : 40)}
                cy={100 + i * 50}
                r="8"
                fill="#b87333"
                opacity="0.3"
              />
            ))}
            
            <line x1="80" y1="200" x2="120" y2="200" stroke="#666" strokeWidth="2" strokeDasharray="4" />
            <line x1="280" y1="200" x2="320" y2="200" stroke="#666" strokeWidth="2" strokeDasharray="4" />
            
            <polygon points="100,190 120,200 100,210" fill="#666" />
            <polygon points="300,190 280,200 300,210" fill="#666" />
            <text x="200" y="240" textAnchor="middle" fill="#666" fontSize="14" fontWeight="bold">
              0.5 mm²
            </text>

            <defs>
              <linearGradient id="cableGradient" x1="0%" y1="0%" x2="100%" y2="0%">
                <stop offset="0%" stopColor="white" stopOpacity="0.1" />
                <stop offset="50%" stopColor="white" stopOpacity="0.3" />
                <stop offset="100%" stopColor="white" stopOpacity="0.1" />
              </linearGradient>
            </defs>
          </svg>
        </div>

        <div className="absolute bottom-4 left-1/2 transform -translate-x-1/2 flex gap-2">
          <button 
            onClick={() => setRotation(prev => prev - 15)}
            className="px-4 py-2 bg-white/90 backdrop-blur-sm rounded-full shadow-lg hover:bg-white transition-colors text-sm font-medium text-gray-700"
          >
            ↺ Rotate
          </button>
          <button 
            onClick={() => setRotation(prev => prev + 15)}
            className="px-4 py-2 bg-white/90 backdrop-blur-sm rounded-full shadow-lg hover:bg-white transition-colors text-sm font-medium text-gray-700"
          >
            Rotate ↻
          </button>
          <button 
            onClick={() => setRotation(0)}
            className="px-4 py-2 bg-white/90 backdrop-blur-sm rounded-full shadow-lg hover:bg-white transition-colors text-sm font-medium text-gray-700"
          >
            Reset
          </button>
        </div>

        {isHovered && (
          <div className="absolute top-2 right-2 px-3 py-1 bg-blue-500/90 backdrop-blur-sm rounded-full text-white text-xs font-medium">
            Interactive 3D
          </div>
        )}
      </div>

      <div className="absolute top-4 left-4 px-3 py-1 bg-green-500 text-white text-xs font-semibold rounded-full shadow-lg">
        Interactive 3D View
      </div>
    </div>
  )
}

export default function ModernProductPage() {
  const product = getProductById(PRODUCT_ID)
  const [selectedQuantity, setSelectedQuantity] = useState(1)
  const [showBuyNow, setShowBuyNow] = useState(false)

  if (!product) {
    return (
      <div className="flex items-center justify-center min-h-screen bg-gray-50">
        <div className="text-center p-8">
          <p className="text-gray-600">Product not found: <strong>{PRODUCT_ID}</strong></p>
        </div>
      </div>
    )
  }


  return (
    <div className="min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 p-4 md:p-8">
      <div className="max-w-6xl mx-auto">
        <div className="bg-white rounded-2xl shadow-xl overflow-hidden mb-6">
          <div className="flex flex-col md:flex-row items-center justify-between p-6 border-b border-gray-100">
            <div className="flex items-center gap-4">
              <img className="h-16 w-auto object-contain" src={sqlogoImg.src} alt="SQ Electricals" />
            </div>
            <div className="flex items-center gap-4 mt-4 md:mt-0">
              <img className="h-20 w-full object-fit" src={detailsImg1.src} alt="Certification" />
            </div>
          </div>
        </div>

        <div className="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6">
          <div className="bg-white rounded-2xl shadow-xl overflow-hidden">
            <div className="p-6">
              <div className="flex items-center justify-between mb-4">
                <h2 className="text-sm font-semibold text-gray-700 uppercase tracking-wider">
                  Interactive 3D Model
                </h2>
                <span className="px-2 py-1 bg-blue-100 text-blue-700 text-xs font-medium rounded-full">
                  Rotate & Explore
                </span>
              </div>
              <Interactive3DModel />
            </div>
          </div>

          <div className="bg-white rounded-2xl shadow-xl overflow-hidden">
            <div className="p-6">
              <div className="flex items-center gap-3 mb-3">
                <span className="px-3 py-1 bg-blue-100 text-blue-700 text-xs font-semibold rounded-full">
                  Building Wire
                </span>
                <span className="px-3 py-1 bg-green-100 text-green-700 text-xs font-semibold rounded-full">
                  In Stock
                </span>
              </div>
              <h1 className="text-3xl font-bold text-gray-800 mb-1">
                {product.name}
              </h1>
              <p className="text-gray-500 text-lg mb-4">{product.subtitle}</p>
              
              <div className="grid grid-cols-2 gap-4 mb-6">
                <div className="bg-gray-50 rounded-xl p-3">
                  <p className="text-xs text-gray-500 uppercase tracking-wider">Conductor</p>
                  <p className="text-sm font-semibold text-gray-700">{product.conductorType}</p>
                </div>
                <div className="bg-gray-50 rounded-xl p-3">
                  <p className="text-xs text-gray-500 uppercase tracking-wider">Insulation</p>
                  <p className="text-sm font-semibold text-gray-700">{product.insulationMaterial}</p>
                </div>
              </div>

              <div className="mb-6">
                <p className="text-sm font-medium text-gray-700 mb-2">Available Colors:</p>
                <div className="flex gap-2 flex-wrap">
                  {product.availableColors.map((c) => (
                    <div
                      key={c.name}
                      title={c.name}
                      className="w-8 h-8 rounded-full border-2 border-gray-200 shadow-sm hover:shadow-md transition-shadow cursor-pointer"
                      style={{ backgroundColor: c.hex }}
                    />
                  ))}
                </div>
                <span className="text-xs text-gray-500 mt-1 block">or as per request</span>
              </div>

              <div className="border-t border-gray-100 pt-6">
                {/* <div className="flex items-center gap-4 mb-4">
                  <label className="text-sm font-medium text-gray-700">Quantity:</label>
                  <div className="flex items-center border border-gray-200 rounded-lg overflow-hidden">
                    <button 
                      onClick={() => setSelectedQuantity(Math.max(1, selectedQuantity - 1))}
                      className="px-3 py-1.5 bg-gray-50 hover:bg-gray-100 transition-colors text-gray-600"
                    >
                      −
                    </button>
                    <span className="px-4 py-1.5 bg-white text-gray-800 font-medium min-w-[40px] text-center">
                      {selectedQuantity}
                    </span>
                    <button 
                      onClick={() => setSelectedQuantity(selectedQuantity + 1)}
                      className="px-3 py-1.5 bg-gray-50 hover:bg-gray-100 transition-colors text-gray-600"
                    >
                      +
                    </button>
                  </div>
                  <span className="text-sm text-gray-500">Coil</span>
                </div> */}

                <div className="flex flex-col sm:flex-row gap-3">
                  <Link href={'/contact'} 
                    className="flex-1 text-center bg-blue-600 hover:bg-blue-700 text-white font-semibold py-3 px-6 rounded-xl transition-all transform hover:scale-[1.02] shadow-lg hover:shadow-xl"
                  >
                    Buy Now
                  </Link>
                 
                </div>

                {showBuyNow && (
                  <div className="mt-3 p-3 bg-green-50 border border-green-200 rounded-lg text-green-700 text-sm animate-fade-in">
                    ✓ Added to cart successfully!
                  </div>
                )}
              </div>
            </div>
          </div>
        </div>

        <div className="bg-white rounded-2xl shadow-xl overflow-hidden mb-6">
          <div className="p-6">
            <div className="flex items-center justify-between mb-4">
              <h3 className="text-sm font-semibold text-gray-700 uppercase tracking-wider">
                Compact Wires Collection
              </h3>
              <span className="text-xs text-blue-600 hover:text-blue-700 cursor-pointer">View All →</span>
            </div>
            <div className="grid grid-cols-2 md:grid-cols-4 gap-4">
              {[
                { name: "1x0.5 re BYA", size: "0.5 mm²" },
                { name: "1x1.5 re BYA", size: "1.5 mm²" },
                { name: "1x2.5 re BYA", size: "2.5 mm²" },
                { name: "1x4.0 re BYA", size: "4.0 mm²" },
              ].map((wire, i) => (
                <div key={i} className="bg-gray-50 rounded-xl p-4 hover:shadow-md transition-shadow cursor-pointer">
                  <div className="w-12 h-12 bg-gradient-to-br from-orange-400 to-orange-600 rounded-full mx-auto mb-2 flex items-center justify-center">
                    <span className="text-white font-bold text-xs">CU</span>
                  </div>
                  <p className="text-sm font-medium text-gray-800 text-center">{wire.name}</p>
                  <p className="text-xs text-gray-500 text-center">{wire.size}</p>
                </div>
              ))}
            </div>
          </div>
        </div>

        <div className="bg-white rounded-2xl shadow-xl overflow-hidden mb-6">
          <div className="p-6">
            <h3 className="text-sm font-semibold text-gray-700 uppercase tracking-wider mb-3">
              Standards & Certifications
            </h3>
            <div className="grid grid-cols-1 md:grid-cols-2 gap-2 bg-gray-50 rounded-xl p-4">
              {product.standards.map((s, i) => (
                <div key={i} className="flex items-start gap-2 text-sm text-gray-600">
                  <span className="text-blue-500 mt-0.5">▸</span>
                  <span>{s}</span>
                </div>
              ))}
            </div>
          </div>
        </div>

        <div className="bg-white rounded-2xl shadow-xl overflow-hidden mb-6">
          <div className="p-6">
            <h3 className="text-sm font-semibold text-gray-700 uppercase tracking-wider mb-4">
              Technical Characteristics
            </h3>
            
            <div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
              {[
                { title: "Construction", data: product.constructionCharacteristics },
                { title: "Dimensional", data: product.dimensionalCharacteristics },
                { title: "Electrical", data: product.electricalCharacteristics },
                { title: "Mechanical", data: product.mechanicalCharacteristics },
                { title: "Usage", data: product.usageCharacteristics },
              ].map((section, idx) => (
                <div key={idx} className="bg-gray-50 rounded-xl overflow-hidden">
                  <div className="bg-blue-600 px-4 py-2">
                    <h4 className="text-xs font-semibold text-white uppercase tracking-wider">
                      {section.title} Characteristics
                    </h4>
                  </div>
                  <div className="divide-y divide-gray-200">
                    {section.data.map((row, i) => (
                      <div key={i} className="flex justify-between px-4 py-2.5 hover:bg-white transition-colors">
                        <span className="text-sm text-gray-600">{row.label}</span>
                        <span className="text-sm font-medium text-gray-800">{row.value}</span>
                      </div>
                    ))}
                  </div>
                </div>
              ))}
            </div>
          </div>
        </div>

        <div className="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
          <div className="bg-white rounded-2xl shadow-xl overflow-hidden">
            <div className="p-6">
              <h3 className="text-sm font-semibold text-gray-700 uppercase tracking-wider mb-4">
                Key Features
              </h3>
              <div className="grid grid-cols-2 gap-2">
                {product.features.map((feature, i) => (
                  <div key={i} className="flex items-center gap-2 text-sm text-gray-600 bg-gray-50 rounded-lg px-3 py-2">
                    <span className="text-green-500">✓</span>
                    <span>{feature}</span>
                  </div>
                ))}
              </div>
            </div>
          </div>

          <div className="bg-white rounded-2xl shadow-xl overflow-hidden">
            <div className="p-6">
              <h3 className="text-sm font-semibold text-gray-700 uppercase tracking-wider mb-4">
                Installation Conditions
              </h3>
              <div className="flex flex-wrap gap-3">
                {product.installationConditions.map((condition, i) => (
                  <span
                    key={i}
                    className="px-4 py-2 bg-blue-50 text-blue-700 text-sm font-medium rounded-full border border-blue-200"
                  >
                    {condition}
                  </span>
                ))}
              </div>
            </div>
          </div>
        </div>

        <div className="mt-6 flex justify-center w-full bg-white rounded-2xl p-10 mb-5">
          <img className="h-full w-full" src={detailsImg4.src} alt="Certification" />
        </div>

        <div className="bg-white rounded-2xl shadow-xl overflow-hidden">
          <div className="p-6">
            <div className="grid grid-cols-1 md:grid-cols-3 gap-6 items-center">
              <div className="flex justify-center">
                <img className="h-16 w-auto object-contain" src={detailsImg3.src} alt="SQ Electricals" />
              </div>
              <div className="text-center md:text-left">
                <h4 className="text-lg font-bold text-gray-800 mb-1">Head Office</h4>
                <p className="text-sm text-gray-600 leading-relaxed">
                  Suvastu Suraiya Trade Center, Level: 8-13<br />
                  Plot: 57 Road: 21, Block: B<br />
                  Kemal Ataturk Avenue, Banani<br />
                  Dhaka-1213, Bangladesh
                </p>
              </div>
              <div className="text-center md:text-left">
                <h4 className="text-lg font-bold text-gray-800 mb-1">SQ Industrial Park</h4>
                <p className="text-sm text-gray-600 leading-relaxed">
                  Plot No.: 40, Zone-2A<br />
                  National Special Economic Zone (NSEZ)<br />
                  Mirsarai, Chattogram<br />
                  Bangladesh
                </p>
              </div>
            </div>
          </div>
        </div>

     
      </div>

      {/* Custom CSS for animations */}
      <style>{`
        @keyframes fade-in {
          from {
            opacity: 0;
            transform: translateY(-10px);
          }
          to {
            opacity: 1;
            transform: translateY(0);
          }
        }
        .animate-fade-in {
          animation: fade-in 0.3s ease-out;
        }
      `}</style>
    </div>
  )
}