// Burger House — shared UI components

const Wordmark = ({ small } = {}) => (
  <div className="row" style={{ gap: 10 }}>
    <svg width={small ? 24 : 28} height={small ? 24 : 28} viewBox="0 0 32 32" style={{ flexShrink: 0 }}>
      <path d="M4 22 Q 16 6 28 22 Z" fill="var(--accent)" />
      <rect x="4" y="22" width="24" height="3" fill="var(--ink)" />
      <path d="M5 25 Q 16 32 27 25 Z" fill="var(--ink)" opacity=".75" />
    </svg>
    <span className="wordmark" style={{ fontSize: small ? 18 : 22 }}>Burger House</span>
  </div>
);

const NavBar = ({ onNav, current }) => {
  const links = ['Menu', 'Locations', 'Rewards', 'Order'];
  return (
    <header style={{
      borderBottom: '1px solid var(--line)',
      background: 'var(--bg)',
      position: 'sticky', top: 0, zIndex: 50,
      backdropFilter: 'saturate(1.4) blur(8px)',
      WebkitBackdropFilter: 'saturate(1.4) blur(8px)',
    }}>
      <div className="container row between nav-bar-row" style={{ height: 68 }}>
        <div className="row gap-32">
          <a onClick={() => onNav?.('home')} style={{ cursor: 'pointer' }}><Wordmark /></a>
          <nav className="row gap-24 nav-bar-links" style={{ marginLeft: 8 }}>
            {links.map(l => (
              <a key={l}
                 onClick={() => onNav?.(l === 'Menu' ? 'menu' : l.toLowerCase())}
                 style={{
                   fontSize: 14, fontWeight: 500, cursor: 'pointer',
                   color: current === l.toLowerCase() ? 'var(--ink)' : 'var(--ink-2)',
                   borderBottom: current === l.toLowerCase() ? '1.5px solid var(--accent)' : '1.5px solid transparent',
                   paddingBottom: 4,
                 }}>
                {l}
              </a>
            ))}
          </nav>
        </div>
        <div className="row gap-12">
          <button className="btn btn-ghost btn-sm hide-mobile">
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3"/></svg>
            Search
          </button>
          <button className="btn btn-ghost btn-sm hide-mobile">Sign in</button>
          <button className="btn btn-primary btn-sm" onClick={() => onNav?.('menu')}>Order now</button>
        </div>
      </div>
    </header>
  );
};

const MobileNavBar = ({ onNav }) => (
  <div style={{
    display: 'flex', alignItems: 'center', justifyContent: 'space-between',
    padding: '14px 18px',
    borderBottom: '1px solid var(--line)',
    background: 'var(--bg)',
    position: 'sticky', top: 0, zIndex: 5,
  }}>
    <button style={{ background: 'none', border: 0, padding: 4 }}>
      <svg width="22" height="22" viewBox="0 0 24 24" stroke="var(--ink)" strokeWidth="2" fill="none"><path d="M3 6h18M3 12h18M3 18h18"/></svg>
    </button>
    <Wordmark small />
    <div className="row gap-8">
      <button style={{ background: 'none', border: 0, padding: 4 }}>
        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="var(--ink)" strokeWidth="2"><circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3"/></svg>
      </button>
      <button style={{ background: 'none', border: 0, padding: 4 }}>
        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="var(--ink)" strokeWidth="2"><circle cx="9" cy="20" r="1.5"/><circle cx="18" cy="20" r="1.5"/><path d="M3 4h3l2.7 12.3a2 2 0 0 0 2 1.7h7.6a2 2 0 0 0 2-1.6L22 8H6"/></svg>
      </button>
    </div>
  </div>
);

