// Page sections — pure presentational components reading from window.OAV_COPY.
//
// All sections accept a `tone` key for content + a `palette`, `heroLayout`,
// `serviceCards` key for layout. Components are not state-aware; the app
// owns state and passes resolved props.

// ── Icon ─────────────────────────────────────────────────────
function Icon({ name, size = 28 }) {
  return (
    <img
      src={`assets/icons/${name}.png`}
      alt=""
      width={size}
      height={size}
      style={{ display: 'block' }}
    />
  );
}

// ── Nav ──────────────────────────────────────────────────────
function Nav({ scrollTo }) {
  return (
    <>
      <div className="top-bar">
        <a href="tel:+441865522678" className="top-bar-link">
          <svg viewBox="0 0 12 12" fill="currentColor" width="10" height="10" aria-hidden="true"><path d="M6 0a4 4 0 014 4c0 3-4 8-4 8S2 7 2 4a4 4 0 014-4zm0 2.5A1.5 1.5 0 107.5 4 1.5 1.5 0 006 2.5z"/></svg>
          Witney · Oxfordshire
        </a>
        <span className="top-bar-sep" />
        <a href="tel:+441865522678" className="top-bar-link top-bar-phone">+44 (0)1865 522&nbsp;678</a>
      </div>
      <nav className="nav" aria-label="Primary">
      <div className="brand">
        <span className="brand-dot" />
        <span className="brand-oxford">Oxfordshire</span>
        <span className="brand-rule" aria-hidden="true" />
        <span className="brand-av">AV</span>
      </div>
      <div className="nav-meta">
        <span className="nav-meta-loc">
          <svg viewBox="0 0 12 12" fill="currentColor" width="10" height="10" aria-hidden="true"><path d="M6 0a4 4 0 014 4c0 3-4 8-4 8S2 7 2 4a4 4 0 014-4zm0 2.5A1.5 1.5 0 107.5 4 1.5 1.5 0 006 2.5z"/></svg>
          Witney · Oxfordshire
        </span>
        <span className="nav-meta-sep" />
        <a href="tel:+441865522678">+44 (0)1865 522&nbsp;678</a>
      </div>
      <nav className="nav-links" aria-label="Site sections">
        <a className="nav-link" href="/conference-av.html">Services</a>
        <a className="nav-link" href="/live-streaming.html">Streaming</a>
        <a className="nav-link" href="/event-filming.html">Filming</a>
        <a className="nav-link" href="/team.html">About</a>
      </nav>
      <a className="nav-cta" href="#enquiry" onClick={(e) => { e.preventDefault(); scrollTo('enquiry'); }}>
        Quote
      </a>
    </nav>
    </>
  );
}

// ── Hero ─────────────────────────────────────────────────────
function Hero({ copy, layout, scrollTo }) {
  return (
    <section className="hero" data-layout={layout} data-screen-label="01 Hero">
      <h1>{copy.h1}</h1>
      <p className="hero-sub">{copy.sub}</p>

      <div className="hero-ctas">
        <a className="btn btn-primary btn-block" href="#enquiry"
           onClick={(e) => { e.preventDefault(); scrollTo('enquiry'); }}>
          {copy.ctaPrimary}
          <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
            <path d="M3 7h8m-3-3l3 3-3 3" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/>
          </svg>
        </a>
        <a className="btn btn-ghost btn-block" href="#usp"
           onClick={(e) => { e.preventDefault(); scrollTo('usp'); }}>
          {copy.ctaSecondary}
        </a>
      </div>

      <div className="hero-rig">
        {layout === 'Typographic' && <AVRigDiagram />}
        {layout === 'Split' && (
          <img
            className="hero-photo"
            src="/assets/images/hero-conference.webp"
            alt="Conference room with 100-plus delegates, managed by Oxfordshire AV"
            width="1600"
            height="1067"
          />
        )}
        {layout === 'Video Frame' && (
          <div className="video-frame">
            <div className="video-frame-chrome">
              <span className="video-rec">REC · 04:11</span>
              <span>1080 · 60p</span>
            </div>
            <div className="video-play">
              <div className="video-play-btn">
                <svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor"><path d="M6 4l10 6-10 6z"/></svg>
              </div>
            </div>
            <div className="video-frame-caption">
              Speaker on stage. <span className="hl">Reel on LinkedIn by 11am.</span>
            </div>
          </div>
        )}

        {layout === 'Typographic' && (
          <div className="hero-rig-meta">
            <span>FIG · 01 — STANDARD CONFERENCE RIG</span>
            <span>WITNEY · OX29</span>
          </div>
        )}
      </div>
    </section>
  );
}

