// atoms.jsx — shared building blocks
// Placeholders, icons, nav, footer

const { useState, useEffect, useRef } = React;

// ── Placeholder block (instead of imagery) ──────────────────────────────
function PH({ label = '', tone = 'default', children, style, className = '', icon = null, src = null, alt = '' }) {
  if (src) {
    return (
      <div className={`ph has-img ${className}`} style={style}>
        <img src={src} alt={alt || label} loading="lazy" />
        {children}
      </div>
    );
  }
  return (
    <div className={`ph ${className}`} data-label={label} style={style}>
      {icon && <div className="ph-icon">{icon}</div>}
      {children}
    </div>
  );
}

// Mountain SVG icon for placeholders
const MountainIcon = () => (
  <svg viewBox="0 0 100 100" fill="none" stroke="currentColor" strokeWidth="1.5">
    <path d="M5 80 L30 35 L45 55 L60 25 L75 50 L95 80 Z" />
    <path d="M30 35 L40 50 M60 25 L70 45" opacity="0.5" />
  </svg>
);

// ── Icons ───────────────────────────────────────────────────────────────
const Ico = {
  arrow: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M5 12h14M13 5l7 7-7 7"/></svg>,
  arrowSm: <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M5 12h14M13 5l7 7-7 7"/></svg>,
  wifi: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M5 12a10 10 0 0114 0M8.5 15.5a5 5 0 017 0M12 19h.01"/></svg>,
  parking: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><rect x="4" y="4" width="16" height="16" rx="2"/><path d="M10 16V8h3a3 3 0 010 6h-3"/></svg>,
  pet: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><circle cx="11" cy="4" r="2"/><circle cx="18" cy="8" r="2"/><circle cx="4" cy="8" r="2"/><circle cx="6.5" cy="14" r="2"/><path d="M9 14c0 4 2 7 5 7s5-3 5-7c0-3-2-5-5-5s-5 2-5 5z"/></svg>,
  pool: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M2 18c2 0 2-1 5-1s3 1 5 1 2-1 5-1 3 1 5 1M2 14c2 0 2-1 5-1s3 1 5 1 2-1 5-1 3 1 5 1M7 13V6a2 2 0 014 0M13 13V6a2 2 0 014 0"/></svg>,
  fire: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M12 2c3 4 5 7 5 11a5 5 0 01-10 0c0-2 1-3 2-4-1 4 2 5 3 4 0-3-3-5 0-11z"/></svg>,
  kitchen: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M3 10h18M7 7v.01M11 7v.01"/></svg>,
  tv: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><rect x="3" y="5" width="18" height="13" rx="2"/><path d="M8 21h8"/></svg>,
  ac: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M3 12h18M12 3v18M5 5l14 14M19 5L5 19"/></svg>,
  sauna: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M4 20h16M6 16h12M8 12c0-2 1-3 0-5M12 12c0-2 1-3 0-5M16 12c0-2 1-3 0-5"/></svg>,
  view: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><circle cx="12" cy="12" r="3"/><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7z"/></svg>,
  bbq: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M4 7h16l-2 7a4 4 0 01-4 3h-4a4 4 0 01-4-3L4 7zM12 17v4M9 7V3M12 7V3M15 7V3"/></svg>,
  baby: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><circle cx="12" cy="8" r="4"/><path d="M9 9v.01M15 9v.01M9 12c1 1 4 1 6 0M5 22c0-4 3-7 7-7s7 3 7 7"/></svg>,
  bike: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><circle cx="5" cy="17" r="4"/><circle cx="19" cy="17" r="4"/><path d="M5 17l4-10h4l4 10M9 7h4"/></svg>,
  cave: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M3 21V13a9 9 0 0118 0v8h-5v-5a4 4 0 00-8 0v5H3z"/></svg>,
  ski: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M3 19l18-7M5 17l3-3M9 13l3-3M13 9l3-3M19 7l-2 2M3 22h18"/></svg>,
  hike: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><circle cx="14" cy="5" r="2"/><path d="M14 21v-7l-3-1-2 5M14 14l4 3v4M9 13l-4-2M11 9l-1-3"/></svg>,
  water: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M12 3s7 8 7 13a7 7 0 01-14 0c0-5 7-13 7-13z"/></svg>,
  food: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M3 11h18M3 11l2 9h14l2-9M7 11V6a5 5 0 0110 0v5"/></svg>,
  star: <svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 2l3 7h7l-5.5 4.5L18 21l-6-4-6 4 1.5-7.5L2 9h7z"/></svg>,
  ig: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><rect x="3" y="3" width="18" height="18" rx="5"/><circle cx="12" cy="12" r="4"/><circle cx="17.5" cy="6.5" r="1" fill="currentColor"/></svg>,
  fb: <svg viewBox="0 0 24 24" fill="currentColor"><path d="M14 9V6.5c0-.8.5-1.5 1.5-1.5H18V2h-3.5C12 2 10 4 10 6.5V9H7v3h3v10h4V12h3l1-3h-4z"/></svg>,
  phone: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M22 16.9v3a2 2 0 01-2.2 2 19.8 19.8 0 01-8.6-3.1 19.5 19.5 0 01-6-6A19.8 19.8 0 012.1 4.2 2 2 0 014.1 2h3a2 2 0 012 1.7c.1.9.3 1.8.6 2.6a2 2 0 01-.5 2.1l-1.3 1.3a16 16 0 006 6l1.3-1.3a2 2 0 012.1-.5c.8.3 1.7.5 2.6.6a2 2 0 011.7 2z"/></svg>,
  mail: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 7l9 6 9-6"/></svg>,
  pin: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M12 22s8-9 8-14a8 8 0 00-16 0c0 5 8 14 8 14z"/><circle cx="12" cy="8" r="3"/></svg>,
  check: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M5 12l5 5L20 7"/></svg>,
};

