// Guías públicas: el launcher (con las capturas reales) y cómo se abren las
// citas con Nami. Lo que pasa DENTRO de una cita —stats, respuestas, finales—
// vive en el área de mecenas y no se toca desde aquí.

function Guides() {
  const { t } = useI18n();
  const [tab, setTab] = React.useState('launcher');

  const tabs = [
    { id: 'launcher', label: t('guides.tabLauncher'), icon: Icon.Download },
    { id: 'dating',   label: t('guides.tabDating'),   icon: Icon.Heart },
  ];

  return (
    <section id="guides">
      <div className="wrap">
        <Head eyebrow={t('guides.eyebrow')} title={t('guides.title')} lead={t('guides.lead')} />

        <div className="row" style={{ gap: 8, marginBottom: 30 }}>
          {tabs.map(({ id, label, icon: Ic }) => (
            <button key={id} onClick={() => setTab(id)}
              className={tab === id ? 'btn btn-gold' : 'btn btn-ghost'}
              aria-pressed={tab === id}>
              <Ic /> {label}
            </button>
          ))}
        </div>

        {tab === 'launcher' ? <LauncherGuide /> : <DatingGuide />}
      </div>
    </section>
  );
}

/* ── Guía del launcher ──────────────────────────────────────────── */
function LauncherGuide() {
  const { t, tl } = useI18n();

  return (
    <div className="stack" style={{ gap: 26 }}>
      <div className="card card-pad">
        <h3 className="display" style={guideS.h3}>{t('guides.launcher.title')}</h3>
        <p style={guideS.p}>{t('guides.launcher.intro')}</p>
        <div className="grid-2" style={{ marginTop: 18 }}>
          <Nota icon={Icon.Chest} text={t('guides.launcher.portable')} />
          <Nota icon={Icon.Lock} text={t('guides.launcher.saves')} />
        </div>
      </div>

      {tl('guides.launcher.steps').map((paso, i) => (
        <article key={i} className="card" style={{ ...guideS.step, flexDirection: i % 2 ? 'row-reverse' : 'row' }}>
          <figure style={guideS.shotWrap}>
            <img src={`/assets/launcher/${paso.img}.jpg`} alt={paso.title} loading="lazy" style={guideS.shot} />
          </figure>
          <div className="stack" style={{ gap: 12, padding: 26, flex: '1 1 320px', justifyContent: 'center', minWidth: 0 }}>
            <span className="mono" style={guideS.stepN}>{paso.n}</span>
            <h4 className="display" style={{ fontSize: 23 }}>{paso.title}</h4>
            <p style={guideS.p} dangerouslySetInnerHTML={{ __html: paso.body }} />
            {paso.tip && <p style={guideS.tip} dangerouslySetInnerHTML={{ __html: paso.tip }} />}
          </div>
        </article>
      ))}

      <div className="grid-2">
        <div className="card card-pad">
          <div className="eyebrow" style={{ marginBottom: 12 }}>{t('guides.launcher.extrasTitle')}</div>
          <h4 className="display" style={{ fontSize: 20, marginBottom: 8 }}>{t('guides.launcher.language.title')}</h4>
          <p style={guideS.p}>{t('guides.launcher.language.body')}</p>
          <h4 className="display" style={{ fontSize: 20, margin: '20px 0 8px' }}>{t('guides.launcher.silent.title')}</h4>
          <p style={guideS.p} dangerouslySetInnerHTML={{ __html: t('guides.launcher.silent.body') }} />
          <pre style={guideS.pre}>[launcher]{'\n'}auto=true</pre>
          <p style={guideS.p} dangerouslySetInnerHTML={{ __html: t('guides.launcher.silent.after') }} />
        </div>

        <div className="card card-pad">
          <div className="eyebrow" style={{ marginBottom: 14 }}>{t('guides.launcher.faqTitle')}</div>
          <div className="stack" style={{ gap: 14 }}>
            {tl('guides.launcher.faq').map((f, i) => (
              <div key={i}>
                <div style={{ fontWeight: 600, fontSize: 14.5, marginBottom: 4 }}>{f.q}</div>
                <div style={{ color: 'var(--tx-md)', fontSize: 14, lineHeight: 1.55 }}>{f.a}</div>
              </div>
            ))}
          </div>
        </div>
      </div>

      <div className="card card-pad">
        <div className="eyebrow" style={{ marginBottom: 14 }}>{t('guides.launcher.techTitle')}</div>
        <ul style={{ listStyle: 'none', display: 'grid', gap: 9 }}>
          {tl('guides.launcher.tech').map((linea, i) => (
            <li key={i} style={{ display: 'grid', gridTemplateColumns: '16px 1fr', gap: 10, color: 'var(--tx-md)', fontSize: 14, lineHeight: 1.55 }}>
              <Icon.Check style={{ width: 13, height: 13, color: 'var(--gold)', marginTop: 4 }} />
              <span dangerouslySetInnerHTML={{ __html: linea }} />
            </li>
          ))}
        </ul>
      </div>
    </div>
  );
}

