// Shared website chrome for Stashly — Nav, Footer, StoreButtons. Assigns to window.
const { Logo, Button, Icon } = window.StashlyDesignSystem_821802;
const ASSETS = '../assets/logos';
const APP_STORE_URL = 'https://apps.apple.com/us/app/stashly-makeup-tracker/id6766150902';

function StoreButtons({ align = 'flex-start', dark = false }) {
  const primary = {
    display: 'inline-flex', alignItems: 'center', gap: 10, textDecoration: 'none',
    padding: '10px 18px', borderRadius: 'var(--radius-pill)', cursor: 'pointer',
    fontFamily: 'var(--font-body)', border: '1.5px solid transparent',
    background: dark ? 'var(--cream-50)' : 'var(--burgundy-500)', color: dark ? 'var(--burgundy-500)' : 'var(--cream-100)',
  };
  const soon = {
    display: 'inline-flex', alignItems: 'center', gap: 10, textDecoration: 'none',
    padding: '10px 18px', borderRadius: 'var(--radius-pill)', cursor: 'default',
    fontFamily: 'var(--font-body)',
    background: 'transparent', color: dark ? 'var(--cream-100)' : 'var(--burgundy-500)',
    border: `1.5px solid ${dark ? 'rgba(254,245,233,0.45)' : 'var(--border-strong, rgba(83,26,39,0.35))'}`, opacity: 0.85,
  };
  const Sub = ({ children }) => <span style={{ fontSize: 10, opacity: 0.8, letterSpacing: '.04em', textTransform: 'uppercase' }}>{children}</span>;
  const Big = ({ children }) => <span style={{ fontSize: 16, fontWeight: 700, marginTop: -2 }}>{children}</span>;
  const PlayGlyph = () => (
    <svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor" aria-hidden style={{ flex: '0 0 auto' }}><path d="M4 3.5c-.3.16-.5.48-.5.9v15.2c0 .42.2.74.5.9l8.4-8.5L4 3.5zm10 8.5l2.6-2.63-9.1-5.16L14 12zm3.9-3.95l-2.9 2.95 2.9 2.95 3.2-1.82c.6-.34.6-1.02 0-1.36l-3.2-1.72zM7.5 20.45l9.1-5.16L14 12.66 7.5 20.45z"/></svg>
  );
  return (
    <div style={{ display: 'flex', gap: 12, flexWrap: 'wrap', justifyContent: align }}>
      <a href={APP_STORE_URL} target="_blank" rel="noopener" style={primary}>
        <Icon name="apple" size={24} />
        <span style={{ display: 'flex', flexDirection: 'column', lineHeight: 1.1 }}><Sub>Download on the</Sub><Big>App Store</Big></span>
      </a>
      <span style={soon} aria-label="Coming soon to the Play Store">
        <PlayGlyph />
        <span style={{ display: 'flex', flexDirection: 'column', lineHeight: 1.1 }}><Sub>Coming soon to the</Sub><Big>Play Store</Big></span>
      </span>
    </div>
  );
}

function Nav() {
  const [open, setOpen] = React.useState(false);
  const links = [['How it works', '/#how'], ['Pricing', '/#pricing'], ['Coming soon', '/#next'], ['FAQ', 'support.html']];
  return (
    <header style={{ position: 'sticky', top: 0, zIndex: 50, background: 'rgba(254,245,233,0.85)', backdropFilter: 'blur(12px)', borderBottom: '1px solid var(--border-subtle)' }}>
      <div style={{ maxWidth: 1240, margin: '0 auto', display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '16px 28px', gap: 20 }}>
        <a href="/" style={{ display: 'flex' }}><Logo variant="lockup" tone="default" height={28} assetsPath={ASSETS} /></a>
        <nav className="nav-links" style={{ display: 'flex', alignItems: 'center', gap: 26 }}>
          {links.map(([l, h]) => <a key={l} href={h} style={{ fontFamily: 'var(--font-body)', fontSize: 15, fontWeight: 600, color: 'var(--text-strong)', textDecoration: 'none' }}>{l}</a>)}
        </nav>
        <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
          <a href={APP_STORE_URL} target="_blank" rel="noopener" style={{ textDecoration: 'none' }}><Button variant="primary" size="sm" iconLeft="download">Download</Button></a>
          <button className="nav-burger" onClick={() => setOpen(o => !o)} aria-label="Menu" style={{ display: 'none', background: 'transparent', border: 'none', cursor: 'pointer', padding: 6, color: 'var(--text-strong)' }}>
            <Icon name={open ? 'x' : 'menu'} size={24} />
          </button>
        </div>
      </div>
      {open && (
        <div className="nav-drawer" style={{ display: 'none', flexDirection: 'column', padding: '8px 20px 18px', borderTop: '1px solid var(--border-subtle)', background: 'rgba(254,245,233,0.98)' }}>
          {links.map(([l, h]) => <a key={l} href={h} onClick={() => setOpen(false)} style={{ fontFamily: 'var(--font-body)', fontSize: 16, fontWeight: 600, color: 'var(--text-strong)', textDecoration: 'none', padding: '10px 0' }}>{l}</a>)}
        </div>
      )}
    </header>
  );
}

function Footer() {
  const cols = [
    ['Product', [['How it works', '/#how'], ['Pricing', '/#pricing'], ['Coming soon', '/#next']]],
    ['Company', [['Contact', 'mailto:maricruz@stashly.life'], ['FAQ', 'support.html'], ['Privacy Policy', 'privacy.html']]],
  ];
  return (
    <footer style={{ background: 'var(--burgundy-500)', color: 'var(--cream-200)' }}>
      <div style={{ maxWidth: 1240, margin: '0 auto', padding: '56px 28px 40px', display: 'grid', gridTemplateColumns: 'minmax(0,1.6fr) minmax(0,1fr) minmax(0,1fr)', gap: 40 }}>
        <div>
          <Logo variant="lockup" tone="on-dark" height={30} assetsPath={ASSETS} />
          <p style={{ fontFamily: 'var(--font-body)', fontSize: 15, color: 'var(--cream-300)', lineHeight: 1.6, marginTop: 16, maxWidth: 300 }}>Your stash-care friend. Fall back in love with the beauty products you already own.</p>
          <div style={{ marginTop: 20 }}><StoreButtons dark /></div>
        </div>
        {cols.map(([title, items]) => (
          <div key={title}>
            <div style={{ fontFamily: 'var(--font-display)', fontSize: 14, letterSpacing: '.14em', textTransform: 'uppercase', color: 'var(--orange-400)', marginBottom: 14 }}>{title}</div>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
              {items.map(([l, h]) => <a key={l} href={h} style={{ fontFamily: 'var(--font-body)', fontSize: 15, color: 'var(--cream-200)', textDecoration: 'none' }}>{l}</a>)}
            </div>
          </div>
        ))}
      </div>
      <div style={{ borderTop: '1px solid rgba(254,245,233,0.15)' }}>
        <div style={{ maxWidth: 1240, margin: '0 auto', padding: '18px 28px', display: 'flex', justifyContent: 'space-between', flexWrap: 'wrap', gap: 10, fontFamily: 'var(--font-body)', fontSize: 13, color: 'var(--sand-500)' }}>
          <span>© 2026 Stashly · stashly.life</span>
          <span>Unlock more beauty! ✨</span>
        </div>
      </div>
    </footer>
  );
}

Object.assign(window, { Nav, Footer, StoreButtons });
