// ui.jsx, Polaris (Amigos-style) icons + small components
const P = {
  mail: ["M4 4h16a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z", "M22 7l-10 6L2 7"],
  phone: ["M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.96.36 1.9.7 2.81a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45c.91.34 1.85.57 2.81.7A2 2 0 0 1 22 16.92z"],
  user: ["M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2", "M12 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8z"],
  chevron: ["M6 9l6 6 6-6"],
  arrow: ["M5 12h14", "M12 5l7 7-7 7"],
  arrowr: ["M5 12h14", "M12 5l7 7-7 7"],
  back: ["M19 12H5", "M12 19l-7-7 7-7"],
  x: ["M18 6L6 18", "M6 6l12 12"],
  check: ["M20 6L9 17l-5-5"],
  checkc: ["M22 11.08V12a10 10 0 1 1-5.93-9.14", "M22 4L12 14.01l-3-3"],
  camera: ["M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z", "M12 17a4 4 0 1 0 0-8 4 4 0 0 0 0 8z"],
  home: ["M3 9.5L12 3l9 6.5", "M5 10v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V10"],
  users: ["M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2", "M9 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8z", "M23 21v-2a4 4 0 0 0-3-3.87", "M16 3.13a4 4 0 0 1 0 7.75"],
  scissors: ["M6 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6z", "M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6z", "M20 4L8.12 15.88", "M14.47 14.48L20 20", "M8.12 8.12L12 12"],
  layers: ["M12 2L2 7l10 5 10-5-10-5z", "M2 17l10 5 10-5", "M2 12l10 5 10-5"],
  sprout: ["M7 20h10", "M10 20c5.5-2.5.8-6.4 3-10", "M9.5 9.4c1.1.8 1.8 2.2 2.3 3.7-2 .4-3.5.4-4.8-.3-1.2-.6-2.3-1.9-3-4.2 2.8-.5 4.4 0 5.5.8z", "M14.1 6a7 7 0 0 0-1.1 4c1.9-.1 3.3-.6 4.3-1.4 1-1 1.6-2.3 1.7-4.6-2.7.1-4 1-4.9 2z"],
  flower: ["M12 9a3 3 0 1 0 0 6 3 3 0 0 0 0-6z", "M12 9c0-2 1-4 0-6-1 2 0 4 0 6z M12 15c0 2-1 4 0 6 1-2 0-4 0-6z M9 12c-2 0-4-1-6 0 2 1 4 0 6 0z M15 12c2 0 4 1 6 0-2-1-4 0-6 0z", "M12 16v6"],
  brush: ["M9.5 14.5L4 20", "M15 4l5 5L9 20H4v-5z", "M13 6l5 5"],
  wind: ["M9.6 4.6A2 2 0 1 1 11 8H2", "M12.6 19.4A2 2 0 1 0 14 16H2", "M17.7 7.7A2.5 2.5 0 1 1 19.5 12H2"],
  snow: ["M2 12h20", "M12 2v20", "M20 16l-4-4 4-4", "M4 8l4 4-4 4", "M16 4l-4 4-4-4", "M8 20l4-4 4 4"],
  leaf: ["M11 20A7 7 0 0 1 9.8 6.1C15.5 5 17 4.48 19 2c1 2 2 4.18 2 8 0 5.5-4.78 10-10 10z", "M2 21c0-3 1.85-5.36 5.08-6"],
  tree: ["M8 19a4 4 0 0 1-1-7.9 5 5 0 0 1 9.7-1.6A4.5 4.5 0 0 1 16 18.4", "M12 13v9", "M9 18l3-2 3 2"],
  footprints: ["M4 16v-2.38C4 11.5 2.97 10.5 3 8c.03-2.72 1.49-6 4.5-6C9.37 2 10 3.8 10 5.5c0 3.11-2 5.66-2 8.68V16a2 2 0 1 1-4 0z", "M20 20v-2.38c0-2.12 1.03-3.12 1-5.62-.03-2.72-1.49-6-4.5-6C14.63 6 14 7.8 14 9.5c0 3.11 2 5.66 2 8.68V20a2 2 0 1 0 4 0z"],
  satellite: ["M13 7l-2-2 4-4 2 2z", "M5 15l-2 2 4 4 2-2", "M2 22l5-5", "M12 8l4 4", "M18 12a6 6 0 0 1-6 6"],
  heart: ["M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7z"],
  pin: ["M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0z", "M12 12.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5z"],
  spark: ["M12 3l1.6 5.4L19 10l-5.4 1.6L12 17l-1.6-5.4L5 10l5.4-1.6z"],
  text: ["M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"],
  building: ["M3 21h18", "M6 21V4a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v17", "M9.5 7h1", "M13.5 7h1", "M9.5 11h1", "M13.5 11h1", "M9.5 15h1", "M13.5 15h1"],
  shield: ["M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z", "M9 12l2 2 4-4"],
  clock: ["M12 22a10 10 0 1 0 0-20 10 10 0 0 0 0 20z", "M12 6v6l4 2"],
  calendar: ["M19 4H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2z", "M16 2v4", "M8 2v4", "M3 10h18"],
  plus: ["M12 5v14", "M5 12h14"],
  minus: ["M5 12h14"],
  truck: ["M1 3h15v13H1z", "M16 8h4l3 3v5h-7", "M5.5 18.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5z", "M18.5 18.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5z"],
  badge: ["M12 15a4 4 0 1 0 0-8 4 4 0 0 0 0 8z", "M8.2 13.5L7 22l5-3 5 3-1.2-8.5"],
};

