// Sections A: Header, Hero, Social Proof, Problem, Solution

const { useState, useEffect, useRef } = React;

// Reusable: scroll reveal
function useReveal() {
  const ref = useRef(null);
  useEffect(() => {
    if (!ref.current) return;
    const el = ref.current;
    const io = new IntersectionObserver((entries) => {
      entries.forEach(e => { if (e.isIntersecting) { el.classList.add('in'); io.unobserve(el); } });
    }, { threshold: 0.12 });
    io.observe(el);
    return () => io.disconnect();
  }, []);
  return ref;
}
window.useReveal = useReveal;

// Logo component
function Logo({ size = 22 }) {
  return (
    <a href="#" className="logo" style={{ fontSize: size }}>
      <span className="mark"><img src="enki-logo.png" alt="إنكي" /></span>
      <span>إنكي</span>
    </a>
  );
}
window.Logo = Logo;

function StoreBtn({ kind }) {
  const isApple = kind === 'apple';
  return (
    <button className="store-btn" disabled aria-disabled="true" tabIndex={-1}>
      {isApple ? <Ic.Apple className="store-ic" /> : <Ic.Google className="store-ic" />}
      <span className="store-text">
        <span className="store-small">{isApple ? 'قريباً على' : 'قريباً على'}</span>
        <span className="store-big">{isApple ? 'App Store' : 'Google Play'}</span>
      </span>
      <span className="tooltip">قريباً</span>
    </button>
  );
}
window.StoreBtn = StoreBtn;

// 1. Header
function Header() {
  const [scrolled, setScrolled] = useState(false);
  const [menuOpen, setMenuOpen] = useState(false);
  useEffect(() => {
    const on = () => setScrolled(window.scrollY > 24);
    on(); window.addEventListener('scroll', on, { passive: true });
    return () => window.removeEventListener('scroll', on);
  }, []);
  const links = [
    ['#home', 'الرئيسية'],
    ['#how', 'شلون يشتغل'],
    ['#features', 'المميزات'],
    ['#testimonials', 'آراء الطلاب'],
    ['#pricing', 'الخطط والأسعار'],
    ['#faq', 'الأسئلة الشائعة'],
  ];
  return (
    <>
      <header className={'hdr' + (scrolled ? ' scrolled' : '')}>
        <div className="container hdr-inner">
          <Logo />
          <nav className="nav-links">
            {links.map(([h, l]) => <a key={h} href={h} className="nav-link">{l}</a>)}
          </nav>
          <div className="hdr-cta">
            <a href="#cta" className="btn btn-gold btn-sm">ابدأ هسه</a>
            <button className="menu-btn" onClick={() => setMenuOpen(o => !o)} aria-label="القائمة">
              {menuOpen ? <Ic.X width="20" height="20" /> : <Ic.Menu width="20" height="20" />}
            </button>
          </div>
        </div>
      </header>
      <div className={'mobile-menu' + (menuOpen ? '' : ' hidden')}>
        {links.map(([h, l]) => <a key={h} href={h} onClick={() => setMenuOpen(false)}>{l}</a>)}
        <a href="#cta" className="btn btn-gold" onClick={() => setMenuOpen(false)}>ابدأ هسه</a>
      </div>
    </>
  );
}
window.Header = Header;

// Phone mockup
function PhoneMockup() {
  return (
    <div className="hero-visual" aria-hidden="true">
      {/* Floating cards around phone */}
      <div className="floating-card" style={{ top: '6%', right: '-8px', animationDelay: '0s' }}>
        <span className="ic-wrap"><Ic.Brain width="18" height="18" /></span>
        <span>معلم ذكي</span>
      </div>
      <div className="floating-card" style={{ top: '32%', left: '-20px', animationDelay: '1.3s' }}>
        <span className="ic-wrap"><Ic.Target width="18" height="18" /></span>
        <span>اختبارات تكيفية</span>
      </div>
      <div className="floating-card" style={{ bottom: '24%', right: '-24px', animationDelay: '2.1s' }}>
        <span className="ic-wrap"><Ic.Map width="18" height="18" /></span>
        <span>خطة مخصصة</span>
      </div>
      <div className="floating-card" style={{ bottom: '4%', left: '-4px', animationDelay: '0.7s' }}>
        <span className="ic-wrap"><Ic.Sparkles width="18" height="18" /></span>
        <span>شرح على مزاجك</span>
      </div>

      <div className="phone">
        <div className="phone-screen">
          <PhoneInterior />
        </div>
      </div>
    </div>
  );
}

