/* global React */
const { useState, useEffect, useRef } = React;

// =========================================================
// Icons (simple, custom-drawn line set — original)
// =========================================================
const Icon = {
  arrow: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M2.5 7h9M8 3.5L11.5 7 8 10.5" />
    </svg>
  ),
  check: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M2.5 7.5l3 3 6.5-7" />
    </svg>
  ),
  shield: (p) => (
    <svg width="20" height="20" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M10 2L3 5v5c0 3.5 2.8 6.7 7 8 4.2-1.3 7-4.5 7-8V5l-7-3z" />
    </svg>
  ),
  cloud: (p) => (
    <svg width="20" height="20" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M5 14a3 3 0 010-6 4 4 0 017.6-1.2A3 3 0 0115 14H5z" />
    </svg>
  ),
  gear: (p) => (
    <svg width="20" height="20" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <circle cx="10" cy="10" r="2.6" />
      <path d="M10 1.5v2M10 16.5v2M3.5 3.5l1.4 1.4M15.1 15.1l1.4 1.4M1.5 10h2M16.5 10h2M3.5 16.5l1.4-1.4M15.1 4.9l1.4-1.4" />
    </svg>
  ),
  swap: (p) => (
    <svg width="20" height="20" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M3 7h12M11 3l4 4-4 4M17 13H5M9 17l-4-4 4-4" />
    </svg>
  ),
  zap: (p) => (
    <svg width="20" height="20" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M11 2L4 11h5l-1 7 7-9h-5l1-7z" />
    </svg>
  ),
  layers: (p) => (
    <svg width="20" height="20" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M10 2.5l8 4-8 4-8-4 8-4zM2 10l8 4 8-4M2 13.5l8 4 8-4" />
    </svg>
  ),
  spark: (p) => (
    <svg width="20" height="20" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M10 2.5l1.7 4.8 4.8 1.7-4.8 1.7L10 15.5l-1.7-4.8L3.5 9l4.8-1.7L10 2.5z" />
      <path d="M15.5 3l.7 1.8 1.8.7-1.8.7-.7 1.8-.7-1.8-1.8-.7 1.8-.7.7-1.8z" />
    </svg>
  ),
  phone: (p) => (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M3 3.5c0 5.5 4 9.5 9.5 9.5l1-2.5L11 9l-1.5 1L7 7.5 8 6 6.5 3.5 4 3 3 3.5z" />
    </svg>
  ),
  mail: (p) => (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <rect x="2" y="3.5" width="12" height="9" rx="1.5" />
      <path d="M2.5 4.5L8 9l5.5-4.5" />
    </svg>
  ),
  pin: (p) => (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M8 14s5-4.5 5-8.5a5 5 0 00-10 0C3 9.5 8 14 8 14z" />
      <circle cx="8" cy="5.5" r="2" />
    </svg>
  ),
};

// =========================================================
// Logo
// =========================================================
function Logo({ onClick, variant = 'light' }) {
  // variant: 'light' for use on dark backgrounds, 'dark' for use on light backgrounds
  const src = variant === 'light' ? 'assets/logo-light.png' : 'assets/logo.png';
  return (
    <a href="#" onClick={(e) => { e.preventDefault(); onClick && onClick(); }} className="logo" aria-label="Planetiware home">
      <img src={src} alt="Planetiware" className="logo-img" />
      <span className="logo-reg" aria-hidden="true">®</span>
    </a>
  );
}

// =========================================================
// Top nav
// =========================================================
function Nav({ route, go }) {
  const links = [
    ['home', 'Home'],
    ['solutions', 'Solutions'],
    ['defensible', 'Defensible'],
    ['about', 'About'],
    ['contact', 'Contact'],
  ];
  return (
    <nav className="nav">
      <div className="wrap nav-inner">
        <Logo onClick={() => go('home')} />
        <div className="nav-links">
          {links.map(([id, label]) => (
            <a key={id}
               href={`#${id}`}
               className={route === id ? 'active' : ''}
               onClick={(e) => { e.preventDefault(); go(id); }}>
              {label}
            </a>
          ))}
        </div>
        <button className="btn btn-primary btn-sm nav-cta" onClick={() => go('contact')}>
          Support
        </button>
      </div>
    </nav>
  );
}

// =========================================================
// Photo placeholder
// =========================================================
function Photo({ label, light, style, className = '' }) {
  return (
    <div className={`photo-ph ${light ? 'light' : ''} ${className}`} style={style}>
      <span className="photo-ph-label">{label}</span>
    </div>
  );
}

// =========================================================
// Eyebrow
// =========================================================
function Eyebrow({ children }) {
  return <span className="eyebrow">{children}</span>;
}

// =========================================================
// Footer
// =========================================================
function Footer({ go }) {
  return (
    <footer className="footer">
      <div className="wrap">
        <div className="footer-grid">
          <div className="footer-col footer-brand">
            <Logo onClick={() => go('home')} />
            <p>Outcomes-led IT services for mid-market businesses. Build a system you can trust, then forget about.</p>
          </div>
          <div className="footer-col">
            <h5>Solutions</h5>
            <ul>
              <li><a href="#" onClick={(e) => { e.preventDefault(); go('solutions'); }}>Managed IT</a></li>
              <li><a href="#" onClick={(e) => { e.preventDefault(); go('solutions'); }}>Intune adoption</a></li>
              <li><a href="#" onClick={(e) => { e.preventDefault(); go('solutions'); }}>Cloud & Microsoft 365</a></li>
              <li><a href="#" onClick={(e) => { e.preventDefault(); go('defensible'); }}>Defensible — cyber</a></li>
              <li><a href="#" onClick={(e) => { e.preventDefault(); go('solutions'); }}>AI adoption</a></li>
            </ul>
          </div>
          <div className="footer-col">
            <h5>Company</h5>
            <ul>
              <li><a href="#" onClick={(e) => { e.preventDefault(); go('about'); }}>About</a></li>
              <li><a href="#" onClick={(e) => { e.preventDefault(); go('about'); }}>How we work</a></li>
              <li><a href="#" onClick={(e) => { e.preventDefault(); go('contact'); }}>Contact</a></li>
              <li><a href="#" onClick={(e) => e.preventDefault()}>Careers</a></li>
            </ul>
          </div>
          <div className="footer-col">
            <h5>Contact</h5>
            <ul>
              <li><a href="mailto:info@planetiware.com">info@planetiware.com</a></li>
              <li><a href="tel:+61291998520">(02) 9199 8520</a></li>
              <li><a href="#" onClick={(e) => e.preventDefault()}>Level 2, 65–71 Belmore Rd<br/>Randwick NSW 2031</a></li>
              <li><a href="https://portal.planetiware.com" target="_blank" rel="noopener">Client portal →</a></li>
            </ul>
          </div>
        </div>
        <div className="footer-bottom">
          <span>© 2026 Planetiware · ABN 11 569 240 443 · Planetiware® is a registered trademark.</span>
          <span className="sys"><span className="dot"></span>All systems operational</span>
        </div>
      </div>
    </footer>
  );
}

// expose to other babel scripts
Object.assign(window, { Icon, Logo, Nav, Photo, Eyebrow, Footer });
