import Reveal from "./Reveal";
import {
  PhoneIcon,
  MessageIcon,
  AlertIcon,
  BadgeCheckIcon,
  QrIcon,
  ArrowRightIcon,
  StarIcon,
} from "./icons";

const FLOW = ["User", "Scan QR", "VehCall", "Owner", "Connected"];

export default function Hero() {
  return (
    <section
      id="home"
      className="relative flex min-h-screen items-center overflow-hidden pt-28 pb-20"
    >
      {/* Backdrop layers */}
      <div className="pointer-events-none absolute inset-0 bg-grid [mask-image:radial-gradient(ellipse_at_center,black,transparent_75%)]" />
      <div className="pointer-events-none absolute inset-0 bg-glow-radial" />
      <div className="pointer-events-none absolute -left-24 top-24 h-72 w-72 rounded-full bg-brand/20 blur-[120px]" />
      <div className="pointer-events-none absolute -right-16 bottom-10 h-80 w-80 rounded-full bg-electric/20 blur-[130px]" />

      <div className="relative mx-auto grid w-full max-w-7xl grid-cols-1 items-center gap-14 px-5 sm:px-8 lg:grid-cols-[1.05fr_1fr]">
        {/* Left content */}
        <div className="flex flex-col items-start gap-7">
          <Reveal>
            <span className="eyebrow">
              <span className="h-1.5 w-1.5 rounded-full bg-brand" />
              Secure Vehicle Communication
            </span>
          </Reveal>

          <Reveal delay={80}>
            <h1 className="text-4xl font-extrabold leading-[1.08] sm:text-5xl lg:text-6xl">
              Contact Any Vehicle Owner{" "}
              <span className="text-gradient">Without Sharing</span> Your Number
            </h1>
          </Reveal>

          <Reveal delay={160}>
            <p className="max-w-xl text-lg leading-relaxed text-white/65">
              Scan a VehCall QR code and instantly call, message, or notify a
              vehicle owner while keeping personal contact information private.
            </p>
          </Reveal>

          <Reveal delay={240}>
            <div className="flex flex-col gap-3 sm:flex-row">
              <a href="#pricing" className="btn-primary">
                Get Started
                <ArrowRightIcon width={18} height={18} />
              </a>
            </div>
          </Reveal>

          <Reveal delay={320}>
            <div className="flex flex-wrap items-center gap-x-6 gap-y-3 pt-2">
              <div className="flex items-center gap-2">
                <div className="flex -space-x-2">
                  {["#5C7CFA", "#9B6BFF", "#25D366", "#7C6CFD"].map((c) => (
                    <span
                      key={c}
                      className="h-8 w-8 rounded-full border-2 border-bg"
                      style={{ background: c }}
                    />
                  ))}
                </div>
                <span className="text-sm text-white/60">
                  50,000+ vehicles registered
                </span>
              </div>
              <div className="flex items-center gap-1.5">
                <span className="flex text-warning">
                  {Array.from({ length: 5 }).map((_, i) => (
                    <StarIcon key={i} width={15} height={15} />
                  ))}
                </span>
                <span className="text-sm text-white/60">4.9/5 rating</span>
              </div>
            </div>
          </Reveal>
        </div>

        {/* Right visual */}
        <Reveal delay={200} className="relative">
          <HeroVisual />
        </Reveal>
      </div>

      {/* Flow visualization */}
      <Reveal
        delay={120}
        className="absolute inset-x-0 bottom-6 hidden justify-center px-5 lg:flex"
      >
        <div className="glass flex items-center gap-2 rounded-full px-5 py-2.5">
          {FLOW.map((step, i) => (
            <div key={step} className="flex items-center gap-2">
              <span className="text-sm font-medium text-white/70">{step}</span>
              {i < FLOW.length - 1 && (
                <ArrowRightIcon
                  width={16}
                  height={16}
                  className="text-brand/70"
                />
              )}
            </div>
          ))}
        </div>
      </Reveal>
    </section>
  );
}

