// Section components for landing page

function Reveal({ children, delay = 0, className = '' }) {
  const ref = React.useRef(null);
  const [seen, setSeen] = React.useState(false);
  React.useEffect(() => {
    const el = ref.current;if (!el) return;
    const io = new IntersectionObserver((es) => es.forEach((e) => {if (e.isIntersecting) {setSeen(true);io.disconnect();}}), { threshold: 0.15 });
    io.observe(el);return () => io.disconnect();
  }, []);
  return <div ref={ref} className={`reveal ${seen ? 'in' : ''} ${delay ? 'd' + delay : ''} ${className}`}>{children}</div>;
}

function StoreIcon({ kind }) {
  if (kind === 'apple') return <svg className="store-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M17.05 12.5c0-2.34 1.91-3.47 2-3.52-1.09-1.59-2.79-1.81-3.39-1.84-1.44-.14-2.81.85-3.54.85-.73 0-1.85-.83-3.05-.81-1.57.02-3.02.91-3.83 2.32-1.63 2.83-.42 7.02 1.17 9.32.78 1.13 1.71 2.4 2.92 2.35 1.17-.04 1.62-.76 3.04-.76 1.42 0 1.82.76 3.06.74 1.27-.02 2.07-1.15 2.84-2.29.9-1.31 1.27-2.59 1.29-2.65-.03-.01-2.47-.95-2.51-3.71zm-2.34-6.83c.65-.79 1.09-1.88.97-2.97-.94.04-2.07.62-2.74 1.41-.6.7-1.13 1.82-.99 2.89 1.04.08 2.11-.53 2.76-1.33z" /></svg>;
  return <svg className="store-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M3.61 1.81C3.24 2.21 3 2.83 3 3.65v16.7c0 .82.24 1.44.61 1.84l.09.09L13 13.06v-.18L3.7 1.72l-.09.09zM16.81 16.34l-3.1-3.1v-.18l3.1-3.1.07.04 3.67 2.09c1.05.59 1.05 1.56 0 2.15l-3.67 2.09-.07.04zM13.71 13.06L4.41 22.36c.35.37.92.41 1.56.05L16.74 16.4l-3.03-3.34zM4.41 1.64l9.3 9.3 3.03-3.34L5.97 1.59c-.64-.36-1.21-.31-1.56.05z" /></svg>;
}

function Nav({ lang, setLang, t }) {
  const [scrolled, setScrolled] = React.useState(false);
  React.useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 30);
    window.addEventListener('scroll', onScroll, { passive: true });
    return () => window.removeEventListener('scroll', onScroll);
  }, []);
  return (
    <nav className={`nav ${scrolled ? 'scrolled' : ''}`} data-screen-label="Nav">
      <a href="#top" className="nav-logo"><img src={(typeof window !== "undefined" && window.__resources && window.__resources.logo) || "assets/logo.png"} alt="Seçtim Ben" /><span className="wordmark">Seçtim <em>Ben</em></span></a>
      <div className="nav-links">
        <a href="#features">{t.navFeatures}</a>
        <a href="#preview">{t.navHowItWorks}</a>
        <a href="#stores">{t.navStores}</a>
        <a href="#testimonials">{t.navStories}</a>
      </div>
      <div className="nav-right">
        <div className="lang-switch">
          <button className={lang === 'tr' ? 'active' : ''} onClick={() => setLang('tr')}>TR</button>
          <button className={lang === 'en' ? 'active' : ''} onClick={() => setLang('en')}>EN</button>
        </div>
        <a href="#download" className="btn btn-primary">{t.navDownload}</a>
      </div>
    </nav>);

}

function GiftDeco({ className, size = 80, color = '#F2A076', ribbon = '#2C5650' }) {
  return (
    <svg className={className} width={size} height={size} viewBox="0 0 80 80" fill="none">
      <rect x="12" y="30" width="56" height="38" rx="4" fill={color} />
      <rect x="36" y="30" width="8" height="38" fill={ribbon} />
      <rect x="12" y="42" width="56" height="6" fill={ribbon} />
      <path d="M40 30 C 30 18, 18 22, 22 30 L 40 30 Z" fill={color} stroke={ribbon} strokeWidth="2" />
      <path d="M40 30 C 50 18, 62 22, 58 30 L 40 30 Z" fill={color} stroke={ribbon} strokeWidth="2" />
    </svg>);

}

