import * as React from "react";

import { Typography } from "@/components/ui/typography";
import { cn } from "@/lib/utils";
import Image from "next/image";

/**
 * Premium, on-brand hero illustration — a stylised luxury car under a foam +
 * water spray. Pure vector (no external asset): gradients reference the brand
 * CSS variables and solid fills use design-token utilities, so it themes with
 * the palette. Decorative only → aria-hidden.
 */
export function HeroArt({ className }: { className?: string }) {
  return (
    <svg
      viewBox="0 0 520 440"
      role="img"
      aria-hidden
      className={cn("h-auto w-full", className)}
    >
      <defs>
        <linearGradient id="washy-blob" x1="0" y1="0" x2="1" y2="1">
          <stop offset="0%" stopColor="var(--primary-sky-blue)" />
          <stop offset="100%" stopColor="var(--primary-blue)" />
        </linearGradient>
        <linearGradient id="washy-car" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="var(--primary-sky-blue)" />
          <stop offset="100%" stopColor="var(--primary-blue)" />
        </linearGradient>
      </defs>

      {/* backdrop blob */}
      <path
        d="M470 220c0 120-96 190-214 190S30 356 30 232 118 40 256 40s214 60 214 180z"
        fill="url(#washy-blob)"
        opacity="0.14"
      />
      <circle
        cx="256"
        cy="230"
        r="180"
        fill="url(#washy-blob)"
        opacity="0.10"
      />

      {/* ground shadow */}
      <ellipse
        cx="262"
        cy="352"
        rx="184"
        ry="20"
        className="fill-primary-blue"
        opacity="0.12"
      />

      {/* car body */}
      <path
        d="M104 300c-14 0-22-8-22-22v-14c0-16 10-26 28-30l40-8 46-44c12-11 26-16 44-16h74c22 0 40 8 58 26l34 34 38 8c18 4 28 15 28 33v11c0 14-8 22-22 22z"
        fill="url(#washy-car)"
      />
      {/* windows */}
      <path
        d="M196 176c8-8 16-12 28-12h58c16 0 28 5 40 18l24 26H168z"
        className="fill-white"
        opacity="0.92"
      />
      <path
        d="M266 164h16c16 0 28 5 40 18l24 26h-80z"
        className="fill-primary-sky-blue"
        opacity="0.35"
      />
      {/* door line + handle */}
      <path
        d="M236 208v78"
        stroke="var(--surface)"
        strokeOpacity="0.5"
        strokeWidth="3"
      />
      <rect
        x="250"
        y="228"
        width="26"
        height="7"
        rx="3.5"
        className="fill-white"
        opacity="0.85"
      />

      {/* wheels */}
      <g>
        <circle cx="176" cy="300" r="40" className="fill-main-text" />
        <circle cx="176" cy="300" r="18" className="fill-white" />
        <circle cx="176" cy="300" r="7" className="fill-main-text" />
      </g>
      <g>
        <circle cx="372" cy="300" r="40" className="fill-main-text" />
        <circle cx="372" cy="300" r="18" className="fill-white" />
        <circle cx="372" cy="300" r="7" className="fill-main-text" />
      </g>

      {/* headlight shine */}
      <circle cx="452" cy="266" r="9" className="fill-primary-amber" />

      {/* foam bubbles on the roof */}
      <g className="fill-white">
        <circle cx="214" cy="150" r="18" opacity="0.95" />
        <circle cx="244" cy="138" r="14" opacity="0.9" />
        <circle cx="272" cy="150" r="20" opacity="0.95" />
        <circle cx="300" cy="140" r="12" opacity="0.88" />
        <circle cx="196" cy="164" r="11" opacity="0.85" />
      </g>

      {/* water spray */}
      <g className="fill-primary-sky-blue">
        {[
          [96, 96],
          [120, 78],
          [150, 66],
          [86, 130],
          [110, 118],
          [70, 168],
          [140, 100],
        ].map(([cx, cy], i) => (
          <circle
            key={i}
            cx={cx}
            cy={cy}
            r={i % 2 === 0 ? 7 : 4}
            opacity="0.75"
          />
        ))}
      </g>

      {/* sparkles */}
      <g className="fill-primary-amber">
        <Sparkle x={398} y={120} s={16} />
        <Sparkle x={430} y={172} s={10} />
        <Sparkle x={150} y={214} s={12} />
      </g>
    </svg>
  );
}

function Sparkle({ x, y, s }: { x: number; y: number; s: number }) {
  return (
    <path
      d={`M${x} ${y - s}C${x + s * 0.14} ${y - s * 0.14} ${x + s * 0.14} ${y - s * 0.14} ${x + s} ${y}C${x + s * 0.14} ${y + s * 0.14} ${x + s * 0.14} ${y + s * 0.14} ${x} ${y + s}C${x - s * 0.14} ${y + s * 0.14} ${x - s * 0.14} ${y + s * 0.14} ${x - s} ${y}C${x - s * 0.14} ${y - s * 0.14} ${x - s * 0.14} ${y - s * 0.14} ${x} ${y - s}Z`}
    />
  );
}

/** App Store / Google Play download badge (placeholder link until store URLs exist). */
export function StoreBadge({
  store,
  label,
  href = "#",
  className,
}: {
  store: "apple" | "google";
  label: string;
  href?: string;
  className?: string;
}) {
  return (
    <a
      href={href}
      className={cn(
        "inline-flex items-center gap-3 rounded-[14px] bg-main-text px-5 py-3 text-white transition-colors hover:bg-main-text/90",
        className,
      )}
    >
      {store === "apple" ? (
        <Image src={"/svgs/apple_store.webp"} width={20} height={20} alt="" />
      ) : (
        <Image src={"/svgs/playstore_logo.svg"} width={20} height={20} alt="" />
      )}
      <Typography
        as="span"
        variant="button"
        color="inherit"
        className="text-[15px] font-semibold"
      >
        {label}
      </Typography>
    </a>
  );
}

/**
 * Decorative faux-QR (deterministic modules — no random, so it renders the same
 * every time). A real QR image can drop in once the app store links exist.
 */
export function QrCode({ className }: { className?: string }) {
  return (
    <Image
      src={"/svgs/apple_store_qr.png"}
      width={120}
      height={120}
      alt=""
      className={className}
    />
  );
}
