/* Pōda Ksamil — shared website chrome (wordmark, header, hero, footer) */

function Icon({ name, size = 18, color = 'currentColor', strokeWidth = 1.6, style = {} }) {
  // Lucide icon, rendered via data-lucide and hydrated by lucide.createIcons()
  return <i data-lucide={name} style={{ width: size, height: size, color, display: 'inline-flex', ...style }} data-stroke={strokeWidth}></i>;
}

function useIsNarrow(bp = 680) {
  const get = () => (typeof window !== 'undefined' ? window.innerWidth <= bp : false);
  const [narrow, setNarrow] = React.useState(get);
  React.useEffect(() => {
    const onR = () => setNarrow(get());
    window.addEventListener('resize', onR);
    onR();
    return () => window.removeEventListener('resize', onR);
  }, [bp]);
  return narrow;
}

function Wordmark({ tone = 'light', size = 1 }) {
  const ink = tone === 'light' ? 'var(--ink-900)' : '#fff';
  const gold = tone === 'light' ? 'var(--gold-600)' : 'var(--gold-500)';
  return (
    <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4 * size, lineHeight: 1 }}>
      <span style={{ font: 'var(--weight-semibold) ' + (28 * size) + 'px/0.9 var(--font-display)', letterSpacing: '0.22em', textIndent: '0.22em', color: ink }}>PŌDA</span>
      <span style={{ height: 1, width: 24 * size, background: gold, opacity: 0.85 }} />
      <span style={{ font: 'var(--weight-semibold) ' + (8.5 * size) + 'px/1 var(--font-body)', letterSpacing: '0.42em', textIndent: '0.42em', color: gold }}>KSAMIL</span>
    </div>
  );
}

function LangToggle({ lang, setLang }) {
  const langs = ['EN', 'SQ', 'IT'];
  return (
    <div style={{ display: 'inline-flex', border: '1px solid rgba(255,255,255,0.28)', borderRadius: 'var(--radius-pill)', padding: 2, gap: 2 }}>
      {langs.map((l) => {
        const active = l === lang;
        return (
          <button key={l} type="button" onClick={() => setLang(l)} style={{
            appearance: 'none', cursor: 'pointer', border: 0, borderRadius: 'var(--radius-pill)',
            padding: '5px 11px', font: 'var(--weight-semibold) 11px/1 var(--font-body)', letterSpacing: '0.08em',
            background: active ? '#fff' : 'transparent', color: active ? 'var(--navy-900)' : 'rgba(255,255,255,0.8)',
            transition: 'background var(--dur-fast), color var(--dur-fast)',
          }}>{l}</button>
        );
      })}
    </div>
  );
}

function SiteHeader({ lang, setLang, t, onReserve }) {
  const [scrolled, setScrolled] = React.useState(false);
  const narrow = useIsNarrow(680);
  React.useEffect(() => {
    const el = document.querySelector('[data-scroll-root]') || window;
    const onScroll = () => setScrolled((el.scrollTop || window.scrollY || 0) > 40);
    el.addEventListener('scroll', onScroll, { passive: true });
    return () => el.removeEventListener('scroll', onScroll);
  }, []);
  return (
    <header style={{
      position: 'sticky', top: 0, zIndex: 30,
      display: 'flex', alignItems: 'center', justifyContent: 'space-between',
      padding: scrolled ? '11px 16px' : (narrow ? '13px 16px' : '18px 28px'),
      background: scrolled ? 'rgba(17,19,46,0.92)' : 'transparent',
      backdropFilter: scrolled ? 'saturate(140%) blur(10px)' : 'none',
      borderBottom: scrolled ? '1px solid rgba(255,255,255,0.10)' : '1px solid transparent',
      transition: 'padding var(--dur-base) var(--ease-soft), background var(--dur-base), border-color var(--dur-base)',
    }}>
      {narrow ? (
        <button type="button" onClick={onReserve} style={{
          appearance: 'none', cursor: 'pointer', border: '1px solid var(--gold-500)', background: 'transparent',
          color: 'var(--gold-500)', borderRadius: 'var(--radius-pill)', padding: '7px 13px', flex: '0 0 auto',
          font: 'var(--weight-semibold) 11px/1 var(--font-body)', letterSpacing: '0.1em', textTransform: 'uppercase',
        }}>{t.reserve}</button>
      ) : (
        <div style={{ display: 'flex', alignItems: 'center', gap: 10, color: 'rgba(255,255,255,0.85)' }}>
          <Icon name="map-pin" size={15} />
          <span style={{ font: 'var(--weight-semibold) 11px/1 var(--font-body)', letterSpacing: '0.16em', textTransform: 'uppercase' }}>Poda Bay</span>
        </div>
      )}
      <div style={narrow
        ? { flex: '1 1 auto', display: 'flex', justifyContent: 'center', minWidth: 0 }
        : { position: 'absolute', left: '50%', transform: 'translateX(-50%)' }}>
        <Wordmark tone="dark" size={narrow ? 0.78 : (scrolled ? 0.85 : 1)} />
      </div>
      <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
        <LangToggle lang={lang} setLang={setLang} />
        {narrow ? null : (
          <button type="button" onClick={onReserve} style={{
            appearance: 'none', cursor: 'pointer', border: '1px solid var(--gold-500)', background: 'transparent',
            color: 'var(--gold-500)', borderRadius: 'var(--radius-pill)', padding: '8px 16px',
            font: 'var(--weight-semibold) 11px/1 var(--font-body)', letterSpacing: '0.1em', textTransform: 'uppercase',
          }}>{t.reserve}</button>
        )}
      </div>
    </header>
  );
}