function Hero({ t, screenIndex, setScreenIndex }) {
  const screens = [<ScreenHome t={t} />, <ScreenBirthday t={t} />, <ScreenFriends t={t} />, <ScreenDiscover t={t} />];
  return (
    <section className="hero" id="top" data-screen-label="Hero">
      <GiftDeco className="gift-deco gd-1" size={70} color="#FCE2CC" ribbon="#F2A076" />
      <GiftDeco className="gift-deco gd-2" size={100} color="#F2A076" ribbon="#2C5650" />
      <GiftDeco className="gift-deco gd-3" size={56} color="#2C5650" ribbon="#F2A076" />
      <GiftDeco className="gift-deco gd-4" size={80} color="#FCE2CC" ribbon="#2C5650" />
      <div className="container hero-grid">
        <div>
          <Reveal>
            <div className="hero-brand" style={{ fontFamily: "\"Instrument Serif\"" }}>
              <img src={(typeof window !== "undefined" && window.__resources && window.__resources.logo) || "assets/logo.png"} alt="Seçtim Ben" />
              <div>
                <div className="hero-brand-name">Seçtim <em>Ben</em></div>
                <div className="hero-brand-tag">{t.heroBrandTag}</div>
              </div>
            </div>
          </Reveal>
          <Reveal delay={1}><div className="eyebrow"><span className="dot"></span> {t.heroBrandSub}</div></Reveal>
          <Reveal delay={1}>
            <h1 className="h1">{t.heroH1a}<br /><em>{t.heroH1b}</em> {t.heroH1c}</h1>
          </Reveal>
          <Reveal delay={2}><p className="lede">{t.heroLede}</p></Reveal>
          <Reveal delay={3}>
            <div className="hero-cta">
              <a href="#download" className="store-btn"><StoreIcon kind="apple" /><div className="store-text"><small>{t.downloadOn}</small><strong>App Store</strong></div></a>
              <a href="#download" className="store-btn"><StoreIcon kind="google" /><div className="store-text"><small>{t.getItOn}</small><strong>Google Play</strong></div></a>
            </div>
          </Reveal>
          <Reveal delay={4}>
            <div className="hero-stats">
              <div><div className="stat-num">12K+</div><div className="stat-label">{t.statUsers}</div></div>
              <div><div className="stat-num">450+</div><div className="stat-label">{t.statStores}</div></div>
              <div><div className="stat-num">4.9</div><div className="stat-label">App Store</div></div>
            </div>
          </Reveal>
        </div>
        <Reveal delay={2}>
          <div className="phone-stage">
            <div className="phone">
              <div className="phone-notch"></div>
              <div className="phone-screen">
                {screens.map((sc, i) =>
                <div key={i} className="ps-screen-fade" style={{
                  opacity: screenIndex === i ? 1 : 0,
                  transform: screenIndex === i ? 'scale(1)' : 'scale(0.96)',
                  transition: 'opacity 0.7s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1)',
                  pointerEvents: screenIndex === i ? 'auto' : 'none'
                }}>{sc}</div>
                )}
              </div>
            </div>
            <div className="phone-notif">
              <img src={(typeof window !== "undefined" && window.__resources && window.__resources.logo) || "assets/logo.png"} alt="" className="pn-icon" />
              <div className="pn-body">
                <div className="pn-head">
                  <span className="pn-app">SEÇTİM BEN</span>
                  <span className="pn-time">{t.floatLabel1}</span>
                </div>
                <div className="pn-text">🎁 {t.floatVal1}</div>
              </div>
            </div>
            <div className="float-card" style={{ bottom: 110, right: -40 }}>
              <div className="ic" style={{ background: 'rgba(242,160,118,0.18)', color: '#F2A076' }}>✓</div>
              <div><div className="lbl">{t.floatLabel2}</div><div className="val">{t.floatVal2}</div></div>
            </div>
          </div>
        </Reveal>
      </div>
    </section>);

}