function Nota({ icon: Ic, text }) {
  return (
    <div style={{ display: 'grid', gridTemplateColumns: '20px 1fr', gap: 12, alignItems: 'start' }}>
      <Ic style={{ width: 17, height: 17, color: 'var(--gold)', marginTop: 3 }} />
      <p style={{ color: 'var(--tx-md)', fontSize: 14, lineHeight: 1.55 }}>{text}</p>
    </div>
  );
}

/* ── Guía de desbloqueo de citas ────────────────────────────────── */
function DatingGuide() {
  const { t, tl } = useI18n();

  return (
    <div className="stack" style={{ gap: 26 }}>
      <div className="card card-pad">
        <h3 className="display" style={guideS.h3}>{t('guides.dating.title')}</h3>
        <p style={guideS.p}>{t('guides.dating.intro')}</p>
      </div>

      <div>
        <h4 className="display" style={guideS.h4}>{t('guides.dating.firstTitle')}</h4>
        <p style={{ ...guideS.p, marginBottom: 18 }}>{t('guides.dating.first')}</p>
        <div className="grid-2">
          {tl('guides.dating.paths').map((p, i) => (
            <article key={i} className="card card-pad" style={{ borderColor: i === 0 ? 'var(--gold)' : 'var(--line-soft)' }}>
              <span className="chip" style={{ marginBottom: 12, borderColor: i === 0 ? 'var(--gold)' : 'var(--line)', color: i === 0 ? 'var(--gold-hi)' : 'var(--tx-md)' }}>
                {p.tag}
              </span>
              <h5 className="display" style={{ fontSize: 20, marginBottom: 9 }}>{p.title}</h5>
              <p style={guideS.p} dangerouslySetInnerHTML={{ __html: p.body }} />
              {p.note && <p style={guideS.tip}>{p.note}</p>}
            </article>
          ))}
        </div>
      </div>

      <div>
        <h4 className="display" style={guideS.h4}>{t('guides.dating.chainTitle')}</h4>
        <p style={{ ...guideS.p, marginBottom: 18 }}>{t('guides.dating.chain')}</p>
        <div className="grid-auto">
          {tl('guides.dating.dates').map((d, i) => (
            <article key={i} className="card card-pad" style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
              <div className="row" style={{ gap: 12, alignItems: 'center' }}>
                {/* El número dice lo que el emoji no decía: que van en orden. */}
                <span className="display" style={{
                  width: 32, height: 32, flexShrink: 0, borderRadius: '50%',
                  border: '1px solid var(--line)', color: 'var(--gold-hi)',
                  display: 'grid', placeItems: 'center', fontSize: 16,
                }} aria-hidden>{i + 1}</span>
                <div style={{ minWidth: 0 }}>
                  <div className="display" style={{ fontSize: 21 }}>{d.name}</div>
                  <div className="mono" style={{ fontSize: 10, letterSpacing: '.16em', textTransform: 'uppercase', color: 'var(--tx-lo)' }}>{d.type}</div>
                </div>
              </div>
              <Fila k={t('guides.dating.labels.unlock')} v={d.unlock} destacado />
              <Fila k={t('guides.dating.labels.cost')}   v={d.cost} />
              <Fila k={t('guides.dating.labels.budget')} v={d.budget} />
              <Fila k={t('guides.dating.labels.mins')}   v={d.mins} />
              <Fila k={t('guides.dating.labels.outfit')} v={d.outfit} />
              <Fila k={t('guides.dating.labels.items')}  v={d.items} />
              {d.note && <p style={guideS.tip}>{d.note}</p>}
            </article>
          ))}
        </div>
      </div>

      <div className="grid-2">
        <div className="card card-pad">
          <h4 className="display" style={{ fontSize: 21, marginBottom: 10 }}>{t('guides.dating.outfitTitle')}</h4>
          <p style={guideS.p} dangerouslySetInnerHTML={{ __html: t('guides.dating.outfit') }} />
        </div>
        <div className="card card-pad">
          <h4 className="display" style={{ fontSize: 21, marginBottom: 12 }}>{t('guides.dating.requirementsTitle')}</h4>
          <ul style={{ listStyle: 'none', display: 'grid', gap: 8, marginBottom: 14 }}>
            {tl('guides.dating.requirements').map((r, i) => (
              <li key={i} style={{ display: 'grid', gridTemplateColumns: '16px 1fr', gap: 10, color: 'var(--tx-md)', fontSize: 14.5 }}>
                <Icon.Check style={{ width: 13, height: 13, color: 'var(--ok)', marginTop: 4 }} /> {r}
              </li>
            ))}
          </ul>
          <p style={guideS.tip}>{t('guides.dating.requirementsNote')}</p>
        </div>
      </div>

      <div className="card card-pad" style={{ borderColor: 'var(--gold)', background: 'linear-gradient(135deg, rgba(192,138,43,.10), transparent)' }}>
        <h4 className="display" style={{ fontSize: 22, marginBottom: 9 }}>{t('guides.dating.moreTitle')}</h4>
        <p style={{ ...guideS.p, marginBottom: 18 }}>{t('guides.dating.more')}</p>
        <a className="btn btn-gold" href="#members"><Icon.Book /> {t('guides.dating.moreCta')}</a>
      </div>
    </div>
  );
}