const Footer = () => (
  <footer style={{ borderTop: '1px solid var(--line)', marginTop: 80 }}>
    <div className="container" style={{ padding: '56px 32px 32px' }}>
      <div className="footer-grid" style={{ display: 'grid', gridTemplateColumns: '2fr 1fr 1fr 1fr 1fr', gap: 32 }}>
        <div>
          <Wordmark />
          <p className="dim" style={{ fontSize: 13, marginTop: 16, maxWidth: 280 }}>
            Better burgers, made by hand, served fast. Thirty-eight kitchens, no shortcuts.
          </p>
        </div>
        {[
          ['Menu', ['Burgers', 'Chicken', 'Sides', 'Drinks', 'Desserts']],
          ['Burger House', ['Our story', 'Sourcing', 'Sustainability', 'Press']],
          ['Help', ['Allergens', 'Nutrition', 'Contact', 'FAQs']],
          ['Visit', ['Locations', 'Delivery', 'Catering', 'Gift cards']],
        ].map(([title, items]) => (
          <div key={title} className="col gap-12">
            <div className="eyebrow">{title}</div>
            {items.map(i => <a key={i} style={{ fontSize: 13, color: 'var(--ink-2)', cursor: 'pointer' }}>{i}</a>)}
          </div>
        ))}
      </div>
      <div className="row between footer-bottom" style={{ marginTop: 56, paddingTop: 24, borderTop: '1px solid var(--line)' }}>
        <span className="mono" style={{ fontSize: 11, color: 'var(--ink-3)' }}>© 2026 Burger House Co. — Original concept design</span>
        <div className="row gap-16">
          <span className="mono" style={{ fontSize: 11, color: 'var(--ink-3)' }}>Privacy</span>
          <span className="mono" style={{ fontSize: 11, color: 'var(--ink-3)' }}>Terms</span>
          <span className="mono" style={{ fontSize: 11, color: 'var(--ink-3)' }}>Cookies</span>
        </div>
      </div>
    </div>
  </footer>
);

const ProductCard = ({ p, onClick, compact }) => (
  <article className="card lift" onClick={onClick} style={{ cursor: 'pointer', overflow: 'hidden', display: 'flex', flexDirection: 'column' }}>
    <div style={{ aspectRatio: '1 / 1', background: 'var(--surface-2)', display: 'flex', alignItems: 'center', justifyContent: 'center', position: 'relative', overflow: 'hidden' }}>
      <img src={`public/${p.id}.jpg`} alt={p.name} style={{ width: '100%', height: '100%', objectFit: 'cover', position: 'absolute', inset: 0 }} />
      {p.badges?.[0] && (
        <span className="pill accent" style={{ position: 'absolute', top: 14, left: 14, zIndex: 1 }}>{p.badges[0]}</span>
      )}
    </div>
    <div className="col gap-8" style={{ padding: compact ? 14 : 20 }}>
      <div className="row between" style={{ alignItems: 'flex-start' }}>
        <h3 style={{ margin: 0, fontSize: compact ? 15 : 17, fontWeight: 600, letterSpacing: '-0.01em' }}>{p.name}</h3>
        <span className="mono" style={{ fontSize: 13, color: 'var(--ink)' }}>£{p.price.toFixed(2)}</span>
      </div>
      <p className="muted" style={{ margin: 0, fontSize: 13, lineHeight: 1.4 }}>{p.tagline}</p>
      <div className="row between" style={{ marginTop: 4 }}>
        <span className="mono" style={{ fontSize: 11, color: 'var(--ink-3)' }}>{p.calories} kcal</span>
        <button className="btn btn-ghost btn-sm" style={{ height: 30, padding: '0 12px', fontSize: 12 }} onClick={e => { e.stopPropagation(); }}>Add +</button>
      </div>
    </div>
  </article>
);

const CategoryTile = ({ c, onClick }) => (
  <a className="lift cat-tile" onClick={onClick} style={{
    background: 'var(--surface)',
    border: '1px solid var(--line)',
    borderRadius: 18,
    padding: 24,
    cursor: 'pointer',
    display: 'flex',
    alignItems: 'center',
    gap: 18,
  }}>
    <div className="cat-illo-wrap" style={{ width: 84, height: 84, background: 'var(--surface-2)', borderRadius: 14, overflow: 'hidden', flexShrink: 0 }}>
      <img src={`public/categories/${c.id}.jpg`} alt={c.name} style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }} />
    </div>
    <div className="col" style={{ gap: 4 }}>
      <h3 style={{ margin: 0, fontSize: 17, fontWeight: 600, letterSpacing: '-0.01em' }}>{c.name}</h3>
      <span className="mono" style={{ fontSize: 11, color: 'var(--ink-3)' }}>{c.count} items</span>
    </div>
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="var(--ink-3)" strokeWidth="2" style={{ marginLeft: 'auto' }}><path d="M9 6l6 6-6 6"/></svg>
  </a>
);

Object.assign(window, { Wordmark, NavBar, MobileNavBar, Footer, ProductCard, CategoryTile });