function Features({ t }) {
  const items = [
  {
    num: '01',
    title: t.feat1Title,
    body: t.feat1Body,
    illu:
    <div style={{ position: 'absolute', inset: 0, padding: 18, display: 'flex', flexDirection: 'column', gap: 8 }}>
          {[
      { l: t.feat1Item1, p: '₺790', t: t.bought, c: '#2C5650', img: PRODUCT.perfume },
      { l: t.feat1Item2, p: '₺450', t: t.reserve, c: '#F2A076', img: PRODUCT.vase },
      { l: t.feat1Item3, p: '₺1.250', t: t.available, c: '#8A8F8C', img: PRODUCT.sunglasses }].
      map((it, i) =>
      <div key={i} style={{ background: '#fff', borderRadius: 10, padding: '8px 10px', display: 'flex', alignItems: 'center', gap: 10, border: '1px solid rgba(28,38,35,0.06)' }}>
              <div style={{ width: 28, height: 28, borderRadius: 8, overflow: 'hidden', flexShrink: 0 }}><img src={it.img} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover' }} /></div>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div style={{ fontSize: 11, fontWeight: 700, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{it.l}</div>
                <div style={{ fontFamily: "'Instrument Serif', serif", fontSize: 13 }}>{it.p}</div>
              </div>
              <div style={{ fontSize: 9, padding: '3px 7px', borderRadius: 999, background: it.c === '#2C5650' ? 'rgba(44,86,80,0.12)' : it.c === '#F2A076' ? 'rgba(242,160,118,0.18)' : 'rgba(138,143,140,0.15)', color: it.c, fontWeight: 600 }}>{it.t}</div>
            </div>
      )}
        </div>

  },
  {
    num: '02',
    title: t.feat2Title,
    body: t.feat2Body,
    illu:
    <div style={{ position: 'absolute', inset: 0, padding: 24, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 16 }}>
          <div style={{ display: 'flex', justifyContent: 'center' }}>
            {[AVATAR.melis, AVATAR.selin, AVATAR.zeynep, AVATAR.arda].map((src, i) =>
        <img key={i} src={src} alt="" style={{ width: 48, height: 48, borderRadius: 24, border: '3px solid #FBF7EE', marginLeft: i ? -12 : 0, objectFit: 'cover' }} />
        )}
          </div>
          <div style={{ background: '#fff', borderRadius: 14, padding: '10px 14px', textAlign: 'center', border: '1px solid rgba(28,38,35,0.06)' }}>
            <div style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 9, color: '#F2A076', letterSpacing: '0.1em', textTransform: 'uppercase' }}>{t.friendInvite}</div>
            <div style={{ fontFamily: "'Instrument Serif', serif", fontSize: 16, marginTop: 4 }}>{t.moreFriends}</div>
          </div>
        </div>

  },
  {
    num: '03',
    title: t.feat3Title,
    body: t.feat3Body,
    illu:
    <div style={{ position: 'absolute', inset: 0, padding: 16, display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 8, alignContent: 'center' }}>
          {['trendyol', 'ZARA', 'MANGO', 'Karaca', 'SEPHORA', 'PANDORA'].map((s, i) =>
      <div key={i} style={{ aspectRatio: '1.4', background: '#fff', border: '1px solid rgba(28,38,35,0.06)', borderRadius: 10, display: 'flex', alignItems: 'center', justifyContent: 'center', fontFamily: "'Instrument Serif', serif", fontSize: 13, fontStyle: 'italic' }}>{s}</div>
      )}
        </div>

  }];

  return (
    <section className="features" id="features" data-screen-label="Features">
      <div className="container">
        <div className="section-head">
          <Reveal><div className="section-eyebrow">— {t.feat_eyebrow}</div></Reveal>
          <Reveal delay={1}><h2 className="section-title">{t.feat_titleA} <em>{t.feat_titleB}</em></h2></Reveal>
          <Reveal delay={2}><p className="section-sub">{t.feat_sub}</p></Reveal>
        </div>
        <div className="feature-grid">
          {items.map((it, i) =>
          <Reveal key={i} delay={i + 1}>
              <div className="feature-card">
                <span className="num">{it.num}</span>
                <h3>{it.title}</h3>
                <p>{it.body}</p>
                <div className="feature-illu">{it.illu}</div>
              </div>
            </Reveal>
          )}
        </div>
      </div>
    </section>);

}

function PhonePlaceholder() {
  return (
    <div className="phone-screenshot-placeholder">
      <div className="phone-placeholder-content">
        <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="#8A8F8C" strokeWidth="1.2">
          <rect x="5" y="2" width="14" height="20" rx="2" />
          <circle cx="12" cy="17" r="1" fill="#8A8F8C" />
        </svg>
        <div className="phone-placeholder-label">Görsel yakında</div>
      </div>
    </div>
  );
}

