/* Portfolio sections — part 1: Nav, Hero, About */
const DS = window.BassantZeidanFesforiDesignSystem_940ce5;
const ASSET = 'assets';

function Nav({ t, lang, setLang, dir }) {
  const P = window.PORTFOLIO;
  const [scrolled, setScrolled] = React.useState(false);
  React.useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 20);
    window.addEventListener('scroll', onScroll);
    return () => window.removeEventListener('scroll', onScroll);
  }, []);
  return (
    <header style={{
      position: 'sticky', top: 0, zIndex: 50,
      background: scrolled ? 'rgba(251,252,248,0.92)' : 'transparent',
      backdropFilter: scrolled ? 'saturate(160%) blur(10px)' : 'none',
      borderBottom: scrolled ? '1px solid var(--border-default)' : '1px solid transparent',
      transition: 'all var(--dur-base) var(--ease-out)',
    }}>
      <div className="pf-container" style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', height: '76px' }}>
        <a href="#top" style={{ display: 'flex', alignItems: 'center', gap: '0.7rem', textDecoration: 'none' }}>
          <img src={window.R(ASSET + '/brand/fesfori-logo.png')} alt="Fesfori" style={{ width: 44, height: 44, borderRadius: 12 }} />
          <span style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: '1.25rem', color: 'var(--text-heading)' }}>{t(P.brand)}</span>
        </a>
        <nav className="pf-navlinks" style={{ display: 'flex', alignItems: 'center', gap: '1.6rem' }}>
          {P.nav.map(n => (
            <a key={n.id} href={'#' + n.id} style={{
              fontFamily: 'var(--font-body)', fontWeight: 600, fontSize: 'var(--fs-sm)',
              color: 'var(--text-body)', textDecoration: 'none', transition: 'color var(--dur-fast)',
            }}
              onMouseEnter={e => e.currentTarget.style.color = 'var(--green-600)'}
              onMouseLeave={e => e.currentTarget.style.color = 'var(--text-body)'}
            >{t(n)}</a>
          ))}
          <a href="/blog/" style={{
            fontFamily: 'var(--font-body)', fontWeight: 600, fontSize: 'var(--fs-sm)',
            color: 'var(--text-body)', textDecoration: 'none', transition: 'color var(--dur-fast)',
          }}
            onMouseEnter={e => e.currentTarget.style.color = 'var(--green-600)'}
            onMouseLeave={e => e.currentTarget.style.color = 'var(--text-body)'}
          >{t({ en: 'Blog', ar: 'المدوّنة' })}</a>
        </nav>
        <div style={{ display: 'flex', alignItems: 'center', gap: '0.75rem' }}>
          <button onClick={() => setLang(lang === 'en' ? 'ar' : 'en')} aria-label="Toggle language" style={{
            display: 'inline-flex', alignItems: 'center', gap: '0.35rem',
            padding: '0.45rem 0.85rem', border: '2px solid var(--navy-800)', background: 'transparent',
            borderRadius: 'var(--radius-pill)', cursor: 'pointer',
            fontFamily: 'var(--font-display)', fontWeight: 600, fontSize: 'var(--fs-sm)', color: 'var(--navy-800)',
          }}>
            <span style={{ opacity: lang === 'en' ? 1 : 0.4 }}>EN</span>
            <span style={{ opacity: 0.3 }}>/</span>
            <span style={{ opacity: lang === 'ar' ? 1 : 0.4 }}>ع</span>
          </button>
          <DS.Button as="a" href="#contact" variant="primary" size="sm" className="pf-hide-sm">{t(P.hero.ctaPrimary)}</DS.Button>
        </div>
      </div>
    </header>
  );
}

