import React from 'react';

// ─── Design: Browser wireframe আঁকা হচ্ছে ─────────────────────────────────
const DesignSVG: React.FC = () => (
    <svg viewBox="0 0 80 80" style={{ width: '100%', height: '100%' }} xmlns="http://www.w3.org/2000/svg">
        {/* Browser */}
        <rect x="5" y="8" width="70" height="64" rx="4"
            fill="rgba(255,255,255,0.08)" stroke="rgba(255,255,255,0.65)" strokeWidth="1.5"/>
        <rect x="5" y="8" width="70" height="13" rx="4" fill="rgba(255,255,255,0.15)"/>
        <circle cx="14" cy="14.5" r="2.5" fill="#ff5f57"/>
        <circle cx="22" cy="14.5" r="2.5" fill="#ffbd2e"/>
        <circle cx="30" cy="14.5" r="2.5" fill="#28c840"/>

        {/* Hero block */}
        <rect x="9" y="25" width="62" height="12" rx="2"
            fill="none" stroke="rgba(255,255,255,0.85)" strokeWidth="1.5"
            strokeDasharray="148" strokeDashoffset="148">
            <animate attributeName="strokeDashoffset" values="148;0;0;148"
                dur="4s" repeatCount="indefinite" keyTimes="0;0.3;0.8;1"/>
        </rect>

        {/* Left block */}
        <rect x="9" y="41" width="20" height="24" rx="2"
            fill="none" stroke="rgba(255,255,255,0.7)" strokeWidth="1.5"
            strokeDasharray="88" strokeDashoffset="88">
            <animate attributeName="strokeDashoffset" values="88;88;0;0;88"
                dur="4s" repeatCount="indefinite" keyTimes="0;0.32;0.58;0.8;1"/>
        </rect>

        {/* Right block */}
        <rect x="33" y="41" width="38" height="24" rx="2"
            fill="none" stroke="rgba(255,255,255,0.7)" strokeWidth="1.5"
            strokeDasharray="124" strokeDashoffset="124">
            <animate attributeName="strokeDashoffset" values="124;124;0;0;124"
                dur="4s" repeatCount="indefinite" keyTimes="0;0.6;0.76;0.8;1"/>
        </rect>

        {/* Cursor */}
        <g>
            <animateTransform attributeName="transform" type="translate"
                values="9,25; 71,25; 71,37; 9,41; 29,65; 71,65; 9,25"
                dur="4s" repeatCount="indefinite"
                keyTimes="0;0.08;0.3;0.32;0.58;0.76;1"/>
            <polygon points="0,0 0,11 3,8 5.5,13 7.5,12 5,7 8.5,7"
                fill="white" opacity="0.95"/>
        </g>
    </svg>
);

// ─── Development: Terminal code টাইপিং ─────────────────────────────────────
const DevelopmentSVG: React.FC = () => (
    <svg viewBox="0 0 80 80" style={{ width: '100%', height: '100%' }} xmlns="http://www.w3.org/2000/svg">
        <rect x="4" y="8" width="72" height="64" rx="4"
            fill="rgba(0,0,0,0.45)" stroke="rgba(255,255,255,0.3)" strokeWidth="1.5"/>
        <rect x="4" y="8" width="72" height="13" rx="4" fill="rgba(0,0,0,0.55)"/>
        <circle cx="13" cy="14.5" r="2.5" fill="#ff5f57"/>
        <circle cx="21" cy="14.5" r="2.5" fill="#ffbd2e"/>
        <circle cx="29" cy="14.5" r="2.5" fill="#28c840"/>

        {/* $ prompt */}
        <text x="9" y="33" fontSize="7" fill="rgba(100,255,100,0.9)" fontFamily="monospace">$</text>

        {/* Line 1 – purple */}
        <rect x="18" y="27.5" height="7" rx="1.5" fill="rgba(195,150,255,0.95)" width="0">
            <animate attributeName="width" values="0;44;44;0"
                dur="5s" repeatCount="indefinite" keyTimes="0;0.2;0.82;1"/>
        </rect>

        {/* Line 2 – cyan */}
        <rect x="9" y="38" height="7" rx="1.5" fill="rgba(100,215,255,0.95)" width="0">
            <animate attributeName="width" values="0;0;38;38;0"
                dur="5s" repeatCount="indefinite" keyTimes="0;0.2;0.44;0.82;1"/>
        </rect>

        {/* Line 3 – orange (indented) */}
        <rect x="18" y="48.5" height="7" rx="1.5" fill="rgba(255,175,100,0.95)" width="0">
            <animate attributeName="width" values="0;0;30;30;0"
                dur="5s" repeatCount="indefinite" keyTimes="0;0.44;0.62;0.82;1"/>
        </rect>

        {/* Line 4 – green */}
        <rect x="9" y="59" height="7" rx="1.5" fill="rgba(100,255,140,0.95)" width="0">
            <animate attributeName="width" values="0;0;20;20;0"
                dur="5s" repeatCount="indefinite" keyTimes="0;0.62;0.74;0.82;1"/>
        </rect>

        {/* Blinking cursor */}
        <rect y="0" width="4" height="7" rx="1" fill="rgba(255,255,255,0.95)">
            <animate attributeName="opacity" values="1;0;1" dur="0.65s" repeatCount="indefinite"/>
            <animateTransform attributeName="transform" type="translate"
                values="18,27.5; 62,27.5; 47,38; 48,48.5; 29,59; 18,27.5"
                dur="5s" repeatCount="indefinite"
                keyTimes="0;0.2;0.44;0.62;0.74;1"/>
        </rect>
    </svg>
);

