/* Sections — SERVICES + ACADEMY */

// ───────── SERVICES (tabs + list) ─────────
function Services() {
  const t = useT();
  const { lang } = useLang();
  const cats = Object.keys(GH_DATA.services);
  const [active, setActive] = React.useState(cats[0]);
  const cat = GH_DATA.services[active];

  return (
    <section id="services" className="section services-section">
      <div className="container">
        <Reveal style={{textAlign: 'center', marginBottom: 56}}>
          <div className="eyebrow" style={{justifyContent: 'center', display: 'flex'}}>{t('serv_eyebrow')}</div>
          <h2 className="h-section" style={{marginTop: 16}}>
            {t('serv_title')} <em>{t('serv_title_em')}</em>
          </h2>
          <p className="lead" style={{maxWidth: 480, margin: '24px auto 0'}}>{t('serv_intro')}</p>
        </Reveal>

        {/* Tabs */}
        <Reveal className="serv-tabs">
          {cats.map((c) => (
            <button
              key={c}
              className={`serv-tab ${active === c ? 'on' : ''}`}
              onClick={() => setActive(c)}
            >
              {GH_DATA.services[c][lang]}
            </button>
          ))}
        </Reveal>

        {/* Lista */}
        <div className="serv-list" key={active}>
          {cat.items.map((s, i) => (
            <Reveal key={s.es} delay={Math.min(4, Math.floor(i / 2) + 1)} className="serv-row">
              <div className="serv-name">
                <span className="serv-bullet">✦</span>
                {s[lang]}
              </div>
              <div className="serv-dots"></div>
              <div className="serv-time">{s.time}</div>
              <div className="serv-price">{s.price}</div>
            </Reveal>
          ))}
        </div>

        <Reveal style={{textAlign: 'center', marginTop: 56}}>
          <a href={GH_DATA.contact.booksy} target="_blank" rel="noreferrer" className="btn btn-solid btn-arrow">
            {t('serv_all')}
          </a>
        </Reveal>
      </div>

      <style>{`
        .services-section { background: var(--bg); }
        .serv-tabs {
          display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
          padding: 24px 0;
          border-top: 1px solid var(--gold-soft);
          border-bottom: 1px solid var(--gold-soft);
          margin-bottom: 48px;
        }
        .serv-tab {
          background: transparent; border: 1px solid transparent;
          color: var(--white); font: inherit; cursor: pointer;
          padding: 10px 22px;
          font-family: var(--sans); font-size: 11px; font-weight: 500;
          letter-spacing: 0.2em; text-transform: uppercase;
          transition: all 0.3s ease;
          border-radius: 999px;
        }
        .serv-tab:hover { color: var(--gold); }
        .serv-tab.on {
          background: var(--gold); color: var(--bg);
          border-color: var(--gold);
        }
        .serv-list {
          max-width: 920px; margin: 0 auto;
          display: flex; flex-direction: column;
        }
        .serv-row {
          display: grid; grid-template-columns: auto 1fr auto auto;
          gap: 16px; align-items: baseline;
          padding: 18px 0;
          border-bottom: 1px solid rgba(255,255,255,0.06);
        }
        .serv-name {
          font-family: var(--serif); font-size: 22px; font-weight: 400;
          display: flex; align-items: baseline; gap: 12px;
        }
        .serv-bullet { color: var(--gold); font-size: 11px; }
        .serv-dots {
          border-bottom: 1px dotted rgba(212,175,55,0.3);
          transform: translateY(-6px);
        }
        .serv-time {
          font-size: 12px; letter-spacing: 0.15em; text-transform: uppercase;
          color: var(--gray); min-width: 60px; text-align: right;
        }
        .serv-price {
          font-family: var(--serif); font-size: 22px; font-weight: 500;
          color: var(--gold); min-width: 88px; text-align: right;
        }
        @media (max-width: 700px) {
          .serv-row { grid-template-columns: 1fr auto; row-gap: 4px; }
          .serv-name { grid-column: 1 / -1; font-size: 18px; }
          .serv-dots { display: none; }
          .serv-time { font-size: 11px; text-align: left; }
          .serv-price { font-size: 18px; }
        }
      `}</style>
    </section>
  );
}