// ── Top nav ─────────────────────────────────────────────────────────────
function TopNav({ current, onNav, lang, setLang, scrolled }) {
  const items = [
    { id: 'home', label: 'Domov' },
    { id: 'regiony', label: 'Regióny' },
    { id: 'atrakcie', label: 'Atrakcie' },
    { id: 'sluzby', label: 'Služby & Akcie' },
    { id: 'about', label: 'O nás' },
    { id: 'kontakt', label: 'Kontakt' },
  ];
  return (
    <nav className={`nav ${scrolled ? 'scrolled' : ''}`}>
      <a className="nav-logo" href="#home" onClick={(e) => { e.preventDefault(); onNav('home'); }}>
        Liptove
      </a>
      <ul className="nav-links">
        {items.map((it) => (
          <li key={it.id}>
            <a
              href={`#${it.id}`}
              className={`nav-link ${current === it.id ? 'active' : ''}`}
              onClick={(e) => { e.preventDefault(); onNav(it.id); }}
            >{it.label}</a>
          </li>
        ))}
      </ul>
      <div className="nav-right">
        <div className="lang-switch">
          {['SK', 'EN', 'DE', 'PL'].map((l) => (
            <button key={l} className={l === lang ? 'on' : ''} onClick={() => setLang(l)}>{l}</button>
          ))}
        </div>
        <button className="btn btn-primary btn-sm" onClick={() => onNav('object')}>
          Rezervovať
        </button>
      </div>
    </nav>
  );
}

// ── Footer ──────────────────────────────────────────────────────────────
function Footer({ onNav }) {
  const link = (id, label) => (
    <a href={`#${id}`} onClick={(e) => { e.preventDefault(); onNav(id); }}>{label}</a>
  );
  return (
    <footer className="footer">
      <div className="footer-top">
        <div>
          <div className="nav-logo" style={{ fontSize: 44, marginBottom: 18 }}>Liptove</div>
          <p className="lead" style={{ fontSize: 15, maxWidth: '36ch', margin: 0 }}>
            Pokoj. Výhľad. Liptov.<br/>
            Apartmány a zruby v najkrajších kútoch slovenských hôr.
          </p>
          <div style={{ display: 'flex', gap: 12, marginTop: 24 }}>
            <a href="#" style={{ width: 38, height: 38, borderRadius: 999, border: '1px solid var(--line-2)', display: 'grid', placeItems: 'center' }}>
              <span style={{ width: 16, height: 16, display: 'block' }}>{Ico.ig}</span>
            </a>
            <a href="#" style={{ width: 38, height: 38, borderRadius: 999, border: '1px solid var(--line-2)', display: 'grid', placeItems: 'center' }}>
              <span style={{ width: 16, height: 16, display: 'block' }}>{Ico.fb}</span>
            </a>
          </div>
        </div>
        <div>
          <h4>Regióny</h4>
          <ul>
            <li>{link('region-jan', 'Liptovský Ján')}</li>
            <li>{link('region-dem', 'Demänovská Dolina')}</li>
            <li>{link('coming', 'Bešeňová — pripravujeme')}</li>
          </ul>
        </div>
        <div>
          <h4>Objekty</h4>
          <ul>
            <li>{link('object', 'Apartmány Stagnum')}</li>
            <li>{link('object', 'Zruby v Jáne')}</li>
            <li>{link('object', 'Apartmány Capra')}</li>
            <li>{link('coming', 'Mitošiny')}</li>
          </ul>
        </div>
        <div>
          <h4>Informácie</h4>
          <ul>
            <li>{link('sluzby', 'Služby & Akcie')}</li>
            <li>{link('atrakcie', 'Atrakcie')}</li>
            <li>{link('about', 'O nás')}</li>
            <li>{link('kontakt', 'Kontakt')}</li>
            <li><a href="#">Obchodné podmienky</a></li>
            <li><a href="#">Ochrana osobných údajov</a></li>
          </ul>
        </div>
      </div>
      <div className="footer-bottom">
        <div>© 2026 Liptove. Všetky práva vyhradené.</div>
        <div>SK · EN · DE · PL</div>
      </div>
    </footer>
  );
}

// ── Section head helper ────────────────────────────────────────────────
function SectionHead({ eyebrow, title, lead, action }) {
  return (
    <div className="section-head">
      <div style={{ maxWidth: '32ch' }}>
        {eyebrow && <div className="eyebrow" style={{ marginBottom: 20 }}>{eyebrow}</div>}
        <h2 className="h2" style={{ margin: 0 }}>{title}</h2>
      </div>
      {(lead || action) && (
        <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-end', gap: 18, maxWidth: '44ch', textAlign: 'right' }}>
          {lead && <p className="lead" style={{ margin: 0, textAlign: 'right' }}>{lead}</p>}
          {action}
        </div>
      )}
    </div>
  );
}

// expose
Object.assign(window, { PH, Ico, MountainIcon, TopNav, Footer, SectionHead });