function Icon({ name, style }) {
  const d = P[name] || [];
  return (
    <svg className="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"
      strokeLinecap="round" strokeLinejoin="round" style={style} aria-hidden="true">
      {d.map((p, i) => <path key={i} d={p} />)}
    </svg>
  );
}

function Stars({ n = 5 }) {
  return (
    <span className="stars" aria-label={`${n} stars`}>
      {Array.from({ length: n }).map((_, i) => (
        <svg key={i} viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
          <path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01z" />
        </svg>
      ))}
    </span>
  );
}

// Polaris friendly star-badge logo mark (placeholder for a real mascot/logo)
function Mark({ className = "mark" }) {
  return (
    <svg className={className} viewBox="0 0 56 56" fill="none" aria-hidden="true">
      <rect x="2" y="2" width="52" height="52" rx="16" fill="#2f5d34" />
      <path d="M28 11l4.4 12.3L45 27l-12.6 3.7L28 43l-4.4-12.3L11 27l12.6-3.7z" fill="#d9b48f" />
      <circle cx="28" cy="27" r="3.4" fill="#fff" />
    </svg>
  );
}

function GoogleG({ size = 26 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 48 48" aria-hidden="true">
      <path fill="#4285F4" d="M45.12 24.5c0-1.56-.14-3.06-.4-4.5H24v8.51h11.84c-.51 2.75-2.06 5.08-4.39 6.64v5.52h7.11c4.16-3.83 6.56-9.47 6.56-16.17z" />
      <path fill="#34A853" d="M24 46c5.94 0 10.92-1.97 14.56-5.33l-7.11-5.52c-1.97 1.32-4.49 2.1-7.45 2.1-5.73 0-10.58-3.87-12.31-9.07H4.34v5.7C7.96 41.07 15.4 46 24 46z" />
      <path fill="#FBBC05" d="M11.69 28.18A13.2 13.2 0 0 1 11 24c0-1.45.25-2.86.69-4.18v-5.7H4.34A21.98 21.98 0 0 0 2 24c0 3.55.85 6.91 2.34 9.88z" />
      <path fill="#EA4335" d="M24 10.75c3.23 0 6.13 1.11 8.41 3.29l6.31-6.31C34.91 4.18 29.93 2 24 2 15.4 2 7.96 6.93 4.34 14.12l7.35 5.7c1.73-5.2 6.58-9.07 12.31-9.07z" />
    </svg>
  );
}

// Your real Polaris icon, original colors, rendered as a plain static image.
function LogoMark({ className = "" }) {
  return <img className={"logo-icon " + className} src="/assets/polaris-icon.svg" alt="Polaris Landscape" />;
}

// FadeRotate, dissolves through a list of phrases: hold, fade/blur out, swap, fade in.
// Plain React + CSS (no framer-motion); respects prefers-reduced-motion.
function FadeRotate({ phrases, holdTime = 1800, fadeTime = 380, className = "" }) {
  const list = Array.isArray(phrases) ? phrases : [phrases];
  const reduce = typeof window !== "undefined"
    && window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
  const [idx, setIdx] = React.useState(0);
  const [out, setOut] = React.useState(false);

  React.useEffect(() => {
    if (list.length < 2) return;
    let t;
    if (reduce) {
      // No fade for reduced motion, just swap phrases in place.
      t = setTimeout(() => setIdx((i) => (i + 1) % list.length), holdTime + fadeTime * 2);
    } else if (!out) {
      t = setTimeout(() => setOut(true), holdTime);
    } else {
      t = setTimeout(() => {
        setIdx((i) => (i + 1) % list.length);
        setOut(false);
      }, fadeTime);
    }
    return () => clearTimeout(t);
  }, [out, idx, reduce, holdTime, fadeTime, list.length]);

  return (
    <span className={`fade-rotate${out ? " out" : ""} ${className}`} aria-live="polite"
      style={{ transitionDuration: fadeTime + "ms" }}>
      {list[idx % list.length]}
    </span>
  );
}
const Typewriter = FadeRotate; // back-compat alias for the old component name

function useReveal() {
  React.useEffect(() => {
    const els = document.querySelectorAll(".reveal");
    if (!("IntersectionObserver" in window)) { els.forEach(e => e.classList.add("in")); return; }
    const io = new IntersectionObserver((ents) => {
      ents.forEach(e => { if (e.isIntersecting) { e.target.classList.add("in"); io.unobserve(e.target); } });
    }, { rootMargin: "0px 0px -8% 0px", threshold: 0.08 });
    els.forEach(e => io.observe(e));
    return () => io.disconnect();
  });
}

Object.assign(window, { Icon, Stars, Mark, LogoMark, GoogleG, FadeRotate, Typewriter, useReveal });