function Hero({ t, dir }) {
  const P = window.PORTFOLIO;
  return (
    <section id="top" style={{ position: 'relative', overflow: 'hidden' }}>
      {/* soft blobs */}
      <span style={{ position: 'absolute', top: '-120px', insetInlineEnd: '-80px', width: 380, height: 380, background: 'radial-gradient(circle, var(--green-100), transparent 70%)', borderRadius: '50%', pointerEvents: 'none' }} />
      <span style={{ position: 'absolute', bottom: '-140px', insetInlineStart: '-120px', width: 420, height: 420, background: 'radial-gradient(circle, var(--sky-100), transparent 70%)', borderRadius: '50%', pointerEvents: 'none' }} />
      <div className="pf-container pf-hero" style={{ display: 'grid', gridTemplateColumns: '1.15fr 0.85fr', gap: 'var(--space-8)', alignItems: 'center', paddingTop: 'var(--space-8)', paddingBottom: 'var(--space-9)' }}>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--space-5)' }}>
          <DS.Pill tone="green" style={{ alignSelf: dir === 'rtl' ? 'flex-end' : 'flex-start' }}>{t(P.hero.eyebrow)}</DS.Pill>
          <h1 style={{ margin: 0, fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 'var(--fs-display)', lineHeight: 1.02, letterSpacing: '-0.02em', color: 'var(--text-heading)' }}>
            {t(P.hero.name)}
          </h1>
          <p style={{ margin: 0, fontFamily: 'var(--font-display)', fontWeight: 600, fontSize: 'var(--fs-h3)', color: 'var(--green-600)' }}>{t(P.hero.tagline)}</p>
          <p style={{ margin: 0, maxWidth: 560, fontFamily: 'var(--font-body)', fontSize: 'var(--fs-lead)', lineHeight: 'var(--lh-body)', color: 'var(--text-body)' }}>{t(P.hero.intro)}</p>
          <div style={{ display: 'flex', gap: 'var(--space-3)', flexWrap: 'wrap', marginTop: 'var(--space-2)' }}>
            <DS.Button as="a" href="#contact" variant="primary" size="lg">{t(P.hero.ctaPrimary)}</DS.Button>
            <DS.Button as="a" href="#watch" variant="outline" size="lg">{t(P.hero.ctaSecondary)}</DS.Button>
          </div>
        </div>
        <div style={{ position: 'relative' }}>
          <div style={{ position: 'absolute', inset: 0, background: 'var(--navy-800)', borderRadius: '32px', transform: 'rotate(-4deg)' }} />
          <div style={{ position: 'relative', borderRadius: '28px', overflow: 'hidden', boxShadow: 'var(--shadow-lg)', background: 'var(--green-100)', aspectRatio: '4/5' }}>
            <img src={window.R(ASSET + '/photos/bassant-headshot.png')} alt={t(P.hero.name)} style={{ width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center top' }} />
          </div>
          <div style={{ position: 'absolute', insetInlineStart: '-18px', bottom: '24px', background: 'var(--white)', boxShadow: 'var(--shadow-md)', borderRadius: '18px', padding: '0.8rem 1.1rem', display: 'flex', alignItems: 'center', gap: '0.6rem' }}>
            <img src={window.R(ASSET + '/brand/fesfori-logo.png')} style={{ width: 40, height: 40, borderRadius: 10 }} alt="" />
            <div style={{ display: 'flex', flexDirection: 'column' }}>
              <span style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: '1rem', color: 'var(--text-heading)', lineHeight: 1.1 }}>Fesfori</span>
              <span style={{ fontFamily: 'var(--font-body)', fontSize: 'var(--fs-xs)', color: 'var(--text-muted)' }}>{t(P.hero.eyebrow).split('·').pop().trim()}</span>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

function About({ t }) {
  const P = window.PORTFOLIO;
  return (
    <section id="about" className="pf-section">
      <div className="pf-container pf-about" style={{ display: 'grid', gridTemplateColumns: '0.85fr 1.15fr', gap: 'var(--space-8)', alignItems: 'center' }}>
        <div style={{ position: 'relative', borderRadius: '28px', overflow: 'hidden', boxShadow: 'var(--shadow-md)', background: 'var(--sky-100)', aspectRatio: '4/5' }}>
          <img src={window.R(ASSET + '/photos/bassant-puppet-green.png')} alt="Basant with the Fesfori puppet" style={{ width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center top' }} />
        </div>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--space-5)' }}>
          <DS.SectionHeading eyebrow={t(P.about.eyebrow)} title={t(P.about.title)} intro={t(P.about.body)} />
          <div>
            <span style={{ display: 'block', fontFamily: 'var(--font-body)', fontWeight: 800, fontSize: 'var(--fs-eyebrow)', letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--text-muted)', marginBottom: 'var(--space-3)' }}>{t(P.about.skillsTitle)}</span>
            <div style={{ display: 'flex', flexWrap: 'wrap', gap: 'var(--space-2)' }}>
              {P.about.skills.map((s, i) => (
                <DS.Pill key={i} tone={['green', 'sky', 'sun', 'green', 'sky', 'sun'][i % 6]}>{t(s)}</DS.Pill>
              ))}
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

Object.assign(window, { Nav, Hero, About });