function Fila({ k, v, destacado }) {
  if (!v) return null;
  return (
    <div style={{ display: 'grid', gridTemplateColumns: '86px 1fr', gap: 12, alignItems: 'baseline' }}>
      <span className="mono" style={{ fontSize: 9.5, letterSpacing: '.14em', textTransform: 'uppercase', color: 'var(--tx-lo)' }}>{k}</span>
      <span style={{ fontSize: 14, lineHeight: 1.5, color: destacado ? 'var(--gold-hi)' : 'var(--tx-md)' }}>{v}</span>
    </div>
  );
}

const guideS = {
  h3: { fontSize: 'clamp(22px, 2.6vw, 30px)', marginBottom: 12 },
  h4: { fontSize: 'clamp(20px, 2.2vw, 26px)', marginBottom: 10 },
  p:  { color: 'var(--tx-md)', fontSize: 15, lineHeight: 1.65 },
  tip: {
    color: 'var(--tx-lo)', fontSize: 13.5, lineHeight: 1.6,
    borderLeft: '2px solid var(--gold)', paddingLeft: 14, marginTop: 12,
  },
  step: { display: 'flex', flexWrap: 'wrap', padding: 0, overflow: 'hidden', alignItems: 'stretch' },
  stepN: {
    fontSize: 10, letterSpacing: '.2em', color: 'var(--gold)',
    border: '1px solid var(--line)', borderRadius: 999, padding: '3px 10px', alignSelf: 'flex-start',
  },
  shotWrap: { margin: 0, flex: '1 1 380px', minWidth: 0, background: '#0F0903', display: 'flex', alignItems: 'center' },
  shot: { width: '100%', display: 'block' },
  pre: {
    fontFamily: 'var(--f-mono)', fontSize: 12.5, background: 'var(--bg0)',
    border: '1px solid var(--line-soft)', borderRadius: 'var(--r-sm)',
    padding: '12px 14px', margin: '12px 0', color: 'var(--gold-hi)', overflowX: 'auto',
  },
};

window.Guides = Guides;