function Hero({ t }) {
  const narrow = useIsNarrow(680);
  return (
    <section style={{ position: 'relative', overflow: 'hidden', color: '#fff', textAlign: 'center', padding: narrow ? '72px 20px 64px' : '96px 24px 104px', minHeight: narrow ? '76vh' : '62vh', display: 'flex', flexDirection: 'column', justifyContent: 'center' }}>
      {/* clean turquoise Ionian water gradient — the Ksamil beach-bar backdrop */}
      <div aria-hidden="true" style={{ position: 'absolute', inset: 0, background:
        'linear-gradient(180deg, #2bbcd0 0%, #1aa9bf 38%, #128ba0 70%, #0c7384 100%)' }} />
      {narrow ? (
        <React.Fragment>
          {/* mobile-only: real PODA KSAMIL portrait photo */}
          <div aria-hidden="true" style={{ position: 'absolute', inset: 0, backgroundImage: 'url(../../assets/brand/poda-ksamil-portrait.png)', backgroundSize: 'cover', backgroundPosition: 'center 42%' }} />
          <div aria-hidden="true" style={{ position: 'absolute', inset: 0, background:
            'linear-gradient(180deg, rgba(7,50,60,0.5) 0%, rgba(7,50,60,0.18) 42%, rgba(7,50,60,0.66) 100%)' }} />
        </React.Fragment>
      ) : (
        <React.Fragment>
          {/* desktop/laptop: real PODA KSAMIL whitewashed-entrance photo, dropped below the header */}
          <div aria-hidden="true" style={{ position: 'absolute', top: 22, left: 0, right: 0, bottom: 0, backgroundImage: 'url(../../assets/brand/poda-entrance-wide.png)', backgroundSize: 'cover', backgroundPosition: 'center top' }} />
          <div aria-hidden="true" style={{ position: 'absolute', inset: 0, background:
            'linear-gradient(180deg, rgba(6,40,50,0.5) 0%, rgba(6,40,50,0.22) 34%, rgba(6,40,50,0.58) 100%)' }} />
          <div aria-hidden="true" style={{ position: 'absolute', inset: 0, background:
            'radial-gradient(62% 54% at 50% 54%, rgba(6,40,50,0.42) 0%, rgba(6,40,50,0) 76%)' }} />
        </React.Fragment>
      )}
      <div style={{ position: 'relative', maxWidth: 720, margin: '0 auto', display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
        <div style={{ fontFamily: 'var(--font-body)', fontWeight: 600, fontSize: narrow ? 11 : 12, lineHeight: 1.3, letterSpacing: narrow ? '0.24em' : '0.34em', textTransform: 'uppercase', color: 'var(--gold-500)', marginBottom: narrow ? 14 : 20 }}>{t.heroEyebrow}</div>
        <h1 style={{ margin: 0, fontFamily: 'var(--font-display)', fontWeight: 600, fontSize: 'clamp(34px, 7.5vw, 70px)', lineHeight: 1.05, letterSpacing: '0.01em', textWrap: 'balance' }}>{t.heroTitle}</h1>
        <p style={{ margin: 0, marginTop: narrow ? 16 : 20, maxWidth: 520, fontFamily: 'var(--font-body)', fontWeight: 400, fontSize: narrow ? 14.5 : 16, lineHeight: 1.6, color: 'rgba(255,255,255,0.88)' }}>{t.heroSub}</p>
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 18, marginTop: narrow ? 22 : 30, color: 'rgba(255,255,255,0.82)', fontFamily: 'var(--font-body)', fontWeight: 500, fontSize: 12, letterSpacing: '0.04em', flexWrap: 'wrap' }}>
          <span style={{ display: 'inline-flex', alignItems: 'center', gap: 7 }}><Icon name="sun" size={15} /> {t.heroHours}</span>
          <span style={{ opacity: 0.4 }}>·</span>
          <span style={{ display: 'inline-flex', alignItems: 'center', gap: 7 }}><Icon name="waves" size={15} /> {t.heroSeaview}</span>
        </div>
      </div>
    </section>
  );
}