// ── Problem ──────────────────────────────────────────────────
function Problem({ copy }) {
  return (
    <section className="problem section--alt" data-screen-label="02 Problem">
      <p className="eyebrow">{copy.eyebrow}</p>
      <h2>{copy.h2}</h2>

      <div className="problem-blocks">
        {/* Block 1 — AV is sorted */}
        <div className="problem-block problem-block--ok">
          <div className="problem-block-icon">
            <svg width="28" height="28" viewBox="0 0 28 28" fill="none" aria-hidden="true">
              <rect x="2" y="8" width="6" height="12" rx="1" fill="currentColor" opacity="0.9"/>
              <path d="M8 10 C12 10 16 7 16 4" stroke="currentColor" strokeWidth="2" strokeLinecap="round" fill="none"/>
              <path d="M8 18 C12 18 16 21 16 24" stroke="currentColor" strokeWidth="2" strokeLinecap="round" fill="none"/>
              <path d="M8 14 C13 14 18 11 20 8" stroke="currentColor" strokeWidth="2" strokeLinecap="round" fill="none" opacity="0.5"/>
              <path d="M8 14 C13 14 18 17 20 20" stroke="currentColor" strokeWidth="2" strokeLinecap="round" fill="none" opacity="0.5"/>
              <circle cx="22" cy="14" r="3" fill="var(--accent)" opacity="0.9"/>
              <path d="M20.5 14 l1 1.2 2-2" stroke="var(--m3-ink)" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" fill="none"/>
            </svg>
          </div>
          <h3>{copy.block1.title}</h3>
          <p>{copy.block1.body}</p>
        </div>

        {/* Block 2 — Content is the problem */}
        <div className="problem-block problem-block--gap">
          <div className="problem-block-icon">
            <svg width="28" height="28" viewBox="0 0 28 28" fill="none" aria-hidden="true">
              <circle cx="14" cy="14" r="11" stroke="currentColor" strokeWidth="2" fill="none"/>
              <path d="M14 8 L14 14 L18 17" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
              <path d="M20 4 L24 4 M22 2 L22 6" stroke="var(--accent)" strokeWidth="1.8" strokeLinecap="round"/>
            </svg>
          </div>
          <h3>{copy.block2.title}</h3>
          <p>{copy.block2.body}</p>
        </div>
      </div>

      <p className="problem-resolution">{copy.resolution}</p>
      <span className="problem-extra">{copy.extra}</span>
    </section>
  );
}

// ── Services ─────────────────────────────────────────────────
function Services({ copy, mode }) {
  const showIcons = mode === 'Icons · Grid' || mode === 'Icons · Stacked';
  return (
    <section className="section services" data-screen-label="03 Services">
      <p className="eyebrow">{copy.eyebrow}</p>
      <h2>{copy.h2}</h2>
      <div className="services-grid" data-mode={mode}>
        {copy.cards.map((card) => {
          const Tag = card.href ? 'a' : 'div';
          const linkProps = card.href ? { href: card.href } : {};
          return (
            <Tag className="service-card" key={card.num} {...linkProps}>
              {card.flag && <span className="usp-flag">{card.flag}</span>}
              {showIcons
                ? <span className="service-card-icon"><Icon name={card.icon} /></span>
                : <span className="service-card-num">{card.num}</span>}
              <div>
                <h3>{card.title}</h3>
                <p>{card.body}</p>
              </div>
            </Tag>
          );
        })}
      </div>
    </section>
  );
}