// ─── E-commerce: Products cart-এ উড়ে আসছে + counter ──────────────────────
const EcommerceSVG: React.FC = () => (
    <svg viewBox="0 0 80 80" style={{ width: '100%', height: '100%' }} xmlns="http://www.w3.org/2000/svg">
        {/* Cart body */}
        <path d="M6 15 L17 15 L26 54 L68 54 L73 28 L17 28"
            fill="none" stroke="rgba(255,255,255,0.88)" strokeWidth="2.5"
            strokeLinejoin="round" strokeLinecap="round"/>
        <circle cx="6" cy="13" r="3" fill="rgba(255,255,255,0.6)"/>
        {/* Wheels */}
        <circle cx="32" cy="64" r="6" fill="none" stroke="rgba(255,255,255,0.85)" strokeWidth="2.5"/>
        <circle cx="60" cy="64" r="6" fill="none" stroke="rgba(255,255,255,0.85)" strokeWidth="2.5"/>
        <circle cx="32" cy="64" r="2" fill="rgba(255,255,255,0.6)"/>
        <circle cx="60" cy="64" r="2" fill="rgba(255,255,255,0.6)"/>

        {/* Product 1 – yellow */}
        <rect x="-5" y="-5" width="10" height="10" rx="2" fill="rgba(255,210,60,0.95)">
            <animateTransform attributeName="transform" type="translate"
                values="14,9; 47,40" dur="0.85s" begin="0s" repeatCount="indefinite"
                calcMode="spline" keySplines="0.4 0 0.2 1"/>
            <animate attributeName="opacity" values="1;1;0" dur="0.85s" begin="0s"
                repeatCount="indefinite" keyTimes="0;0.75;1"/>
        </rect>

        {/* Product 2 – cyan */}
        <circle r="5" fill="rgba(80,220,255,0.95)">
            <animateTransform attributeName="transform" type="translate"
                values="70,8; 50,40" dur="0.85s" begin="1.1s" repeatCount="indefinite"
                calcMode="spline" keySplines="0.4 0 0.2 1"/>
            <animate attributeName="opacity" values="1;1;0" dur="0.85s" begin="1.1s"
                repeatCount="indefinite" keyTimes="0;0.75;1"/>
        </circle>

        {/* Product 3 – pink */}
        <rect x="-4" y="-4" width="8" height="8" rx="4" fill="rgba(255,120,180,0.95)">
            <animateTransform attributeName="transform" type="translate"
                values="43,6; 53,40" dur="0.85s" begin="2.2s" repeatCount="indefinite"
                calcMode="spline" keySplines="0.4 0 0.2 1"/>
            <animate attributeName="opacity" values="1;1;0" dur="0.85s" begin="2.2s"
                repeatCount="indefinite" keyTimes="0;0.75;1"/>
        </rect>

        {/* Badge */}
        <circle cx="70" cy="15" r="10" fill="rgba(255,55,55,0.95)"/>
        <text x="70" y="19.5" textAnchor="middle" fontSize="10"
            fill="white" fontFamily="sans-serif" fontWeight="bold" opacity="0">
            1
            <animate attributeName="opacity" values="0;1;1;0"
                dur="3.3s" repeatCount="indefinite" keyTimes="0;0.04;0.33;0.37"/>
        </text>
        <text x="70" y="19.5" textAnchor="middle" fontSize="10"
            fill="white" fontFamily="sans-serif" fontWeight="bold" opacity="0">
            2
            <animate attributeName="opacity" values="0;0;1;1;0"
                dur="3.3s" repeatCount="indefinite" keyTimes="0;0.37;0.41;0.67;0.71"/>
        </text>
        <text x="70" y="19.5" textAnchor="middle" fontSize="10"
            fill="white" fontFamily="sans-serif" fontWeight="bold" opacity="0">
            3
            <animate attributeName="opacity" values="0;0;1;1;0"
                dur="3.3s" repeatCount="indefinite" keyTimes="0;0.71;0.75;0.96;1"/>
        </text>
    </svg>
);

