/* global React */
const { useState } = React;

// ============== ICONS ==============
const Ico = {
  auction: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M3 21h18M5 17l8-8M9 13l4 4M14 4l6 6M11 7l6 6" /></svg>,
  truck: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M2 7h11v9H2zM13 11h5l3 3v2h-8zM6 19a2 2 0 100-4 2 2 0 000 4zM18 19a2 2 0 100-4 2 2 0 000 4z" /></svg>,
  doc: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M14 3H6a2 2 0 00-2 2v14a2 2 0 002 2h12a2 2 0 002-2V9zM14 3v6h6M9 13h6M9 17h6" /></svg>,
  ship: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M3 18s1 2 5 2 5-2 9-2c2 0 4 2 4 2M5 18l-2-7h18l-2 7M8 11V5h8v6M12 5V2" /></svg>,
  shield: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M12 2l8 3v7c0 5-4 9-8 10-4-1-8-5-8-10V5z M9 12l2 2 4-4" /></svg>,
  clock: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><circle cx="12" cy="12" r="9" /><path d="M12 7v5l3 2" /></svg>,
  refresh: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M3 12a9 9 0 0115-6.7L21 8M21 3v5h-5M21 12a9 9 0 01-15 6.7L3 16M3 21v-5h5" /></svg>,
  lock: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><rect x="4" y="11" width="16" height="10" rx="2" /><path d="M8 11V7a4 4 0 018 0v4" /></svg>,
  arrow: (p) => <svg className="arrow" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.8" {...p}><path d="M3 13L13 3M5 3h8v8" /></svg>,
  phone: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M22 16.92v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07 19.5 19.5 0 01-6-6 19.79 19.79 0 01-3.07-8.67A2 2 0 014.11 2h3a2 2 0 012 1.72c.13.96.36 1.9.7 2.81a2 2 0 01-.45 2.11L8.09 9.91a16 16 0 006 6l1.27-1.27a2 2 0 012.11-.45c.91.34 1.85.57 2.81.7A2 2 0 0122 16.92z" /></svg>,
  pin: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M21 10c0 7-9 13-9 13S3 17 3 10a9 9 0 0118 0z" /><circle cx="12" cy="10" r="3" /></svg>,
  mail: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><rect x="3" y="5" width="18" height="14" rx="2" /><path d="M3 7l9 6 9-6" /></svg>,
  yt: (p) => <svg viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M23 7s-.2-1.6-.9-2.3c-.8-.9-1.7-.9-2.1-1C16.9 3.5 12 3.5 12 3.5s-4.9 0-8 .2c-.4.1-1.3.1-2.1 1C1.2 5.4 1 7 1 7S.8 8.9.8 10.7v1.6c0 1.9.2 3.7.2 3.7s.2 1.6.9 2.3c.8.9 1.9.9 2.4 1 1.7.2 7.7.2 7.7.2s4.9 0 8-.2c.4-.1 1.3-.1 2.1-1 .7-.7.9-2.3.9-2.3s.2-1.9.2-3.7v-1.6C23.2 8.9 23 7 23 7zM9.7 14.4V8.6l6.4 2.9-6.4 2.9z" /></svg>,
  play: (p) => <svg viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M8 5v14l11-7z" /></svg>,
  globe: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><circle cx="12" cy="12" r="9" /><path d="M3 12h18M12 3a14 14 0 010 18M12 3a14 14 0 000 18" /></svg>,
  cash: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><rect x="2" y="6" width="20" height="12" rx="2" /><circle cx="12" cy="12" r="3" /></svg>,
  users: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M16 21v-2a4 4 0 00-4-4H6a4 4 0 00-4 4v2M22 21v-2a4 4 0 00-3-3.87" /><circle cx="9" cy="7" r="4" /><path d="M16 3.13a4 4 0 010 7.75" /></svg>,
  parts: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M14.7 6.3a1 1 0 000 1.4l1.6 1.6a1 1 0 001.4 0l3.77-3.77a6 6 0 01-7.94 7.94l-6.91 6.91a2.12 2.12 0 01-3-3l6.91-6.91a6 6 0 017.94-7.94l-3.76 3.76z" /></svg>
};

// ============== TOP STRIP (very thin top bar, like sample) ==============
function TopStrip({ lang, setLang }) {
  const t = window.useT();
  return (
    <div className="topstrip">
      <div className="topstrip-inner">
        <div className="topstrip-l">
          <span><Ico.clock style={{ width: 13, height: 13, verticalAlign: '-2px' }} /> {t('hours')}</span>
        </div>
        <div className="topstrip-r">
          <a href="#dealer" className="ts-pill">{t('become_dealer')}</a>
          <a href="#account" className="ts-pill ts-pill-ghost">{t('account')}</a>
          <LangPill lang={lang} setLang={setLang} />
        </div>
      </div>
    </div>);

}

function LangPill({ lang, setLang }) {
  const langs = window.SUOMI_LANGS || ["EN", "RU", "LT", "PL", "LV"];
  return (
    <div className="lang-pill">
      {langs.map((l) =>
      <button key={l} className={"lang-btn " + (lang === l ? "active" : "")} onClick={() => setLang(l)}>{l}</button>
      )}
    </div>);

}