function Preview({ t }) {
  const [activeStep, setActiveStep] = React.useState(0);
  const stepRefs = React.useRef([]);
  React.useEffect(() => {
    const io = new IntersectionObserver((entries) => {
      entries.forEach((e) => {
        if (e.isIntersecting) {
          const idx = stepRefs.current.indexOf(e.target);
          if (idx !== -1) setActiveStep(idx);
        }
      });
    }, { threshold: 0.5, rootMargin: '-20% 0px -30% 0px' });
    stepRefs.current.forEach((r) => r && io.observe(r));
    return () => io.disconnect();
  }, []);

  const steps = [
  { num: '01', title: t.step1Title, body: t.step1Body, tip: t.step1Tip, screen: <HowCreateList t={t} />, mobileMockup: <HowCreateList t={t} /> },
  { num: '02', title: t.step2Title, body: t.step2Body, tip: t.step2Tip, screen: <HowAddItem t={t} /> },
  { num: '03', title: t.step3Title, body: t.step3Body, tip: t.step3Tip, screen: <HowShare t={t} /> },
  { num: '04', title: t.step4Title, body: t.step4Body, tip: t.step4Tip, screen: <HowMarkStatus t={t} /> }];


  return (
    <section className="preview" id="preview" data-screen-label="Preview">
      <div className="container">
        <div className="section-head">
          <Reveal><div className="section-eyebrow">— {t.prev_eyebrow}</div></Reveal>
          <Reveal delay={1}><h2 className="section-title">{t.prev_titleA} <em>{t.prev_titleB}</em></h2></Reveal>
          <Reveal delay={2}><p className="section-sub">{t.prev_sub}</p></Reveal>
        </div>
        <div className="preview-grid">
          <div className="preview-sticky">
            <div className="phone">
              <div className="phone-notch"></div>
              <div className="phone-screen">
                {steps.map((s, i) =>
                <div key={i} className="ps-screen-fade" style={{
                  opacity: activeStep === i ? 1 : 0,
                  transform: activeStep === i ? 'scale(1)' : 'scale(0.96)',
                  transition: 'opacity 0.6s, transform 0.6s',
                  pointerEvents: activeStep === i ? 'auto' : 'none'
                }}>{s.screen}</div>
                )}
              </div>
            </div>
          </div>
          <div className="preview-steps">
            {steps.map((s, i) =>
            <div key={i} ref={(el) => stepRefs.current[i] = el} className="preview-step" style={{ opacity: activeStep === i ? 1 : 0.35, transition: 'opacity 0.4s' }}>
                {s.mobileMockup && (
                  <div className="preview-step-phone-mobile">
                    <div className="phone phone-preview-mobile">
                      <div className="phone-notch"></div>
                      <div className="phone-screen">{s.mobileMockup}</div>
                    </div>
                  </div>
                )}
                <span className="step-num">{s.num}</span>
                <h3>{s.title}</h3>
                <p>{s.body}</p>
                {s.tip && <div className="preview-tip"><span>💡</span>{s.tip}</div>}
              </div>
            )}
          </div>
        </div>
      </div>
    </section>);

}

function Stores({ t }) {
  const stores = ['Trendyol', 'Zara', 'Nike', 'Mango', 'Karaca', 'Sephora', 'Beymen', 'Pandora', 'H&M', 'LCW', 'Adidas', 'Boyner', 'Sephora', 'Penti', 'Yargıcı', 'Vakko'];
  return (
    <section className="stores" id="stores" data-screen-label="Stores">
      <div className="container">
        <div className="section-head">
          <Reveal><div className="section-eyebrow">— {t.stores_eyebrow}</div></Reveal>
          <Reveal delay={1}><h2 className="section-title">{t.stores_titleA} <em>{t.stores_titleB}</em></h2></Reveal>
          <Reveal delay={2}><p className="section-sub">{t.stores_sub}</p></Reveal>
        </div>
      </div>
      <div className="marquee marquee-row">
        {[...stores, ...stores].map((s, i) => <span key={i}>{s}</span>)}
      </div>
      <div className="marquee marquee-row r2">
        {[...stores.slice().reverse(), ...stores.slice().reverse()].map((s, i) => <span key={i}>{s}</span>)}
      </div>
    </section>);

}

function Testimonials({ t }) {
  const items = [
  { q: t.testi1, n: 'Defne K.', h: '@defnek', src: AVATAR.defne },
  { q: t.testi2, n: 'Cem A.', h: '@cematk', src: AVATAR.cem },
  { q: t.testi3, n: 'Ayşe N.', h: '@aysenur', src: AVATAR.ayse }];

  return (
    <section className="testimonials" id="testimonials" data-screen-label="Testimonials">
      <div className="container">
        <div className="section-head">
          <Reveal><div className="section-eyebrow">— {t.testi_eyebrow}</div></Reveal>
          <Reveal delay={1}><h2 className="section-title">{t.testi_titleA} <em>{t.testi_titleB}</em></h2></Reveal>
        </div>
        <div className="testi-grid">
          {items.map((it, i) =>
          <Reveal key={i} delay={i + 1}>
              <div className="testi-card">
                <div className="quote-mark">"</div>
                <div className="body">{it.q}</div>
                <div className="author">
                  <img src={it.src} alt="" style={{ width: 44, height: 44, borderRadius: '50%', objectFit: 'cover' }} />
                  <div>
                    <div className="name">{it.n}</div>
                    <div className="handle">{it.h}</div>
                  </div>
                </div>
              </div>
            </Reveal>
          )}
        </div>
      </div>
    </section>);

}