// ─── AI Automation: Circuit + data pulse ────────────────────────────────────
const AutomationSVG: React.FC = () => (
    <svg viewBox="0 0 80 80" style={{ width: '100%', height: '100%' }} xmlns="http://www.w3.org/2000/svg">
        {/* Central brain/chip */}
        <rect x="28" y="28" width="24" height="24" rx="4"
            fill="rgba(255,255,255,0.15)" stroke="rgba(255,255,255,0.8)" strokeWidth="1.8"/>
        <rect x="33" y="33" width="14" height="14" rx="2"
            fill="rgba(255,255,255,0.25)"/>

        {/* Circuit pins – top */}
        <line x1="34" y1="28" x2="34" y2="14" stroke="rgba(255,255,255,0.55)" strokeWidth="1.5"/>
        <line x1="40" y1="28" x2="40" y2="8"  stroke="rgba(255,255,255,0.55)" strokeWidth="1.5"/>
        <line x1="46" y1="28" x2="46" y2="14" stroke="rgba(255,255,255,0.55)" strokeWidth="1.5"/>
        {/* bottom */}
        <line x1="34" y1="52" x2="34" y2="66" stroke="rgba(255,255,255,0.55)" strokeWidth="1.5"/>
        <line x1="40" y1="52" x2="40" y2="72" stroke="rgba(255,255,255,0.55)" strokeWidth="1.5"/>
        <line x1="46" y1="52" x2="46" y2="66" stroke="rgba(255,255,255,0.55)" strokeWidth="1.5"/>
        {/* left */}
        <line x1="28" y1="34" x2="14" y2="34" stroke="rgba(255,255,255,0.55)" strokeWidth="1.5"/>
        <line x1="28" y1="40" x2="8"  y2="40" stroke="rgba(255,255,255,0.55)" strokeWidth="1.5"/>
        <line x1="28" y1="46" x2="14" y2="46" stroke="rgba(255,255,255,0.55)" strokeWidth="1.5"/>
        {/* right */}
        <line x1="52" y1="34" x2="66" y2="34" stroke="rgba(255,255,255,0.55)" strokeWidth="1.5"/>
        <line x1="52" y1="40" x2="72" y2="40" stroke="rgba(255,255,255,0.55)" strokeWidth="1.5"/>
        <line x1="52" y1="46" x2="66" y2="46" stroke="rgba(255,255,255,0.55)" strokeWidth="1.5"/>

        {/* Pulse dots travelling along wires */}
        {/* top-center pulse */}
        <circle r="3" fill="rgba(100,220,255,0.95)">
            <animateTransform attributeName="transform" type="translate"
                values="40,28; 40,8" dur="1.5s" begin="0s" repeatCount="indefinite"
                calcMode="spline" keySplines="0.4 0 0.6 1"/>
            <animate attributeName="opacity" values="1;0" dur="1.5s" begin="0s" repeatCount="indefinite"/>
        </circle>
        {/* right-center pulse */}
        <circle r="3" fill="rgba(255,200,60,0.95)">
            <animateTransform attributeName="transform" type="translate"
                values="52,40; 72,40" dur="1.5s" begin="0.5s" repeatCount="indefinite"
                calcMode="spline" keySplines="0.4 0 0.6 1"/>
            <animate attributeName="opacity" values="1;0" dur="1.5s" begin="0.5s" repeatCount="indefinite"/>
        </circle>
        {/* bottom pulse */}
        <circle r="3" fill="rgba(180,100,255,0.95)">
            <animateTransform attributeName="transform" type="translate"
                values="40,52; 40,72" dur="1.5s" begin="1s" repeatCount="indefinite"
                calcMode="spline" keySplines="0.4 0 0.6 1"/>
            <animate attributeName="opacity" values="1;0" dur="1.5s" begin="1s" repeatCount="indefinite"/>
        </circle>
        {/* left pulse */}
        <circle r="3" fill="rgba(100,255,160,0.95)">
            <animateTransform attributeName="transform" type="translate"
                values="28,40; 8,40" dur="1.5s" begin="0.25s" repeatCount="indefinite"
                calcMode="spline" keySplines="0.4 0 0.6 1"/>
            <animate attributeName="opacity" values="1;0" dur="1.5s" begin="0.25s" repeatCount="indefinite"/>
        </circle>

        {/* Center pulsing glow */}
        <rect x="33" y="33" width="14" height="14" rx="2"
            fill="rgba(100,200,255,0.3)">
            <animate attributeName="opacity" values="0.2;0.8;0.2" dur="2s" repeatCount="indefinite"/>
        </rect>
    </svg>
);