// ── How we work ──────────────────────────────────────────────
function Process({ copy }) {
  return (
    <section className="process" data-screen-label="04 How we work">
      <p className="eyebrow">{copy.eyebrow}</p>
      <h2>{copy.h2}</h2>
      <div className="process-steps">
        {copy.steps.map((s) => (
          <div className="process-step" key={s.num}>
            <div className="process-step-num">{s.num}</div>
            <div>
              <h3>{s.title}</h3>
              <p>{s.body}</p>
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}

// ── USP / same-day social ───────────────────────────────────
function USP({ copy }) {
  return (
    <section className="usp" id="usp" data-screen-label="05 Same-day social">
      <span className="usp-flag-top">{copy.flag}</span>
      <h2>{copy.h2}</h2>
      <p className="lede">{copy.lede}</p>

      <div className="timeline" role="list">
        {copy.timeline.map((row, i) => (
          <div className="timeline-row" key={i} role="listitem">
            <div className={`timeline-dot ${row.live ? 'is-live' : ''}`}>
              <span>
                <span className="timeline-time">
                  {row.time}<span className="ampm">{row.ampm}</span>
                </span>
              </span>
            </div>
            <div className="timeline-body">
              <div className="timeline-label">{row.label}</div>
              <h3>{row.title}</h3>
              <p dangerouslySetInnerHTML={{ __html: row.body }} />
              {row.output && (
                <span className="timeline-output">
                  <svg viewBox="0 0 12 12" fill="none">
                    <path d="M2 6l3 3 5-6" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/>
                  </svg>
                  {row.output}
                </span>
              )}
            </div>
          </div>
        ))}
      </div>

      <div className="usp-outputs">
        <h4>Typical same-day delivery</h4>
        <div className="usp-outputs-list">
          {copy.outputs.map((o, i) => (
            <div className="usp-output-chip" key={i}>
              <span className="usp-output-chip-count">{o.count}</span>
              <span>{o.label}</span>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ── Where ────────────────────────────────────────────────────
function Where({ copy }) {
  return (
    <section className="where" data-screen-label="06 Where we work">
      <p className="eyebrow">{copy.eyebrow}</p>
      <h2>{copy.h2}</h2>
      <p>{copy.p}</p>
      <div className="where-towns">
        {copy.towns.map((t, i) => (
          <span className={`town-chip ${t === 'Witney' ? 'is-base' : ''}`} key={i}>
            {t === 'Witney' && (
              <svg width="10" height="10" viewBox="0 0 12 12" fill="currentColor" style={{ marginRight: 4, verticalAlign: -1, display: 'inline-block' }}>
                <path d="M6 0a4 4 0 014 4c0 3-4 8-4 8S2 7 2 4a4 4 0 014-4zm0 2.5A1.5 1.5 0 107.5 4 1.5 1.5 0 006 2.5z"/>
              </svg>
            )}
            {t}
          </span>
        ))}
      </div>
    </section>
  );
}

// ── Sectors ──────────────────────────────────────────────────
function Sectors({ copy }) {
  return (
    <section className="sectors" data-screen-label="07 Who we work with">
      <p className="eyebrow">{copy.eyebrow}</p>
      <h2>{copy.h2}</h2>
      <div className="sectors-list">
        {copy.list.map((s, i) => (
          <div className="sector-row" key={i}>
            <div>
              <h3>{s.title}</h3>
              <p>{s.body}</p>
            </div>
            <span className="sector-num">{String(i + 1).padStart(2, '0')}</span>
          </div>
        ))}
      </div>
    </section>
  );
}

// ── Why ──────────────────────────────────────────────────────
function Why({ copy }) {
  return (
    <section className="why" data-screen-label="08 Why us">
      <p className="eyebrow">{copy.eyebrow}</p>
      <h2>{copy.h2}</h2>
      <div className="why-list">
        {copy.cards.map((c, i) => (
          <div className="why-card" key={i}>
            <div className="label">{c.label}</div>
            <h3>{c.title}</h3>
            <p dangerouslySetInnerHTML={{ __html: c.body }} />
          </div>
        ))}
      </div>
    </section>
  );
}

// ── FAQ ──────────────────────────────────────────────────────
function FAQ({ copy }) {
  const [open, setOpen] = React.useState(0);
  return (
    <section className="faq" data-screen-label="09 FAQ">
      <p className="eyebrow">{copy.eyebrow}</p>
      <h2>{copy.h2}</h2>
      <div className="faq-list">
        {copy.items.map((it, i) => (
          <div className={`faq-item ${open === i ? 'is-open' : ''}`} key={i}>
            <button className="faq-q" onClick={() => setOpen(open === i ? -1 : i)} aria-expanded={open === i}>
              {it.q}
            </button>
            {open === i && (
              <p className="faq-a" dangerouslySetInnerHTML={{ __html: it.a }} />
            )}
          </div>
        ))}
      </div>
    </section>
  );
}

// ── Enquiry form ─────────────────────────────────────────────
const ZAPIER_WEBHOOK = 'https://hooks.zapier.com/hooks/catch/1833284/4o9aald/';

function Enquiry({ copy }) {
  const [sent, setSent] = React.useState(false);
  const [sending, setSending] = React.useState(false);
  const [error, setError] = React.useState(null);

  const submit = (e) => {
    e.preventDefault();
    const fd = new FormData(e.target);
    const data = {
      name:    fd.get('name'),
      email:   fd.get('email'),
      phone:   fd.get('phone') || '',
      date:    fd.get('date') || '',
      message: fd.get('message'),
    };
    setSending(true);
    setError(null);
    fetch(ZAPIER_WEBHOOK, {
      method: 'POST',
      body: JSON.stringify(data),
    })
      .then((r) => { if (!r.ok) throw new Error('Network error'); setSent(true); })
      .catch(() => { setError('Something went wrong — please try again or call us.'); })
      .finally(() => setSending(false));
  };

  if (sent) {
    return (
      <section className="enquiry" id="enquiry" data-screen-label="10 Enquiry">
        <div className="form-success">
          <svg width="36" height="36" viewBox="0 0 36 36" style={{ margin: '0 auto 10px', display: 'block' }}>
            <circle cx="18" cy="18" r="17" fill="none" stroke="var(--accent)" strokeWidth="1.5"/>
            <path d="M10 18l5 5 11-12" stroke="var(--accent)" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" fill="none"/>
          </svg>
          <h3 dangerouslySetInnerHTML={{ __html: copy.success.title }} />
          <p dangerouslySetInnerHTML={{ __html: copy.success.body }} />
        </div>
      </section>
    );
  }

  return (
    <section className="enquiry" id="enquiry" data-screen-label="10 Enquiry">
      <p className="eyebrow">{copy.eyebrow}</p>
      <h2>{copy.h2}</h2>
      <p className="enquiry-sub">{copy.sub}</p>

      <form onSubmit={submit}>
        <input type="text" name="company" tabIndex="-1" autoComplete="off" style={{ display: 'none' }} />
        <div className="form-field">
          <label htmlFor="oav-name">Name</label>
          <input id="oav-name" name="name" type="text" placeholder="Your name" autoComplete="name" required />
        </div>
        <div className="form-row-2">
          <div className="form-field">
            <label htmlFor="oav-email">Email</label>
            <input id="oav-email" name="email" type="email" placeholder="you@example.com" autoComplete="email" required />
          </div>
          <div className="form-field">
            <label htmlFor="oav-phone">Phone <span style={{ opacity: 0.5, textTransform: 'none', letterSpacing: 0 }}>· optional</span></label>
            <input id="oav-phone" name="phone" type="tel" placeholder="07…" autoComplete="tel" />
          </div>
        </div>
        <div className="form-field">
          <label htmlFor="oav-date">Event date <span style={{ opacity: 0.5, textTransform: 'none', letterSpacing: 0 }}>· optional</span></label>
          <input id="oav-date" name="date" type="text" placeholder="When (if you know)" />
        </div>
        <div className="form-field">
          <label htmlFor="oav-msg">Tell us about your event</label>
          <textarea id="oav-msg" name="message" rows="4" placeholder="Venue, delegate count, anything you'd like covered." required></textarea>
        </div>

        {error && <p style={{ color: 'var(--accent)', fontSize: 13, margin: '0 0 12px' }}>{error}</p>}

        <button type="submit" className="btn btn-primary btn-block" disabled={sending}>
          {sending ? 'Sending…' : copy.submit}
          {!sending && <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
            <path d="M3 7h8m-3-3l3 3-3 3" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/>
          </svg>}
        </button>

        <p className="form-fine">
          Or call us on <a href="tel:+441865522678">+44 (0)1865 522 678</a> — we usually respond within a few working hours.
        </p>
      </form>
    </section>
  );
}

// ── Footer ───────────────────────────────────────────────────
function Footer() {
  return (
    <footer className="foot" data-screen-label="11 Footer">
      <div className="brand">
        <span className="brand-dot" />
        <span className="brand-oxford">Oxfordshire</span>
        <span className="brand-rule" aria-hidden="true" />
        <span className="brand-av">AV</span>
      </div>
      <p>Conference AV, live streaming and event filming. Witney, Oxfordshire.</p>

      <div className="foot-grid">
        <div className="foot-col">
          <h5>Services</h5>
          <ul>
            <li><a href="/conference-av.html">Conference AV hire</a></li>
            <li><a href="/live-streaming.html">Live streaming</a></li>
            <li><a href="/event-filming.html">Event filming</a></li>
            <li><a href="/event-filming.html">Same-day social content</a></li>
            <li><a href="/conference-av.html">Dry hire</a></li>
          </ul>
        </div>
        <div className="foot-col">
          <h5>Areas</h5>
          <ul>
            <li><a href="/oxford.html">AV hire Oxford</a></li>
            <li><a href="/witney.html">AV hire Witney</a></li>
            <li><a href="/bicester.html">AV hire Bicester</a></li>
            <li><a href="/banbury.html">AV hire Banbury</a></li>
            <li><a href="/abingdon.html">AV hire Abingdon</a></li>
          </ul>
        </div>
        <div className="foot-col">
          <h5>Contact</h5>
          <ul>
            <li><a href="tel:+441865522678">+44 (0)1865 522 678</a></li>
            <li>Witney, OX29</li>
          </ul>
        </div>
        <div className="foot-col">
          <h5>Hours</h5>
          <ul>
            <li>Mon–Fri · 8–6</li>
            <li>Event days · always</li>
          </ul>
        </div>
      </div>

      <div className="foot-bottom">
        <span className="motion3-line">Oxfordshire AV is part of the <a href="https://www.motion3.agency" target="_blank" rel="noopener noreferrer"><strong>MOTION3</strong></a> group.</span>
        <span>© 2026 Oxfordshire AV (Oxford Media Factory Limited). Company No. 08469108.</span>
      </div>
    </footer>
  );
}

// ── Gallery ──────────────────────────────────────────────────
function Gallery() {
  const photos = [
    { src: '/assets/images/awards-stage.webp',        alt: 'Awards ceremony with custom AV and projection — Oxfordshire AV' },
    { src: '/assets/images/tech-control-room.webp',  alt: 'AV technician managing a live event from the control desk' },
    { src: '/assets/images/streaming-multicam.webp', alt: 'Multi-camera live streaming production in progress' },
    { src: '/assets/images/conf-panel.webp',         alt: 'Panel discussion at an Oxfordshire conference' },
  ];
  return (
    <section className="gallery" aria-label="Event photography">
      <div className="gallery-grid">
        {photos.map((p, i) => (
          <div className="gallery-item" key={i}>
            <img src={p.src} alt={p.alt} loading="lazy" />
          </div>
        ))}
      </div>
    </section>
  );
}

// ── Clients ──────────────────────────────────────────────────
function Clients() {
  const logos = [
    { src: '/assets/logos/university-of-oxford.svg',  alt: 'University of Oxford' },
    { src: '/assets/logos/christ-church.svg',          alt: 'Christ Church, Oxford' },
    { src: '/assets/logos/keble-college.svg',          alt: 'Keble College, Oxford' },
    { src: '/assets/logos/worcester-college.svg',      alt: 'Worcester College, Oxford' },
    { src: '/assets/logos/london-business-school.svg', alt: 'London Business School' },
  ];
  return (
    <section className="clients section--alt">
      <p className="clients-label">Trusted by Oxford's leading institutions</p>
      <div className="clients-grid">
        {logos.map((l, i) => (
          <div className="client-logo" key={i}>
            <img src={l.src} alt={l.alt} loading="lazy" width="200" height="72" />
          </div>
        ))}
      </div>
    </section>
  );
}

// ── StickyCtA ────────────────────────────────────────────────
function StickyCTA() {
  return (
    <div className="sticky-cta" aria-label="Quick contact">
      <a href="tel:+441865522678" className="sticky-cta-call">
        <svg viewBox="0 0 20 20" fill="currentColor" width="16" height="16" aria-hidden="true">
          <path d="M2 3a1 1 0 011-1h3.5a1 1 0 01.95.684l1 3a1 1 0 01-.23 1.02L6.5 8.4a11.05 11.05 0 005.1 5.1l1.696-1.72a1 1 0 011.02-.23l3 1a1 1 0 01.684.95V17a1 1 0 01-1 1A16 16 0 012 3z"/>
        </svg>
        Call us
      </a>
      <a href="/#enquiry" className="sticky-cta-quote">Get a quote</a>
    </div>
  );
}

Object.assign(window, {
  Nav, Hero, Problem, Services, Process, USP,
  Where, Sectors, Why, FAQ, Enquiry, Footer, Gallery,
  Clients, StickyCTA,
});
