// === Wrap Station — Reusable bits ===

// Inline SVG icons (no emoji, no external lib)
const Icon = {
  Arrow: ({ size = 16 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg>
  ),
  ArrowUp: ({ size = 16 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><line x1="7" y1="17" x2="17" y2="7"/><polyline points="7 7 17 7 17 17"/></svg>
  ),
  Plus: ({ size = 14 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
  ),
  Star: ({ size = 14 }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="currentColor"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>
  ),
  Phone: () => (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="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.72 12.84 12.84 0 0 0 .7 2.81 2 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-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"/></svg>
  ),
  Map: () => (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" 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>
  ),
  Mail: () => (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/><polyline points="22,6 12,13 2,6"/></svg>
  ),
  Clock: () => (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
  ),
  Check: ({ size = 18 }) => (
    <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>
  ),
  Instagram: () => (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="2" y="2" width="20" height="20" rx="5"/><path d="M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z"/><line x1="17.5" y1="6.5" x2="17.51" y2="6.5"/></svg>
  ),
  YouTube: () => (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M22.54 6.42a2.78 2.78 0 0 0-1.94-2C18.88 4 12 4 12 4s-6.88 0-8.6.46a2.78 2.78 0 0 0-1.94 2A29 29 0 0 0 1 11.75a29 29 0 0 0 .46 5.33A2.78 2.78 0 0 0 3.4 19c1.72.46 8.6.46 8.6.46s6.88 0 8.6-.46a2.78 2.78 0 0 0 1.94-2 29 29 0 0 0 .46-5.25 29 29 0 0 0-.46-5.33z"/><polygon points="9.75 15.02 15.5 11.75 9.75 8.48 9.75 15.02"/></svg>
  ),
  TikTok: () => (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor"><path d="M19.59 6.69a4.83 4.83 0 0 1-3.77-4.25V2h-3.45v13.67a2.89 2.89 0 0 1-5.2 1.74 2.89 2.89 0 0 1 2.31-4.64 2.93 2.93 0 0 1 .88.13V9.4a6.84 6.84 0 0 0-1-.05A6.33 6.33 0 0 0 5.8 20.1a6.34 6.34 0 0 0 10.86-4.43V8.3a8.16 8.16 0 0 0 4.77 1.52v-3.4a4.85 4.85 0 0 1-1.84-.27z"/></svg>
  ),
  Facebook: () => (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor"><path d="M22 12.06C22 6.5 17.52 2 12 2S2 6.5 2 12.06c0 5 3.66 9.15 8.44 9.94v-7.03H7.9v-2.9h2.54V9.85c0-2.52 1.49-3.91 3.77-3.91 1.09 0 2.24.2 2.24.2v2.47h-1.26c-1.24 0-1.63.77-1.63 1.56v1.87h2.77l-.44 2.9h-2.33V22c4.78-.79 8.44-4.94 8.44-9.94z"/></svg>
  ),
};

// Reveal-on-scroll wrapper
function Reveal({ children, delay = 0, className = "" }) {
  const ref = React.useRef(null);
  React.useEffect(() => {
    const el = ref.current;
    if (!el) return;
    let fired = false;
    const show = () => {
      if (fired) return;
      fired = true;
      setTimeout(() => el.classList.add("visible"), delay);
    };
    // Fallback: ensure visibility within ~600ms even if observer never fires
    const fallback = setTimeout(show, 600);
    const io = new IntersectionObserver(
      ([entry]) => {
        if (entry.isIntersecting) {
          clearTimeout(fallback);
          show();
          io.disconnect();
        }
      },
      { threshold: 0, rootMargin: "0px 0px -10% 0px" }
    );
    io.observe(el);
    // If element is already in viewport on mount, fire immediately
    const rect = el.getBoundingClientRect();
    if (rect.top < window.innerHeight && rect.bottom > 0) {
      clearTimeout(fallback);
      show();
      io.disconnect();
    }
    return () => { clearTimeout(fallback); io.disconnect(); };
  }, [delay]);
  return (
    <div ref={ref} className={`reveal ${className}`}>
      {children}
    </div>
  );
}

// Placeholder image (used until user uploads imagery)
function Placeholder({ label, ratio }) {
  return (
    <div className="placeholder" style={ratio ? { aspectRatio: ratio } : null}>
      <span className="placeholder-label">{label}</span>
    </div>
  );
}

// Hero car SVG illustration — sleek silhouette so the hero looks complete pre-photo
function HeroCarSilhouette() {
  return (
    <svg className="hero-car" viewBox="0 0 1100 360" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
      <defs>
        <linearGradient id="carBody" x1="0" x2="0" y1="0" y2="1">
          <stop offset="0%" stopColor="#2a2a2f"/>
          <stop offset="50%" stopColor="#161618"/>
          <stop offset="100%" stopColor="#0a0a0b"/>
        </linearGradient>
        <linearGradient id="carHighlight" x1="0" x2="1" y1="0" y2="0">
          <stop offset="0%" stopColor="rgba(255,106,44,0)"/>
          <stop offset="50%" stopColor="rgba(255,106,44,0.6)"/>
          <stop offset="100%" stopColor="rgba(255,106,44,0)"/>
        </linearGradient>
        <linearGradient id="windowGrad" x1="0" x2="0" y1="0" y2="1">
          <stop offset="0%" stopColor="#0a0a0b"/>
          <stop offset="100%" stopColor="#1a1a1f"/>
        </linearGradient>
      </defs>
      {/* Shadow */}
      <ellipse cx="550" cy="320" rx="480" ry="14" fill="#000" opacity="0.5"/>
      {/* Body */}
      <path d="M 80 260 Q 140 200 280 180 Q 360 130 480 120 L 700 120 Q 820 130 880 180 Q 980 200 1020 240 L 1020 280 Q 1020 295 1005 295 L 90 295 Q 75 295 75 280 Z"
        fill="url(#carBody)" stroke="#2a2a2f" strokeWidth="1"/>
      {/* Windows */}
      <path d="M 320 185 Q 380 145 480 138 L 690 138 Q 800 145 850 185 L 800 200 L 380 200 Z"
        fill="url(#windowGrad)" stroke="#1a1a1f" strokeWidth="1"/>
      {/* Window divider */}
      <line x1="585" y1="138" x2="585" y2="200" stroke="#0a0a0b" strokeWidth="2"/>
      {/* Door line */}
      <line x1="585" y1="200" x2="585" y2="270" stroke="#000" strokeWidth="1.5" opacity="0.5"/>
      {/* Highlight strip */}
      <rect x="100" y="225" width="900" height="2" fill="url(#carHighlight)" opacity="0.7"/>
      {/* Wheels */}
      <circle cx="260" cy="290" r="48" fill="#0a0a0b" stroke="#2a2a2f" strokeWidth="1"/>
      <circle cx="260" cy="290" r="32" fill="#1a1a1f"/>
      <circle cx="260" cy="290" r="18" fill="#0a0a0b" stroke="#ff6a2c" strokeWidth="0.5" opacity="0.6"/>
      <circle cx="840" cy="290" r="48" fill="#0a0a0b" stroke="#2a2a2f" strokeWidth="1"/>
      <circle cx="840" cy="290" r="32" fill="#1a1a1f"/>
      <circle cx="840" cy="290" r="18" fill="#0a0a0b" stroke="#ff6a2c" strokeWidth="0.5" opacity="0.6"/>
      {/* Headlight */}
      <ellipse cx="1010" cy="225" rx="14" ry="6" fill="#ffb27a" opacity="0.8"/>
    </svg>
  );
}

Object.assign(window, { Icon, Reveal, Placeholder, HeroCarSilhouette });
