// Activa Soluciones — Booking dialog (multi-step)

const BookingDialog = ({ open, onClose }) => {
  const [step, setStep] = React.useState(0);
  const [form, setForm] = React.useState({ industry: '', revenue: '', name: '', email: '' });

  React.useEffect(() => {
    if (open) { setStep(0); setForm({ industry: '', revenue: '', name: '', email: '' }); }
  }, [open]);

  if (!open) return null;

  const industries = ['Retail & e-commerce', 'Banca & seguros', 'Industrial & B2B', 'Salud & farma', 'Servicios', 'Otra'];
  const revenues = ['Menos de S/ 20M', 'S/ 20M — 100M', 'S/ 100M — 500M', 'Más de S/ 500M'];

  return (
    <div className="dialog-scrim" onClick={onClose}>
      <div className="dialog" onClick={(e) => e.stopPropagation()}>
        <button className="close" onClick={onClose} aria-label="Cerrar">
          <svg width="18" height="18" viewBox="0 0 24 24"><path className="li" stroke="currentColor" d="M6 6l12 12M18 6L6 18"/></svg>
        </button>

        <div className="bd-steps">
          {[0, 1, 2, 3].map((i) => (
            <div key={i} className={"bd-step " + (i <= step ? "done" : "")}>
              <span className="bd-step-n">{i + 1}</span>
              <span className="bd-step-bar"></span>
            </div>
          ))}
        </div>

        {step === 0 && (
          <>
            <h3 className="bd-title">¿En qué industria operas?</h3>
            <p className="bd-lead">Esto nos ayuda a asignar el equipo correcto para tu diagnóstico.</p>
            <div className="bd-grid">
              {industries.map((i) => (
                <button key={i} className={"bd-choice " + (form.industry === i ? "on" : "")}
                  onClick={() => { setForm({ ...form, industry: i }); setStep(1); }}>
                  {i}
                </button>
              ))}
            </div>
          </>
        )}

        {step === 1 && (
          <>
            <h3 className="bd-title">¿Cuál es la facturación anual?</h3>
            <p className="bd-lead">Operamos exclusivamente con mid-large companies (S/ 20M+).</p>
            <div className="bd-grid bd-grid-1">
              {revenues.map((r) => (
                <button key={r} className={"bd-choice " + (form.revenue === r ? "on" : "")}
                  onClick={() => { setForm({ ...form, revenue: r }); setStep(2); }}>
                  {r}
                </button>
              ))}
            </div>
          </>
        )}

        {step === 2 && (
          <>
            <h3 className="bd-title">¿Cómo nos contactamos?</h3>
            <p className="bd-lead">Te escribimos en menos de 24h hábiles desde el equipo regional.</p>
            <div className="bd-form">
              <label>
                <span>Nombre completo</span>
                <input value={form.name} onChange={(e) => setForm({ ...form, name: e.target.value })} placeholder="María Reátegui" autoFocus />
              </label>
              <label>
                <span>Email corporativo</span>
                <input value={form.email} onChange={(e) => setForm({ ...form, email: e.target.value })} placeholder="m.reategui@grupo.pe" type="email" />
              </label>
              <button
                className="btn primary bd-submit"
                disabled={!form.name || !form.email}
                onClick={() => setStep(3)}
              >
                Solicitar diagnóstico <span className="arr arrow-rise">→</span>
              </button>
            </div>
          </>
        )}

        {step === 3 && (
          <div className="bd-done">
            <div className="bd-check">
              <svg width="40" height="40" viewBox="0 0 24 24"><path className="li" stroke="white" strokeWidth="2.2" d="M5 12l5 5L20 7"/></svg>
            </div>
            <h3 className="bd-title">Solicitud enviada.</h3>
            <p className="bd-lead">
              Recibirás un correo de <b>{(form.industry || 'tu equipo').slice(0, 24)}</b> en menos de 24h con la propuesta del diagnóstico ejecutivo.
            </p>
            <button className="btn primary" onClick={onClose}>Cerrar</button>
          </div>
        )}

        <style>{`
          .bd-steps { display: flex; gap: 6px; margin-bottom: 28px; }
          .bd-step { display: flex; align-items: center; gap: 6px; flex: 1; }
          .bd-step-n {
            width: 22px; height: 22px; border-radius: 999px;
            background: var(--activa-gray-200); color: var(--color-fg-3);
            display: grid; place-items: center;
            font-family: var(--font-display); font-weight: 700; font-size: 11px;
            transition: all 220ms var(--ease-rise);
          }
          .bd-step.done .bd-step-n { background: var(--gradient-brand); color: #fff; }
          .bd-step-bar { flex: 1; height: 2px; background: var(--activa-gray-200); border-radius: 2px; }
          .bd-step.done .bd-step-bar { background: var(--color-accent); }
          .bd-step:last-child .bd-step-bar { display: none; }

          .bd-title {
            font-family: var(--font-display); font-weight: 800;
            font-size: 24px; letter-spacing: -0.02em;
            color: var(--color-fg-1); margin: 0 0 8px;
          }
          .bd-lead {
            font-family: var(--font-body); font-size: 14px; line-height: 1.55;
            color: var(--color-fg-2); margin: 0 0 24px;
          }
          .bd-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
          .bd-grid.bd-grid-1 { grid-template-columns: 1fr; }
          .bd-choice {
            background: #fff; border: 1.5px solid var(--color-border);
            border-radius: 10px; padding: 14px 16px;
            font-family: var(--font-body); font-weight: 600; font-size: 14px;
            color: var(--color-fg-1); cursor: pointer; text-align: left;
            transition: all 180ms var(--ease-rise);
          }
          .bd-choice:hover, .bd-choice.on {
            border-color: var(--color-accent); color: var(--color-accent);
            background: #FEF3E0;
          }

          .bd-form { display: flex; flex-direction: column; gap: 14px; }
          .bd-form label { display: flex; flex-direction: column; gap: 6px; }
          .bd-form label span {
            font-family: var(--font-body); font-weight: 600; font-size: 12px;
            color: var(--color-fg-1); letter-spacing: 0.02em;
          }
          .bd-form input {
            font-family: var(--font-body); font-size: 14px; color: var(--color-fg-1);
            background: #fff; border: 1.5px solid var(--color-border);
            border-radius: 10px; padding: 12px 14px; outline: none;
            transition: 220ms var(--ease-rise);
          }
          .bd-form input:focus {
            border-color: var(--activa-blue-500);
            box-shadow: 0 0 0 4px rgba(46,92,158,0.15);
          }
          .bd-submit { justify-content: center; margin-top: 8px; }
          .bd-submit:disabled { opacity: 0.5; cursor: not-allowed; }

          .bd-done { text-align: center; padding: 12px 0; }
          .bd-check {
            width: 64px; height: 64px; margin: 0 auto 22px;
            border-radius: 999px;
            background: var(--gradient-accent);
            display: grid; place-items: center;
            box-shadow: var(--shadow-accent);
          }
        `}</style>
      </div>
    </div>
  );
};