// ─── The 4 cards config ──────────────────────────────────────────────────────
const heroCards = [
    {
        title: 'Web Design',
        description: 'Pixel-perfect UI',
        gradient: 'from-blue-600 to-cyan-500',
        shadow: 'shadow-blue-500/40',
        Animation: DesignSVG,
    },
    {
        title: 'Development',
        description: 'Clean, fast code',
        gradient: 'from-violet-600 to-purple-500',
        shadow: 'shadow-violet-500/40',
        Animation: DevelopmentSVG,
    },
    {
        title: 'E-Commerce',
        description: 'Sell more, faster',
        gradient: 'from-emerald-500 to-teal-500',
        shadow: 'shadow-emerald-500/40',
        Animation: EcommerceSVG,
    },
    {
        title: 'AI Automation',
        description: 'Smart workflows',
        gradient: 'from-rose-500 to-pink-500',
        shadow: 'shadow-rose-500/40',
        Animation: AutomationSVG,
    },
];

const HeroAnimationCards: React.FC = () => (
    <div className="relative w-full flex items-center justify-center py-2">
        {/* Soft ambient glow behind grid */}
        <div className="absolute inset-0 rounded-3xl bg-gradient-to-br from-primary/20 via-purple-500/10 to-cyan-500/15 blur-2xl" />

        <div className="relative grid grid-cols-2 gap-4 w-full max-w-[460px]">
            {heroCards.map((card, i) => (
                <div
                    key={card.title}
                    className={`
                        group relative overflow-hidden rounded-2xl
                        bg-white/5 backdrop-blur-sm
                        border border-white/10
                        hover:border-white/25
                        shadow-xl ${card.shadow}
                        transition-all duration-500
                        hover:-translate-y-1 hover:scale-[1.03]
                    `}
                    style={{
                        animationDelay: `${i * 0.15}s`,
                    }}
                >
                    {/* Gradient top strip */}
                    <div className={`h-2 w-full bg-gradient-to-r ${card.gradient}`} />

                    {/* Animation area */}
                    <div className={`relative mx-auto mt-5 w-[110px] h-[110px] rounded-2xl bg-gradient-to-br ${card.gradient} p-2.5 shadow-lg ${card.shadow}`}>
                        <card.Animation />
                    </div>

                    {/* Text */}
                    <div className="px-4 pt-4 pb-5 text-center">
                        <p className="text-white font-semibold text-base leading-tight">
                            {card.title}
                        </p>
                        <p className="text-white/55 text-sm mt-1">
                            {card.description}
                        </p>
                    </div>

                    {/* Hover inner glow */}
                    <div className={`absolute inset-0 opacity-0 group-hover:opacity-[0.08] transition-opacity duration-500 bg-gradient-to-br ${card.gradient} pointer-events-none`} />
                </div>
            ))}
        </div>
    </div>
);

export default HeroAnimationCards;
