/* Hayes Global Mobility — UI kit: shared page parts */
(function () {
  const { SectionHeading, Button } = window.HayesGlobalMobilityDesignSystem_489ece;
  const wrap = { maxWidth: 'var(--container-max)', margin: '0 auto', padding: '0 40px' };

  function PageHeader({ eyebrow, title, sub }) {
    return (
      <section style={{ position: 'relative', overflow: 'hidden', background: 'var(--color-navy-800)' }}>
        <div style={{ position: 'absolute', inset: 0, opacity: 0.2, backgroundImage: "url('assets/skyline-hero.jpg')", backgroundSize: 'cover', backgroundPosition: 'center' }} />
        <div style={{ position: 'relative', ...wrap, padding: '76px 40px' }}>
          <SectionHeading onDark eyebrow={eyebrow} title={title} subtitle={sub} />
        </div>
      </section>
    );
  }

  function CTABand({ title, sub, ctaLabel = 'Start Your Application', onCta }) {
    return (
      <section style={{ position: 'relative', overflow: 'hidden', background: 'var(--color-navy-900)' }}>
        <div style={{ position: 'absolute', inset: 0, opacity: 0.16, backgroundImage: "url('assets/skyline-hero.jpg')", backgroundSize: 'cover', backgroundPosition: 'center' }} />
        <div style={{ position: 'relative', ...wrap, padding: '60px 40px', textAlign: 'center' }}>
          <h2 style={{ fontFamily: 'var(--font-display)', fontWeight: 600, fontSize: 32, color: '#fff', margin: '0 0 10px' }}>{title}</h2>
          {sub && <p style={{ fontFamily: 'var(--font-ui)', fontSize: 16, color: 'rgba(255,255,255,0.8)', margin: '0 0 24px' }}>{sub}</p>}
          <Button variant="primary" size="lg" onClick={onCta}>{ctaLabel}</Button>
        </div>
      </section>
    );
  }

  window.HayesPageHeader = PageHeader;
  window.HayesCTABand = CTABand;

  /* ---- Form submission → email ----
     Static site: build a prefilled email to the Hayes inbox from the form fields
     (requires name="" on each field) and open the visitor's mail client. */
  const HAYES_EMAIL = 'admin@hayesglobalmobility.com';
  const FIELD_LABELS = {
    fullName: 'Full Name', nationality: 'Nationality', email: 'Email', phone: 'Phone',
    service: 'Service of Interest', destination: 'Destination', goals: 'Goals / Message',
    contactConsent: 'Consent to contact', updates: 'Subscribe to updates',
  };
  function hayesSubmit(e, subject) {
    e.preventDefault();
    let lines = [];
    try {
      const fd = new FormData(e.target);
      for (const [k, v] of fd.entries()) {
        if (v === '' || v == null) continue;
        lines.push((FIELD_LABELS[k] || k) + ': ' + v);
      }
    } catch (err) { /* ignore */ }
    const body = encodeURIComponent(lines.join('\n') || 'New enquiry from the Hayes Global Mobility website.');
    const subj = encodeURIComponent(subject || 'Website Enquiry');
    try { window.location.href = 'mailto:' + HAYES_EMAIL + '?subject=' + subj + '&body=' + body; } catch (err) { /* offline */ }
  }
  window.HAYES_EMAIL = HAYES_EMAIL;
  window.hayesSubmit = hayesSubmit;
})();