// ============== NAV (caps menu, like sample) ==============
function Nav() {
  const t = window.useT();
  return (
    <nav className="nav">
      <div className="nav-inner">
        <a href="#" className="logo">
          <span className="logo-mark">
            <svg viewBox="0 0 18 11" width="22" height="14"><rect width="18" height="11" fill="#fff" /><rect x="5" width="3" height="11" fill="currentColor" /><rect y="4" width="18" height="3" fill="currentColor" /></svg>
          </span>
          <span><span className="suo">SUOMI</span><span className="mot">motors</span></span>
        </a>
        <div className="nav-links">
          <a href="#catalog">{t('nav_catalog')}</a>
          <a href="#services">{t('nav_services')}</a>
          <a href="#calc">{t('nav_calc')}</a>
          <a href="#cases">{t('nav_cases')}</a>
          <a href="#contact">{t('nav_contact')}</a>
        </div>
        <div className="nav-cta">
          <a href="#contact" className="nav-phone">{t('nav_contact_us')}</a>
        </div>
      </div>
    </nav>);

}

// ============== HERO — mirror of sample: photo right, headline + bullets + 2 CTA ==============
function Hero() {
  const t = window.useT();
  const bullets = [t('hero_b1'), t('hero_b2'), t('hero_b3'), t('hero_b4')];
  return (
    <section className="hero">
      <div className="container">
        <div className="hero-grid">
          <div className="hero-left">
            <span className="eyebrow">{t('hero_eyebrow')}</span>
            <h1>{t('hero_h1_l1')}<br />{t('hero_h1_l2')}<br />{t('hero_h1_l3')}</h1>
            <p className="hero-sub">{t('hero_sub')}</p>
            <ul className="hero-bullets">
              {bullets.map((b, i) =>
              <li key={i}>
                  <span className="hb-check">
                    <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="2.4"><path d="M3 8.5L6.5 12L13 4.5" strokeLinecap="round" strokeLinejoin="round" /></svg>
                  </span>
                  <span>{b}</span>
                </li>
              )}
            </ul>
            <div className="hero-cta">
              <a href="#calc" className="btn btn-primary">{t('hero_cta1')} <Ico.arrow /></a>
              <a href="#contact" className="btn btn-secondary">{t('hero_cta2')}</a>
            </div>
          </div>
          <div className="hero-right">
            <div className="hero-photo wide-h has-image">
              <img src="assets/hero-ferry.png" alt={t('hero_img_alt')} />
              <div className="hero-photo-tag">
                <span className="flag-fi">
                  <svg viewBox="0 0 18 11" width="18" height="11"><rect width="18" height="11" fill="#fff" /><rect x="5" width="3" height="11" fill="#003580" /><rect y="4" width="18" height="3" fill="#003580" /></svg>
                </span>
                <span>{t('hero_tag')}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>);

}

// ============== SERVICES STRIP — 3 services in dark band ==============
function ServicesStrip() {
  const t = window.useT();
  const items = [
    { ic: <Ico.truck />, t: t('strip_s1_t'), d: t('strip_s1_d') },
    { ic: <Ico.doc />, t: t('strip_s2_t'), d: t('strip_s2_d') },
    { ic: <Ico.ship />, t: t('strip_s3_t'), d: t('strip_s3_d') }
  ];
  return (
    <section className="strip-services">
      <div className="container">
        <div className="services-strip">
          {items.map((it, i) =>
          <div className="service-cell" key={i}>
              <div className="service-icon">{it.ic}</div>
              <div>
                <h4>{it.t}</h4>
                <p>{it.d}</p>
              </div>
            </div>
          )}
        </div>
      </div>
    </section>);

}

// ============== "BIG SERVICES" — large heading + text + photo right ==============
function ServicesBig() {
  const t = window.useT();
  return (
    <section id="services" className="big-services">
      <div className="container">
        <div className="bs-grid">
          <div className="bs-text">
            <span className="eyebrow">{t('big_eyebrow')}</span>
            <h2>{t('big_h2_l1')}<br />{t('big_h2_l2')}</h2>
            <p className="bs-lead">{t('big_lead1')}</p>
            <p className="bs-lead">{t('big_lead2')}</p>
          </div>
          <div className="bs-photo">
            <div className="hero-photo big has-image">
              <img src="assets/services-warehouse.png" alt={t('big_img_alt')} />
            </div>
          </div>
        </div>
      </div>
    </section>);

}

// ============== FACT GRID 3×2 — 6 cells ==============
function FactGrid() {
  const t = window.useT();
  const facts = [
    { ic: <Ico.lock />, t: t('f1_t'), d: t('f1_d') },
    { ic: <Ico.auction />, t: t('f2_t'), d: t('f2_d') },
    { ic: <Ico.refresh />, t: t('f3_t'), d: t('f3_d') },
    { ic: <Ico.clock />, t: t('f4_t'), d: t('f4_d') },
    { ic: <Ico.cash />, t: t('f5_t'), d: t('f5_d') },
    { ic: <Ico.shield />, t: t('f6_t'), d: t('f6_d') }
  ];
  return (
    <section className="fact-grid-section">
      <div className="container">
        <div className="fact-grid">
          {facts.map((f, i) =>
          <div className="fact-cell" key={i}>
              <div className="fact-icon">{f.ic}</div>
              <h4>{f.t}</h4>
              <p>{f.d}</p>
            </div>
          )}
        </div>
      </div>
    </section>);

}

window.HeaderHero = { TopStrip, Nav, Hero, ServicesStrip, ServicesBig, FactGrid, LangPill, Ico };