// ───────── ACADEMY — sección estrella ─────────
function Academy() {
  const t = useT();
  const { lang } = useLang();
  const [filter, setFilter] = React.useState('all');
  const filtered = GH_DATA.courses.filter((c) =>
    filter === 'all' ? true : c.mode === filter
  );

  return (
    <section id="academy" className="section academy-section">
      {/* Ghost word behind */}
      <div className="academy-ghost" aria-hidden="true">ACADEMY</div>

      <div className="container academy-inner">
        <Reveal className="academy-badge">
          <span className="dot"></span>
          <span>{t('acad_badge')}</span>
          <span className="dot"></span>
        </Reveal>

        <Reveal delay={1}>
          <div className="eyebrow" style={{color: 'var(--gold)'}}>{t('acad_eyebrow')}</div>
          <h2 className="h-hero" style={{marginTop: 16, color: 'var(--white)'}}>
            {t('acad_title')}<br/><em>{t('acad_title_em')}</em>
          </h2>
          <p className="lead" style={{maxWidth: 580, marginTop: 24}}>{t('acad_sub')}</p>
        </Reveal>

        {/* Two modes */}
        <div className="academy-modes">
          {[
            { key: 'in',  t: t('acad_in_t'),  s: t('acad_in_sub'),  b: GH_T.acad_in_b[lang] },
            { key: 'on',  t: t('acad_on_t'),  s: t('acad_on_sub'),  b: GH_T.acad_on_b[lang] },
          ].map((m, i) => (
            <Reveal key={m.key} delay={i + 1} className="mode-card">
              <div className="mode-head">
                <span className="mode-letter">{m.key === 'in' ? 'A' : 'B'}</span>
                <div>
                  <div className="mode-title serif">{m.t}</div>
                  <div className="mode-sub">{m.s}</div>
                </div>
              </div>
              <ul className="mode-list">
                {m.b.map((bullet, j) => (
                  <li key={j}><span>✦</span> {bullet}</li>
                ))}
              </ul>
            </Reveal>
          ))}
        </div>

        {/* Course catalog */}
        <Reveal className="academy-courses-head">
          <h3 className="h-sub serif">{lang === 'es' ? 'Catálogo de cursos' : 'Course catalog'}</h3>
          <div className="course-filters">
            {[
              ['all',        lang === 'es' ? 'Todos' : 'All'],
              ['presencial', t('mode_in')],
              ['online',     t('mode_on')],
            ].map(([k, l]) => (
              <button
                key={k}
                className={`course-filter ${filter === k ? 'on' : ''}`}
                onClick={() => setFilter(k)}
              >{l}</button>
            ))}
          </div>
        </Reveal>

        <div className="course-grid" key={filter}>
          {filtered.map((c, i) => (
            <Reveal key={c.id} delay={Math.min(4, (i % 4) + 1)} className={`course-card ${c.featured ? 'featured' : ''}`}>
              {c.featured && (
                <div className="course-featured-badge">{t('featured')}</div>
              )}
              <div className="course-img-wrap">
                {c.img ? (
                  <img src={c.img} alt={c[lang]} />
                ) : (
                  <div className="img-ph" style={{height: '100%'}}>
                    <div>
                      <span className="icon">✺</span>
                      <span className="lbl">{c[lang]}</span>
                    </div>
                  </div>
                )}
              </div>
              <div className="course-body">
                <div className="course-chips">
                  <span className={`chip ${c.mode === 'online' ? 'gold' : ''}`}>
                    {c.mode === 'online' ? t('mode_on') : t('mode_in')}
                  </span>
                  <span className="chip">{c[`duration_${lang}`] || `${c.hours || ''} ${t('hours')}`}</span>
                </div>
                <h4 className="course-title serif">{c[lang]}</h4>
                {c[`desc_${lang}`] && (
                  <p className="course-desc">{c[`desc_${lang}`]}</p>
                )}
                {c[`includes_${lang}`] && (
                  <ul className="course-includes">
                    {c[`includes_${lang}`].slice(0, 3).map((it, ix) => (
                      <li key={ix}><span>✦</span> {it}</li>
                    ))}
                    {c[`includes_${lang}`].length > 3 && (
                      <li className="more">+ {c[`includes_${lang}`].length - 3} {lang === 'es' ? 'más' : 'more'}</li>
                    )}
                  </ul>
                )}
                <div className="course-bottom">
                  <div className="course-price serif">
                    {c.price ? `${c.price}€` : (lang === 'es' ? 'Ver oferta' : 'See offer')}
                  </div>
                  {c.buyUrl ? (
                    <a href={c.buyUrl} target="_blank" rel="noreferrer" className="course-buy gold-link" style={{fontSize: 11}}>
                      {t('buy')}
                    </a>
                  ) : (
                    <a
                      href={`https://wa.me/${GH_DATA.contact.phoneRaw}?text=${encodeURIComponent(
                        (lang === 'es' ? 'Hola, me interesa el curso de ' : 'Hi, I\u2019m interested in the course ') + c[lang]
                      )}`}
                      target="_blank"
                      rel="noreferrer"
                      className="gold-link"
                      style={{fontSize: 11}}
                    >
                      {lang === 'es' ? 'Info por WhatsApp' : 'Info via WhatsApp'}
                    </a>
                  )}
                </div>
              </div>
            </Reveal>
          ))}
        </div>

        <Reveal style={{textAlign: 'center', marginTop: 48}}>
          <a href="#contact" className="btn btn-solid btn-arrow">{t('acad_all')}</a>
        </Reveal>
      </div>

      <style>{`
        .academy-section {
          background: linear-gradient(180deg, #050505 0%, #0a0a0a 100%);
          position: relative; overflow: hidden;
          border-block: 1px solid var(--gold-soft);
        }
        .academy-ghost {
          position: absolute;
          top: 60px; right: -40px;
          font-family: var(--serif);
          font-weight: 400;
          font-size: clamp(120px, 22vw, 320px);
          color: rgba(212,175,55,0.04);
          letter-spacing: -0.04em;
          line-height: 1;
          pointer-events: none;
          user-select: none;
          white-space: nowrap;
        }
        .academy-inner { position: relative; }
        .academy-badge {
          display: inline-flex; align-items: center; gap: 14px;
          padding: 10px 22px;
          border: 1px solid var(--gold);
          border-radius: 999px;
          color: var(--gold);
          font-family: var(--sans); font-size: 11px;
          letter-spacing: 0.3em; font-weight: 600;
          margin-bottom: 28px;
        }
        .academy-badge .dot {
          width: 6px; height: 6px; border-radius: 99px; background: var(--gold);
          display: inline-block;
        }
        .academy-modes {
          display: grid; grid-template-columns: 1fr 1fr;
          gap: 20px; margin-top: 56px;
        }
        .mode-card {
          padding: 32px;
          border: 1px solid var(--gold-line);
          background: rgba(212,175,55,0.03);
          transition: background 0.4s ease;
        }
        .mode-card:hover { background: rgba(212,175,55,0.06); }
        .mode-head { display: flex; gap: 20px; align-items: center; margin-bottom: 24px; }
        .mode-letter {
          width: 56px; height: 56px;
          border: 1px solid var(--gold);
          color: var(--gold);
          font-family: var(--serif); font-size: 28px; font-style: italic;
          display: flex; align-items: center; justify-content: center;
        }
        .mode-title { font-size: 28px; color: var(--white); }
        .mode-sub { font-size: 12px; letter-spacing: 0.2em; color: var(--gold); text-transform: uppercase; margin-top: 4px; }
        .mode-list {
          list-style: none; padding: 0; margin: 0;
          display: flex; flex-direction: column; gap: 12px;
        }
        .mode-list li { display: flex; gap: 12px; font-size: 14px; color: var(--cream); }
        .mode-list li span { color: var(--gold); font-size: 10px; }

        .academy-courses-head {
          margin-top: 80px; display: flex;
          justify-content: space-between; align-items: end;
          padding-bottom: 16px; border-bottom: 1px solid var(--gold-soft);
          gap: 24px; flex-wrap: wrap;
        }
        .course-filters { display: flex; gap: 8px; }
        .course-filter {
          background: transparent; border: 1px solid var(--gold-line);
          color: var(--cream); padding: 8px 16px;
          font-family: var(--sans); font-size: 11px; letter-spacing: 0.15em; text-transform: uppercase;
          cursor: pointer; border-radius: 999px;
          transition: all 0.3s ease;
        }
        .course-filter:hover { border-color: var(--gold); color: var(--gold); }
        .course-filter.on { background: var(--gold); color: var(--bg); border-color: var(--gold); }

        .course-grid {
          margin-top: 32px;
          display: grid; grid-template-columns: repeat(3, 1fr);
          gap: 20px;
        }
        .course-card {
          background: var(--bg-card);
          border: 1px solid rgba(255,255,255,0.05);
          transition: border-color 0.4s ease, transform 0.4s ease;
          position: relative;
        }
        .course-card:hover {
          border-color: var(--gold-line);
          transform: translateY(-4px);
        }
        .course-card.featured {
          border-color: var(--gold);
          box-shadow: 0 0 0 1px var(--gold), 0 12px 36px rgba(212,175,55,0.08);
        }
        .course-featured-badge {
          position: absolute; top: -1px; left: 16px;
          transform: translateY(-50%);
          background: var(--gold); color: var(--bg);
          font-family: var(--sans); font-size: 10px; font-weight: 700;
          letter-spacing: 0.25em; padding: 6px 14px;
          z-index: 1;
        }
        .course-buy { color: var(--gold) !important; }
        .course-img-wrap {
          aspect-ratio: 4/3;
          overflow: hidden;
          background: var(--bg-soft);
          border-bottom: 1px solid rgba(255,255,255,0.05);
        }
        .course-img-wrap img {
          width: 100%; height: 100%;
          object-fit: cover;
          transition: transform 0.6s cubic-bezier(.2,.7,.2,1);
        }
        .course-card:hover .course-img-wrap img { transform: scale(1.05); }
        .course-img { aspect-ratio: 4/3; border-bottom: 1px solid rgba(255,255,255,0.05); }
        .course-body { padding: 20px; }
        .course-chips { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
        .course-chips .chip { padding: 4px 10px; font-size: 10px; }
        .course-title { font-size: 22px; color: var(--white); line-height: 1.2; margin: 0 0 6px; }
        .course-level { font-size: 11px; letter-spacing: 0.15em; text-transform: uppercase; color: var(--gray); }
        .course-desc {
          font-size: 13px; line-height: 1.5;
          color: rgba(250,250,250,0.65);
          margin: 8px 0 12px;
        }
        .course-includes {
          list-style: none; padding: 0; margin: 0 0 4px;
          display: flex; flex-direction: column; gap: 6px;
        }
        .course-includes li {
          display: flex; gap: 8px; font-size: 12px;
          color: var(--cream); line-height: 1.4;
        }
        .course-includes li span {
          color: var(--gold); font-size: 9px; flex-shrink: 0;
          margin-top: 4px;
        }
        .course-includes li.more {
          color: var(--gold); font-style: italic;
          padding-left: 16px; font-size: 11px;
        }
        .course-bottom {
          display: flex; align-items: baseline; justify-content: space-between;
          margin-top: 20px; padding-top: 16px;
          border-top: 1px solid rgba(255,255,255,0.06);
        }
        .course-price { font-size: 28px; color: var(--gold); }

        @media (max-width: 1000px) {
          .course-grid { grid-template-columns: repeat(2, 1fr); }
        }
        @media (max-width: 700px) {
          .academy-modes { grid-template-columns: 1fr; }
          .course-grid { grid-template-columns: 1fr; }
        }
      `}</style>
    </section>
  );
}

window.Services = Services;
window.Academy = Academy;
