/* Us Para Você — atoms & icons */
const { useState, useEffect, useRef } = React;

/* ---------- Inline icon set (stroke-based, lucide-ish) ---------- */
const Icon = {
  Apple: ({ size = 26 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
      <path d="M16.365 1.43c0 1.14-.41 2.18-1.23 3.13-.99 1.13-2.18 1.79-3.47 1.69-.16-1.13.39-2.31 1.18-3.18.86-.96 2.18-1.66 3.52-1.65zM21 17.07c-.6 1.4-1.31 2.79-2.34 4.05-1.02 1.24-2.27 2.78-3.82 2.79-1.51.02-1.9-.97-3.94-.96-2.05.01-2.49.97-4 .94-1.55-.04-2.74-1.43-3.76-2.66-2.86-3.45-3.13-7.5-1.39-9.65 1.24-1.53 3.19-2.43 5.03-2.46 1.57-.03 3.05.97 3.94.97.89 0 2.81-1.18 4.74-1 1.54.07 3.04.7 4 2.04-3.55 2.07-2.97 7.34.54 9.94z"/>
    </svg>
  ),
  Play: ({ size = 26 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" aria-hidden="true">
      <defs>
        <linearGradient id="gp1" x1="0" y1="0" x2="1" y2="1">
          <stop offset="0" stopColor="#00C6FF"/><stop offset="1" stopColor="#0072FF"/>
        </linearGradient>
        <linearGradient id="gp2" x1="0" y1="0" x2="1" y2="0">
          <stop offset="0" stopColor="#FFE000"/><stop offset="1" stopColor="#FFA000"/>
        </linearGradient>
        <linearGradient id="gp3" x1="0" y1="0" x2="1" y2="1">
          <stop offset="0" stopColor="#FF3A44"/><stop offset="1" stopColor="#C31162"/>
        </linearGradient>
        <linearGradient id="gp4" x1="0" y1="0" x2="1" y2="1">
          <stop offset="0" stopColor="#00A87E"/><stop offset="1" stopColor="#008F5A"/>
        </linearGradient>
      </defs>
      <path d="M3.6 2.5c-.4.3-.6.8-.6 1.4v16.2c0 .6.2 1.1.6 1.4l9-9-9-10z" fill="url(#gp1)"/>
      <path d="M16.5 8.4 13.4 12l3.1 3.6 4-2.3c1-.6 1-2 0-2.6l-4-2.3z" fill="url(#gp2)"/>
      <path d="M3.6 2.5 13.4 12l3.1-3.6L4.7 1.7c-.4-.2-.8-.2-1.1.1z" fill="url(#gp3)"/>
      <path d="m13.4 12-9.8 9.5c.3.3.7.3 1.1.1l11.8-6.7-3.1-2.9z" fill="url(#gp4)"/>
    </svg>
  ),
  Check: ({ size = 16 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
  ),
  Shield: ({ size = 22 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/><path d="m9 12 2 2 4-4"/></svg>
  ),
  ChatHeart: ({ size = 22 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8z"/></svg>
  ),
  Lock: ({ size = 22 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>
  ),
  Pkg: ({ size = 22 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M16.5 9.4 7.55 4.24"/><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><path d="m3.27 6.96 8.73 5.05 8.73-5.05M12 22.08V12"/></svg>
  ),
  Camera: ({ size = 22 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="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"/><circle cx="12" cy="13" r="4"/></svg>
  ),
  Boxes: ({ size = 22 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42z"/><path d="M7 16.5l-4.74-2.85M7 16.5l5-3M7 16.5v5.17"/><path d="M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3z"/><path d="M17 16.5l-5-3M17 16.5l4.74-2.85M17 16.5v5.17"/><path d="M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0z"/><path d="M12 8 7.26 5.15M12 8l4.74-2.85M12 8v5.5"/></svg>
  ),
  Sparkle: ({ size = 22 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M12 3v3M12 18v3M3 12h3M18 12h3M5.6 5.6l2.1 2.1M16.3 16.3l2.1 2.1M5.6 18.4l2.1-2.1M16.3 7.7l2.1-2.1"/><circle cx="12" cy="12" r="3"/></svg>
  ),
  Bag: ({ size = 22 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M6 2 3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4zM3 6h18M16 10a4 4 0 0 1-8 0"/></svg>
  ),
  Card: ({ size = 22 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><rect x="2" y="5" width="20" height="14" rx="2"/><line x1="2" y1="10" x2="22" y2="10"/><line x1="6" y1="15" x2="10" y2="15"/></svg>
  ),
  Users: ({ size = 22 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75"/></svg>
  ),
  Arrow: ({ size = 16 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg>
  ),
  Plus: ({ size = 18 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
  ),
  Pin: ({ size = 14 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"/><circle cx="12" cy="10" r="3"/></svg>
  ),
  Whats: ({ size = 30 }) => (
    <svg width={size} height={size} viewBox="0 0 32 32" fill="currentColor" aria-hidden="true">
      <path d="M16.005 4C9.382 4 4 9.382 4 16.005c0 2.115.553 4.18 1.602 6.001L4 28l6.146-1.575a11.943 11.943 0 0 0 5.86 1.51h.005C22.633 27.935 28 22.567 28 15.94 28 9.314 22.633 4 16.005 4zm6.97 17.123c-.297.834-1.715 1.586-2.4 1.69-.612.092-1.387.13-2.24-.14-.516-.165-1.182-.385-2.034-.752-3.578-1.546-5.916-5.149-6.094-5.387-.18-.238-1.46-1.94-1.46-3.7 0-1.76.924-2.625 1.252-2.984.328-.359.715-.45.953-.45.239 0 .478.003.687.012.22.01.516-.084.806.615.297.715 1.014 2.475 1.103 2.654.09.18.149.388.03.626-.119.239-.179.387-.358.595-.18.209-.378.467-.54.626-.18.18-.367.374-.158.733.209.358.93 1.535 1.997 2.487 1.371 1.225 2.527 1.604 2.886 1.783.358.18.567.149.776-.09.209-.238.894-1.043 1.133-1.4.238-.358.477-.298.806-.18.328.12 2.09.987 2.448 1.166.358.18.597.27.687.42.09.149.09.864-.207 1.696z"/>
    </svg>
  )
};

/* ---------- Brand mark ---------- */
function BrandMark({ onDark = false }) {
  return (
    <a href="#top" className="brand-mark" aria-label="Us Para Você — início">
      <img className="mark-img" src="assets/logo-uspv-transparent.png" alt="" />
      <span className="mark-name">
        <span className="n1" style={{ color: onDark ? "white" : undefined }}>Us Para Você</span>
        <span className="n2" style={{ color: onDark ? "rgba(255,255,255,.55)" : undefined }}>Personal Shopper · USA → BR</span>
      </span>
    </a>
  );
}

/* ---------- App store badges (custom, not exact official) ---------- */
function StoreBadge({ kind }) {
  const isApple = kind === "apple";
  const url = isApple 
    ? "https://apps.apple.com/br/app/us-para-voc%C3%AA/id6448966153" 
    : "https://play.google.com/store/apps/details?id=com.company.usparavoce";

  return (
    <a 
      className="store-badge" 
      href={url} 
      target="_blank" 
      rel="noopener noreferrer" 
      aria-label={isApple ? "Baixar na App Store" : "Baixar no Google Play"}
    >
      <span className="sb-icon">{isApple ? <Icon.Apple /> : <Icon.Play />}</span>
      <span className="sb-text">
        <span className="sb-top">{isApple ? "Baixar na" : "Disponível no"}</span>
        <span className="sb-bot">{isApple ? "App Store" : "Google Play"}</span>
      </span>
    </a>
  );
}

/* ---------- Reveal-on-scroll wrapper ---------- */
function Reveal({ children, delay = 0, as: Tag = "div", className = "", style = {} }) {
  const ref = useRef(null);
  useEffect(() => {
    const el = ref.current;
    if (!el) return;
    const io = new IntersectionObserver(([entry]) => {
      if (entry.isIntersecting) {
        el.classList.add("in");
        io.disconnect();
      }
    }, { threshold: 0.15, rootMargin: "0px 0px -60px 0px" });
    io.observe(el);
    return () => io.disconnect();
  }, []);
  return (
    <Tag ref={ref} className={`reveal ${className}`} data-d={delay} style={style}>
      {children}
    </Tag>
  );
}

Object.assign(window, { Icon, BrandMark, StoreBadge, Reveal });
