// === Escena 02 — "Un interruptor" (la activación) ===
// Config del agente → switch "Buzón de emails" ON → nace su dirección propia → se copia
// con un clic. Contraste: NO es tu dirección. Y no te pedimos nada tuyo. Remate: "El que tú decidas."
function EscenaBA02({ t }){
  // LOCUCIÓN (audio/escena-02.mp3): abres la config → interruptor → buzón de emails →
  // ya está → su propia dirección → suya / única → no es tu dirección → dominio Dinaup →
  // exclusiva → la copias → no te pedimos nada → contraseña / entrar → ¿qué correo? → el que tú decidas.
  const T = {
    dialog:0.3,     // "Abres la configuración de tu agente"
    sw:3.2,         // "y enciendes un interruptor"
    label:4.5,      // "buzón de emails"
    check:6.1,      // "Ya está"
    dir:8.1,        // "su propia dirección de correo"
    suya:10.2,      // "Suya"
    unica:11.2,     // "Única"
    notuya:13.5,    // "no es tu dirección"
    dominio:16.8,   // "en un dominio de Dinaup"
    excl:18.3,      // "exclusiva para este agente"
    copia:20.5,     // "La copias con un clic"
    pedimos:22.5,   // "no te hemos pedido nada tuyo"
    pass:24.5,      // "Ni tu contraseña"
    buzon:26.1,     // "ni entrar en tu buzón"
    pregunta:28.9,  // "¿qué correo le llega?"
    remate:30.3,    // "El que tú decidas"
  };

  const DLG = { x:160, y:196, w:900 };
  const dlgP = clamp((t-T.dialog)/0.7,0,1), dlgE = Easing.easeOutCubic(dlgP);

  // Switch: se enciende justo tras el clic (3.2)
  const swP = clamp((t-T.sw)/0.3,0,1), swE = Easing.easeOutCubic(swP);
  const swOn = swP > 0.5;
  const labelGlow = t >= T.label && t < T.label+1.4 ? Math.sin((t-T.label)/1.4*Math.PI) : 0;
  const checkP = clamp((t-T.check)/0.45,0,1), checkE = Easing.easeOutBack(checkP);

  // Dirección propia
  const dirP = clamp((t-T.dir)/0.6,0,1), dirE = Easing.easeOutBack(dirP);
  const domDraw = Easing.easeInOutCubic(clamp((t-T.dominio)/0.7,0,1));
  const domTint = clamp((t-T.dominio)/0.5,0,1);
  const avP = clamp((t-T.excl)/0.4,0,1), avE = Easing.easeOutBack(avP);

  // Contraste "no es tu dirección"
  const notuyaP = clamp((t-T.notuya)/0.6,0,1), notuyaE = Easing.easeOutCubic(notuyaP);

  // Copiar → toast
  const toastP = clamp((t-T.copia-0.25)/0.5,0,1), toastE = Easing.easeOutBack(toastP);

  // Panel "lo que NO te pedimos"
  const pedimosP = clamp((t-T.pedimos)/0.6,0,1), pedimosE = Easing.easeOutCubic(pedimosP);
  const passP = clamp((t-T.pass)/0.5,0,1), passE = Easing.easeOutCubic(passP);
  const buzonP = clamp((t-T.buzon)/0.5,0,1), buzonE = Easing.easeOutCubic(buzonP);

  // Calma final: el mockup se atenúa, mandan la pregunta y el remate
  const calmaOp = t < T.pregunta ? 1 : lerp(1, 0.24, clamp((t-T.pregunta)/0.7,0,1));
  const quP = clamp((t-T.pregunta)/0.7,0,1), quE = Easing.easeOutCubic(quP);
  const remP = clamp((t-T.remate)/0.6,0,1), remE = Easing.easeOutCubic(remP);

  // Cursor: aparca → switch (clic 3.2) → botón copiar (clic 20.5)
  const cursor = { frames:[
    { t:0.8,  x:1500, y:940 },
    { t:3.0,  x:232, y:436 },
    { t:19.9, x:232, y:436 },
    { t:20.4, x:735, y:506 },
  ], clicks:[T.sw, T.copia] };

  const FilaCfg = ({ label, value })=>(
    <div style={{display:'flex', alignItems:'center', justifyContent:'space-between', padding:'13px 22px', borderBottom:'1px solid #F1F5F9'}}>
      <span className="f-plex" style={{fontSize:16, color:'#64748B'}}>{label}</span>
      <span className="f-plex" style={{fontSize:16, fontWeight:600, color:'#0F172A'}}>{value}</span>
    </div>
  );

  // Fila tachada del panel "no te pedimos"
  const FilaTachada = ({ txt, p, e })=>(
    <div style={{display:'flex', alignItems:'center', gap:14, padding:'14px 4px', opacity:clamp(p*1.3,0,1), transform:`translateY(${(1-e)*10}px)`}}>
      <span style={{width:26, height:26, borderRadius:100, background:'rgba(239,68,68,0.10)', border:'1px solid rgba(239,68,68,0.30)', display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0}}>
        <svg width="12" height="12" viewBox="0 0 12 12"><path d="M2 2 L10 10 M10 2 L2 10" stroke="#DC2626" strokeWidth="2" strokeLinecap="round"/></svg>
      </span>
      <span className="f-plex" style={{fontSize:19, fontWeight:500, color:'#94A3B8', textDecoration:'line-through'}}>{txt}</span>
    </div>
  );

  return (
    <SlideCanvas variant="light">
      <DemoHeader t={t} eyebrow="LA ACTIVACIÓN" title={<span>Un interruptor</span>}/>

      <div style={{position:'absolute', inset:0, opacity:calmaOp, filter:calmaOp<1?'saturate(0.55)':'none'}}>
        {/* Diálogo de configuración del agente */}
        <div style={{position:'absolute', left:DLG.x, top:DLG.y, width:DLG.w, opacity:dlgE, transform:`translateY(${(1-dlgE)*26}px)`}}>
          <div style={{background:'#fff', borderRadius:14, border:'1px solid #E2E8F0', boxShadow:'0 30px 80px rgba(15,23,42,0.10)', overflow:'hidden'}}>
            <BrowserChrome url="play.dinaup.com/App/Agentes/Ada" title="Dinaup — Configurar agente"/>
            <div style={{background:'#fff', padding:'22px 26px 26px'}}>
              {/* Cabecera del agente (azul, siglas IA — continuidad con escena 1) */}
              <div style={{display:'flex', alignItems:'center', gap:14, paddingBottom:16, borderBottom:'1px solid #F1F5F9'}}>
                <div style={{width:46, height:46, borderRadius:100, background:'linear-gradient(135deg,#38BDF8,#0085FF)', display:'flex', alignItems:'center', justifyContent:'center', boxShadow:'0 8px 20px rgba(0,133,255,0.28)'}}>
                  <span className="f-plex" style={{color:'#fff', fontSize:16, fontWeight:800}}>IA</span>
                </div>
                <div>
                  <div className="f-plex" style={{fontSize:19, fontWeight:700, color:'#0F172A'}}>Configurar agente</div>
                  <div className="f-plex" style={{fontSize:13, color:'#94A3B8'}}>Panadería El Molino, S.L.</div>
                </div>
              </div>

              <FilaCfg label="Nombre" value="Ada"/>

              {/* Fila del interruptor */}
              <div style={{display:'flex', alignItems:'center', gap:14, padding:'18px 22px', borderRadius:12, background:labelGlow>0?`rgba(0,133,255,${0.04+labelGlow*0.06})`:'transparent'}}>
                <div style={{width:46, height:26, borderRadius:100, background:swOn?'#0085FF':'#CBD5E1', position:'relative', boxShadow:swOn?'0 4px 12px rgba(0,133,255,0.35)':'none'}}>
                  <div style={{position:'absolute', top:3, left:lerp(3,23,swE), width:20, height:20, borderRadius:100, background:'#fff', boxShadow:'0 1px 4px rgba(15,23,42,0.3)'}}/>
                </div>
                <span className="f-plex" style={{fontSize:17, fontWeight:600, color:labelGlow>0?'#0085FF':'#0F172A'}}>Buzón de emails</span>
                {checkP > 0 && (
                  <svg width="24" height="24" viewBox="0 0 24 24" style={{transform:`scale(${lerp(0.4,1,checkE)})`}}>
                    <circle cx="12" cy="12" r="10" fill="rgba(16,185,129,0.15)"/>
                    <path d="M7 12.5 L10.5 16 L17 9" fill="none" stroke="#059669" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"/>
                  </svg>
                )}
              </div>

              {/* La dirección propia del agente */}
              {dirP > 0 && (
                <div style={{margin:'12px 22px 0', transformOrigin:'left center', transform:`scale(${lerp(0.92,1,dirE)}) translateY(${(1-dirE)*10}px)`, opacity:clamp(dirP*1.3,0,1)}}>
                  <div style={{display:'inline-flex', alignItems:'center', gap:12, background:'#F8FAFC', border:'1.5px solid #E2E8F0', borderRadius:12, padding:'12px 18px', boxShadow:'0 6px 18px rgba(15,23,42,0.05)'}}>
                    {avP > 0 && (
                      <div style={{width:28, height:28, borderRadius:100, background:'linear-gradient(135deg,#38BDF8,#0085FF)', display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0, transform:`scale(${lerp(0.4,1,avE)})`, boxShadow:'0 4px 12px rgba(0,133,255,0.3)'}}>
                        <span className="f-plex" style={{color:'#fff', fontSize:11, fontWeight:800}}>IA</span>
                      </div>
                    )}
                    <span className="f-mono" style={{display:'inline-block', width:440, whiteSpace:'nowrap', overflow:'hidden', fontSize:18, fontWeight:600, color:'#0F172A'}}>
                      elmolino_12_agente_4f2a…
                      <span style={{position:'relative', color:domTint>0?'#0085FF':'#334155'}}>
                        @dinaup-mail.com
                        <span style={{position:'absolute', left:0, right:0, bottom:-3, height:3, borderRadius:2, background:'#0085FF', transform:`scaleX(${domDraw})`, transformOrigin:'left'}}/>
                      </span>
                    </span>
                    {/* Botón copiar */}
                    <div style={{width:34, height:34, borderRadius:8, border:'1px solid #E2E8F0', background:'#fff', display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0}}>
                      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#64748B" strokeWidth="2">
                        <rect x="9" y="9" width="12" height="12" rx="2"/>
                        <path d="M5 15 V5 a2 2 0 0 1 2-2 h10"/>
                      </svg>
                    </div>
                  </div>

                  {/* Chips: Suya · Única */}
                  <div style={{display:'flex', gap:10, marginTop:14, marginLeft:2}}>
                    <StatusChip label="Suya, del agente" color="primary" start={T.suya} t={t}/>
                    <StatusChip label="Única" color="success" start={T.unica} t={t}/>
                  </div>
                </div>
              )}
            </div>
          </div>

          {/* Toast "Dirección copiada" */}
          {toastP > 0 && (
            <div style={{position:'absolute', left:470, top:452, display:'flex', alignItems:'center', gap:11, background:'#fff', border:'1.5px solid rgba(16,185,129,0.4)', borderRadius:12, padding:'12px 18px', boxShadow:'0 16px 40px rgba(16,185,129,0.20)', transform:`scale(${lerp(0.8,1,toastE)}) translateY(${(1-toastE)*-10}px)`, opacity:clamp(toastP*1.3,0,1)}}>
              <svg width="20" height="20" viewBox="0 0 24 24">
                <circle cx="12" cy="12" r="10" fill="rgba(16,185,129,0.15)"/>
                <path d="M7 12.5 L10.5 16 L17 9" fill="none" stroke="#059669" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"/>
              </svg>
              <span className="f-plex" style={{fontSize:15, fontWeight:700, color:'#0F172A'}}>Dirección copiada</span>
            </div>
          )}
        </div>

        {/* Columna derecha — contraste: no es tu dirección */}
        {notuyaP > 0 && (
          <div style={{position:'absolute', left:1130, top:300, width:480, opacity:clamp(notuyaP*1.2,0,1), transform:`translateY(${(1-notuyaE)*16}px)`}}>
            <div className="f-plex" style={{fontSize:13, fontWeight:700, letterSpacing:'1.8px', color:'#94A3B8', marginBottom:10}}>NO ES TU DIRECCIÓN</div>
            <div style={{display:'inline-flex', alignItems:'center', gap:10, background:'#F8FAFC', border:'1px solid #E2E8F0', borderRadius:12, padding:'11px 18px', opacity:0.7}}>
              <span className="f-mono" style={{fontSize:17, color:'#94A3B8', textDecoration:'line-through'}}>tu@panaderiaelmolino.com</span>
            </div>
            <div className="f-plex" style={{marginTop:10, fontSize:15, color:'#64748B'}}>Tu correo de siempre queda intacto.</div>
          </div>
        )}

        {/* Columna derecha — lo que NO te pedimos */}
        {pedimosP > 0 && (
          <div style={{position:'absolute', left:1130, top:540, width:480, background:'#fff', border:'1px solid #E2E8F0', borderRadius:18, padding:'22px 26px', boxShadow:'0 18px 46px rgba(15,23,42,0.08)', opacity:clamp(pedimosP*1.2,0,1), transform:`translateY(${(1-pedimosE)*20}px)`}}>
            <div className="f-plex" style={{fontSize:14, fontWeight:700, letterSpacing:'2px', color:'#0F172A', marginBottom:6}}>NO TE PEDIMOS NADA TUYO</div>
            <FilaTachada txt="Tu contraseña" p={passP} e={passE}/>
            <div style={{height:1, background:'#F1F5F9'}}/>
            <FilaTachada txt="Entrar en tu buzón" p={buzonP} e={buzonE}/>
          </div>
        )}

        <ScriptedCursor frames={cursor.frames} t={t} clickTimes={cursor.clicks}/>
      </div>

      {/* Pregunta + remate (sobre el mockup atenuado) */}
      {quP > 0 && (
        <div className="f-plex" style={{position:'absolute', left:0, right:0, top:432, textAlign:'center', fontSize:38, fontWeight:600, letterSpacing:'-0.01em', color:'#64748B', opacity:quE, transform:`translateY(${(1-quE)*12}px)`}}>
          Entonces… ¿qué correo le llega?
        </div>
      )}
      {remP > 0 && (
        <div className="f-plex" style={{position:'absolute', left:0, right:0, top:512, textAlign:'center', fontSize:70, fontWeight:800, letterSpacing:'-0.03em', opacity:remE, transform:`translateY(${(1-remE)*18}px)`}}>
          <span className="grad-text">El que tú decidas.</span>
        </div>
      )}
    </SlideCanvas>
  );
}
Object.assign(window, { EscenaBA02 });