function HeroVisual() {
  return (
    <div className="relative mx-auto aspect-square w-full max-w-lg">
      {/* Rotating glow ring */}
      <div className="absolute inset-6 rounded-full border border-white/5 [mask-image:linear-gradient(black,transparent_70%)]" />
      <div className="absolute left-1/2 top-1/2 h-[78%] w-[78%] -translate-x-1/2 -translate-y-1/2 animate-spin-slow rounded-full border border-dashed border-brand/20" />

      {/* Central device / vehicle card */}
      <div className="glass card-hover absolute left-1/2 top-1/2 w-[74%] -translate-x-1/2 -translate-y-1/2 rounded-[2rem] p-6 shadow-2xl shadow-brand/10">
        {/* Vehicle silhouette */}
        <div className="relative overflow-hidden rounded-2xl bg-gradient-to-b from-surface to-bg p-6">
          <div className="absolute inset-0 bg-grid opacity-40" />
          <svg
            viewBox="0 0 320 150"
            className="relative w-full"
            aria-hidden="true"
          >
            <defs>
              <linearGradient id="car-body" x1="0" y1="0" x2="0" y2="1">
                <stop stopColor="#1f2937" />
                <stop offset="1" stopColor="#0b1220" />
              </linearGradient>
              <linearGradient id="car-glass" x1="0" y1="0" x2="1" y2="1">
                <stop stopColor="#0ea5e9" stopOpacity="0.5" />
                <stop offset="1" stopColor="#1e293b" stopOpacity="0.5" />
              </linearGradient>
            </defs>
            {/* Body */}
            <path
              d="M18 104 C28 78 56 70 84 66 C104 50 132 42 168 42 C206 42 232 52 254 70 C278 74 296 84 304 104 L304 116 C304 120 301 122 297 122 L23 122 C19 122 16 120 16 116 Z"
              fill="url(#car-body)"
              stroke="#334155"
              strokeWidth="1.5"
            />
            {/* Cabin / windows */}
            <path
              d="M104 58 C120 48 142 46 166 46 C194 46 214 54 232 68 L168 68 Z"
              fill="url(#car-glass)"
            />
            <path
              d="M100 64 L160 64 L160 46 C138 46 118 50 100 64 Z"
              fill="url(#car-glass)"
            />
            {/* Light streak */}
            <path d="M300 100 l-14 4" stroke="#5C7CFA" strokeWidth="3" strokeLinecap="round" />
            {/* Wheels */}
            <circle cx="92" cy="122" r="20" fill="#0b1220" stroke="#334155" strokeWidth="2" />
            <circle cx="92" cy="122" r="9" fill="#1e293b" stroke="#475569" strokeWidth="1.5" />
            <circle cx="240" cy="122" r="20" fill="#0b1220" stroke="#334155" strokeWidth="2" />
            <circle cx="240" cy="122" r="9" fill="#1e293b" stroke="#475569" strokeWidth="1.5" />
          </svg>

          {/* Glowing QR sticker on the door */}
          <div className="absolute bottom-7 left-1/2 flex h-14 w-14 -translate-x-1/2 items-center justify-center rounded-xl bg-gradient-to-br from-brand to-electric text-white shadow-[0_0_24px_4px_rgba(123,108,253,0.6)] animate-glow">
            <QrIcon width={30} height={30} strokeWidth={2} />
          </div>
        </div>

        <div className="mt-4 flex items-center justify-between">
          <div>
            <p className="text-sm font-semibold text-white">Tata · Nexon</p>
            <p className="text-xs text-white/50">VC-8842 · Verified owner</p>
          </div>
          <span className="flex items-center gap-1 rounded-full bg-success/15 px-2.5 py-1 text-xs font-semibold text-success">
            <BadgeCheckIcon width={14} height={14} /> Live
          </span>
        </div>
      </div>

      {/* Floating holographic cards */}
      <FloatCard
        className="left-0 top-8 animate-float"
        icon={<PhoneIcon width={18} height={18} />}
        tone="text-brand"
        title="Call Owner"
        subtitle="Number hidden"
      />
      <FloatCard
        className="right-0 top-24 animate-float-slow"
        icon={<MessageIcon width={18} height={18} />}
        tone="text-electric"
        title="Message Owner"
        subtitle="Quick replies"
      />
      <FloatCard
        className="-left-2 bottom-20 animate-float-slow"
        icon={<AlertIcon width={18} height={18} />}
        tone="text-danger"
        title="Emergency Alert"
        subtitle="Instant notify"
      />
      <FloatCard
        className="right-2 bottom-4 animate-float"
        icon={<BadgeCheckIcon width={18} height={18} />}
        tone="text-success"
        title="Owner Verified"
        subtitle="Authenticated"
      />
    </div>
  );
}

function FloatCard({
  className,
  icon,
  tone,
  title,
  subtitle,
}: {
  className: string;
  icon: React.ReactNode;
  tone: string;
  title: string;
  subtitle: string;
}) {
  return (
    <div
      className={`glass absolute flex items-center gap-3 rounded-2xl px-4 py-3 shadow-xl ${className}`}
    >
      <span
        className={`flex h-9 w-9 items-center justify-center rounded-xl bg-white/5 ${tone}`}
      >
        {icon}
      </span>
      <span className="leading-tight">
        <span className="block text-sm font-semibold text-white">{title}</span>
        <span className="block text-xs text-white/50">{subtitle}</span>
      </span>
    </div>
  );
}