function PhoneInterior() {
  return (
    <div style={{ padding: '46px 16px 16px', display: 'flex', flexDirection: 'column', gap: 12, height: '100%' }}>
      <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '0 4px' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
          <span style={{ width: 28, height: 28, display: 'inline-flex', alignItems:'center', justifyContent: 'center', filter: 'drop-shadow(0 2px 8px rgba(244,195,90,0.5))' }}>
            <img src="enki-logo.png" alt="" style={{ width: '100%', height: '100%', objectFit: 'contain' }} />
          </span>
          <span style={{ fontWeight: 800, fontSize: 14, color: '#fff' }}>إنكي</span>
        </div>
        <span style={{ width: 28, height: 28, borderRadius: 9, background: 'rgba(255,255,255,0.05)', border: '1px solid rgba(255,255,255,0.1)', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', color: '#A9B6D3' }}>
          <Ic.Bell width="14" height="14" />
        </span>
      </div>

      <div style={{ marginTop: 4, padding: '14px 14px 16px', borderRadius: 16, background: 'linear-gradient(180deg, rgba(46,99,214,0.35) 0%, rgba(11,31,74,0.5) 100%)', border: '1px solid rgba(120,160,240,0.3)' }}>
        <div style={{ fontSize: 11, color: '#A9B6D3', marginBottom: 6 }}>خطة اليوم</div>
        <div style={{ fontSize: 15, fontWeight: 800, color: '#fff', lineHeight: 1.3 }}>3 مواد، 5 كويزات</div>
        <div className="progress" style={{ marginTop: 10 }}><span style={{ '--from': '40%', '--to': '72%', width: '72%' }}></span></div>
        <div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 6, fontSize: 11, color: '#BFD2F5' }}>
          <span>%72 منجز</span>
          <span>اليوم</span>
        </div>
      </div>

      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 8 }}>
        <div style={{ padding: '12px', borderRadius: 14, background: 'rgba(255,255,255,0.04)', border: '1px solid rgba(255,255,255,0.1)' }}>
          <div style={{ width: 26, height: 26, borderRadius: 8, background: 'rgba(244,195,90,0.15)', color: '#F4C35A', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', marginBottom: 8 }}>
            <Ic.Target width="14" height="14" />
          </div>
          <div style={{ fontWeight: 700, fontSize: 12, color: '#fff' }}>اختبار سريع</div>
          <div style={{ fontSize: 10, color: '#A9B6D3', marginTop: 2 }}>10 أسئلة</div>
        </div>
        <div style={{ padding: '12px', borderRadius: 14, background: 'rgba(255,255,255,0.04)', border: '1px solid rgba(255,255,255,0.1)' }}>
          <div style={{ width: 26, height: 26, borderRadius: 8, background: 'rgba(120,160,240,0.18)', color: '#BFD2F5', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', marginBottom: 8 }}>
            <Ic.Chart width="14" height="14" />
          </div>
          <div style={{ fontWeight: 700, fontSize: 12, color: '#fff' }}>مستواك</div>
          <div style={{ fontSize: 10, color: '#A9B6D3', marginTop: 2 }}>متوسط — يتحسّن</div>
        </div>
      </div>

      <div style={{ padding: '12px 14px', borderRadius: 14, background: 'rgba(255,255,255,0.04)', border: '1px solid rgba(255,255,255,0.1)' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 6 }}>
          <span style={{ width: 22, height: 22, borderRadius: 7, background: 'rgba(244,195,90,0.18)', color: '#F4C35A', display: 'inline-flex', alignItems: 'center', justifyContent: 'center' }}>
            <Ic.Sparkles width="12" height="12" />
          </span>
          <span style={{ fontSize: 11, fontWeight: 700, color: '#FFE9B8' }}>اقتراح إنكي</span>
        </div>
        <div style={{ fontSize: 12, color: '#DCE5F7', lineHeight: 1.45 }}>
          راجع الفصل الثالث بالفيزياء — نقاط ضعفك بالحركة.
        </div>
      </div>

      <div style={{ marginTop: 'auto', padding: '12px', borderRadius: 14, background: 'linear-gradient(180deg, #F4C35A 0%, #E3A72F 100%)', boxShadow: '0 10px 24px -8px rgba(227,167,47,0.6)', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 6, color: '#FFFFFF', fontWeight: 800, fontSize: 13, textShadow: '0 1px 0 rgba(120,70,0,0.35)' }}>
        ابدأ خطة اليوم
        <Ic.ArrowLeft width="14" height="14" />
      </div>
    </div>
  );
}

// 2. Hero
function Hero() {
  return (
    <section className="hero" id="home">
      <div className="hero-sage"><img src="enki-logo.png" alt="" /></div>
      <div className="container">
        <div className="hero-grid">
          <div>
            <div className="eyebrow"><span className="dot"></span>رفيقك الذكي بالدراسة • صُمم للعراق</div>
            <h1 style={{ marginTop: 18 }}>إنكي… <span className="accent">رفيقك الذكي</span><br/>بالدراسة</h1>
            <p className="hero-sub">ادرس بطريقة أسهل، سوّي اختبارات تكيفية، وخلي إنكي يبنيلك خطة دراسة تناسب مستواك ويشرحلك بأمثلة من الأشياء اللي تحبها.</p>
            <div className="cta-row">
              <a href="#cta" className="btn btn-gold btn-lg">ابدأ رحلتك<Ic.ArrowLeft width="18" height="18" /></a>
              <a href="#how" className="btn btn-ghost btn-lg"><Ic.Play width="14" height="14" />شوف شلون يشتغل</a>
            </div>
            <div className="trust-row">
              <span>مناسب للطلاب بالعراق</span><span className="sep">•</span>
              <span>تجربة سهلة</span><span className="sep">•</span>
              <span>مدعوم بالذكاء الاصطناعي</span>
            </div>
            <div className="download-block">
              <div className="lbl">التطبيق قريباً على iOS و Android</div>
              <div className="download-row">
                <StoreBtn kind="apple" />
                <StoreBtn kind="google" />
              </div>
            </div>
          </div>
          <PhoneMockup />
        </div>
      </div>
    </section>
  );
}
window.Hero = Hero;

// 3. Social proof
function SocialProof() {
  const ref = useReveal();
  const stats = [
    { num: '4.8/5', lbl: 'تقييم الطلاب', stars: true },
    { num: '+10,000', lbl: 'طالب بدأ ويا إنكي' },
    { num: '+50,000', lbl: 'اختبار مكتمل' },
    { num: '95%', lbl: 'حسّوا بتنظيم أكثر بدراستهم' },
  ];
  return (
    <section style={{ paddingTop: 30, paddingBottom: 60 }}>
      <div className="container">
        <div ref={ref} className="reveal">
          <p style={{ textAlign: 'center', color: '#BFD2F5', fontWeight: 600, marginBottom: 20, fontSize: 15 }}>
            طلاب هواية بدوا يدرسون أذكى ويا إنكي
          </p>
          <div className="stats-strip">
            {stats.map((s, i) => (
              <div key={i} className="glass stat-card">
                {s.stars && <div className="stars" style={{ marginBottom: 8 }}>★★★★★</div>}
                <div className="num">{s.num}</div>
                <div className="lbl">{s.lbl}</div>
              </div>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}
window.SocialProof = SocialProof;

// 4. Problem
function Problem() {
  const ref = useReveal();
  const items = [
    { t: 'ما تعرف منين تبدي', d: 'المواد هواية وكل يوم تحس البداية أصعب.', ic: Ic.Compass },
    { t: 'الوقت يضيع بسرعة', d: 'تدرس ساعات بس ما تعرف إذا دي تتقدم فعلاً.', ic: Ic.Clock },
    { t: 'ماكو خطة واضحة', d: 'بدون جدول ومتابعة، الدراسة تصير عشوائية.', ic: Ic.Map },
  ];
  return (
    <section>
      <div className="container">
        <div ref={ref} className="reveal section-head">
          <div className="eyebrow" style={{ marginBottom: 16 }}><span className="dot"></span>المشكلة</div>
          <h2>الدراسة مرات تصير فوضى</h2>
          <p>ملازم، محاضرات، امتحانات، وقت قليل… وبالنهاية ما تعرف منين تبدي. إنكي يرتبلك الطريق ويخليك تعرف شنو تدرس وهسه شنو تسوي.</p>
        </div>
        <div className="grid-3">
          {items.map((it, i) => (
            <div key={i} className="glass feat-card">
              <div className="feat-icon"><it.ic width="22" height="22" /></div>
              <h3>{it.t}</h3>
              <p style={{ marginTop: 8 }}>{it.d}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}
window.Problem = Problem;

// 5. Solution
function Solution() {
  const ref = useReveal();
  const items = [
    { t: 'معلم ذكي', d: 'اسأل، افهم، وراجع المواضيع بطريقة بسيطة وواضحة.', ic: Ic.Brain },
    { t: 'اختبارات تكيفية', d: 'الأسئلة تتغير حسب مستواك حتى تتطور أسرع.', ic: Ic.Target },
    { t: 'خطة مخصصة', d: 'خطة دراسة مبنية عليك، مو نسخة وحدة لكل الطلاب.', ic: Ic.Map },
    { t: 'شرح على مزاجك', d: 'إنكي يشرحلك بأمثلة من الأشياء اللي تحبها: أفلام، رياضة، طبخ، ألعاب، وأكثر.', ic: Ic.Sparkles },
  ];
  return (
    <section>
      <div className="container">
        <div ref={ref} className="reveal section-head">
          <div className="eyebrow" style={{ marginBottom: 16 }}><span className="dot"></span>الحل</div>
          <h2>إنكي يخلي كلشي أوضح</h2>
          <p>بدل ما تدرس عشوائي، إنكي يفهم مستواك ويساعدك بخطة واختبارات وتوجيهات تخليك تمشي خطوة بخطوة.</p>
        </div>
        <div className="grid-4">
          {items.map((it, i) => (
            <div key={i} className="glass feat-card">
              <div className="feat-icon"><it.ic width="22" height="22" /></div>
              <h3>{it.t}</h3>
              <p style={{ marginTop: 8 }}>{it.d}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}
window.Solution = Solution;