function Gallery({ t }) {
  const shots = [
    { src: '../../assets/brand/poda-ksamil-swing-sign.png', cap: t.galSwing },
    { src: '../../assets/brand/beach-bar-entrance.png', cap: t.galEntrance },
    { src: '../../assets/brand/pineapple-cocktail.png', cap: t.galPineapple },
    { src: '../../assets/brand/night-cocktails.png', cap: t.galNight },
  ];
  return (
    <section style={{ background: 'var(--surface-warm)', padding: '56px 28px 64px' }}>
      <div style={{ maxWidth: 'var(--container-wide)', margin: '0 auto' }}>
        <div style={{ textAlign: 'center', marginBottom: 30 }}>
          <div style={{ font: 'var(--weight-semibold) 11px/1 var(--font-body)', letterSpacing: '0.28em', textTransform: 'uppercase', color: 'var(--sea-600)', marginBottom: 12 }}>{t.galEyebrow}</div>
          <h2 style={{ margin: 0, font: 'var(--weight-semibold) clamp(26px, 5vw, 36px)/1.1 var(--font-display)', color: 'var(--text-heading)' }}>{t.galTitle}</h2>
        </div>
        <div style={{ display: 'grid', gap: 16, gridTemplateColumns: 'repeat(auto-fit, minmax(160px, 1fr))' }}>
          {shots.map((s, i) => (
            <figure key={i} style={{ margin: 0 }}>
              <div style={{ aspectRatio: '3 / 4', borderRadius: 'var(--radius-lg)', backgroundImage: 'url(' + s.src + ')', backgroundSize: 'cover', backgroundPosition: 'center', boxShadow: 'var(--shadow-md)' }} />
              <figcaption style={{ marginTop: 10, textAlign: 'center', font: 'var(--weight-medium) 12px/1.4 var(--font-body)', color: 'var(--text-muted)', letterSpacing: '0.02em' }}>{s.cap}</figcaption>
            </figure>
          ))}
        </div>
      </div>
    </section>
  );
}

function SiteFooter({ t }) {
  const cols = [
    { h: t.footFind, lines: ['Poda Bay, Rruga Gjiri Poda', 'Ksamil 9706, Albania'], icon: 'map-pin' },
    { h: t.footHours, lines: ['Every day · 09:00 – 01:00', 'Kitchen until 23:00'], icon: 'clock' },
    { h: t.footReach, lines: ['+355 69 896 6814', '@poda.ksamil'], icon: 'phone' },
  ];
  return (
    <footer style={{ background: 'var(--surface-deep-2)', color: 'rgba(255,255,255,0.78)', padding: '64px 28px 40px' }}>
      <div style={{ maxWidth: 'var(--container-wide)', margin: '0 auto', display: 'grid', gap: 40, gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', alignItems: 'start' }}>
        <div><Wordmark tone="dark" size={1.1} /></div>
        {cols.map((c) => (
          <div key={c.h}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 8, color: 'var(--gold-500)', font: 'var(--weight-semibold) 11px/1 var(--font-body)', letterSpacing: '0.16em', textTransform: 'uppercase', marginBottom: 14 }}>
              <Icon name={c.icon} size={14} /> {c.h}
            </div>
            {c.lines.map((l, i) => <div key={i} style={{ font: 'var(--weight-regular) 14px/1.7 var(--font-body)' }}>{l}</div>)}
          </div>
        ))}
      </div>
      <div style={{ maxWidth: 'var(--container-wide)', margin: '40px auto 0', paddingTop: 24, borderTop: '1px solid rgba(255,255,255,0.12)', display: 'flex', justifyContent: 'space-between', flexWrap: 'wrap', gap: 12, font: '12px/1.6 var(--font-body)', color: 'rgba(255,255,255,0.5)' }}>
        <span>© {new Date().getFullYear()} Pōda Ksamil · Albanian Riviera</span>
        <span>{t.footNote}</span>
      </div>
    </footer>
  );
}

Object.assign(window, { Icon, Wordmark, LangToggle, SiteHeader, Hero, Gallery, SiteFooter });