function CTA({ t }) {
  return (
    <section className="cta" id="download" data-screen-label="CTA">
      <GiftDeco className="cta-deco gd-1" size={120} color="#F2A076" ribbon="#FCE2CC" />
      <GiftDeco className="cta-deco gd-2" size={90} color="#FCE2CC" ribbon="#F2A076" />
      <GiftDeco className="cta-deco gd-3" size={70} color="#F2A076" ribbon="#FCE2CC" />
      <GiftDeco className="cta-deco gd-4" size={110} color="#FCE2CC" ribbon="#F2A076" />
      <div className="container" style={{ position: 'relative', zIndex: 2 }}>
        <Reveal><div className="section-eyebrow">— {t.cta_eyebrow}</div></Reveal>
        <Reveal delay={1}><h2 className="section-title">{t.cta_titleA}<br /><em>{t.cta_titleB}</em></h2></Reveal>
        <Reveal delay={2}><p className="section-sub" style={{ color: 'rgba(246, 240, 228, 0.75)' }}>{t.cta_sub}</p></Reveal>
        <Reveal delay={3}>
          <div className="cta-buttons">
            <a href="#" className="store-btn"><StoreIcon kind="apple" /><div className="store-text"><small>{t.downloadOn}</small><strong>App Store</strong></div></a>
            <a href="#" className="store-btn"><StoreIcon kind="google" /><div className="store-text"><small>{t.getItOn}</small><strong>Google Play</strong></div></a>
          </div>
        </Reveal>
      </div>
    </section>);

}

function Footer({ t }) {
  return (
    <footer data-screen-label="Footer">
      <div className="footer-grid">
        <div className="footer-brand">
          <div className="logo"><img src={(typeof window !== "undefined" && window.__resources && window.__resources.logo) || "assets/logo.png"} alt="Seçtim Ben" />Seçtim <em>Ben</em></div>
          <p>{t.foot_brand}</p>
        </div>
        <div className="footer-col">
          <h4>{t.foot_product}</h4>
          <ul><li><a href="#features">{t.navFeatures}</a></li><li><a href="#preview">{t.navHowItWorks}</a></li><li><a href="#stores">{t.navStores}</a></li><li><a href="#download">{t.navDownload}</a></li></ul>
        </div>
        <div className="footer-col">
          <h4>{t.foot_company}</h4>
          <ul><li><a href="#">{t.foot_about}</a></li><li><a href="#">{t.foot_blog}</a></li><li><a href="#">{t.foot_contact}</a></li><li><a href="#">{t.foot_press}</a></li></ul>
        </div>
        <div className="footer-col">
          <h4>{t.foot_legal}</h4>
          <ul><li><a href="/gizlilik">{t.foot_privacy}</a></li><li><a href="/kullanim-sartlari">{t.foot_terms}</a></li><li><a href="/gizlilik">KVKK</a></li><li><a href="/gizlilik">Cookies</a></li></ul>
        </div>
      </div>
      <div className="footer-bottom">
        <div>© 2026 Seçtim Ben. {t.foot_rights}</div>
        <div className="socials">
          <a href="#" aria-label="Instagram"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><rect x="3" y="3" width="18" height="18" rx="5" /><circle cx="12" cy="12" r="4" /><circle cx="17.5" cy="6.5" r="1" fill="currentColor" /></svg></a>
          <a href="#" aria-label="X"><svg width="12" height="12" viewBox="0 0 24 24" fill="currentColor"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z" /></svg></a>
          <a href="#" aria-label="TikTok"><svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M19.59 6.69a4.83 4.83 0 0 1-3.77-4.25V2h-3.45v13.67a2.89 2.89 0 0 1-5.2 1.74 2.89 2.89 0 0 1 2.31-4.64 2.93 2.93 0 0 1 .88.13V9.4a6.84 6.84 0 0 0-1-.05A6.33 6.33 0 0 0 5.8 20.1a6.34 6.34 0 0 0 10.86-4.43V8.84a8.16 8.16 0 0 0 4.77 1.52V6.9a4.84 4.84 0 0 1-1.84-.21z" /></svg></a>
        </div>
      </div>
    </footer>);

}

Object.assign(window, { Reveal, Nav, Hero, Features, Preview, Stores, Testimonials, CTA, Footer });