// === primitives-extra.jsx ===
// Primitives propias de la presentación definitiva ("Un día entero. Una plataforma.").
// Se cargan después de primitives.jsx. Sin hooks con destructuring para no
// redeclarar consts globales de otros scripts babel.

// =====================================================================
// TimeBadge — hilo conductor del día. Píldora oscura arriba-izquierda
// con la hora en mono + etiqueta del bloque. Entra con easeOutBack.
// =====================================================================
function TimeBadge({ t, hora, label, start=0.2 }){
  const p = clamp((t-start)/0.5, 0, 1);
  const e = Easing.easeOutBack(p);
  return (
    <div style={{
      position:'absolute', top:44, left:60, zIndex:6,
      display:'flex', alignItems:'center', gap:12,
      padding:'10px 18px 10px 14px',
      background:'rgba(15,23,42,0.92)',
      border:'1px solid rgba(255,255,255,0.10)',
      borderRadius:14,
      boxShadow:'0 12px 32px rgba(15,23,42,0.25)',
      backdropFilter:'blur(10px)',
      opacity: clamp(p*1.3,0,1),
      transform:`translateY(${(1-e)*-14}px) scale(${lerp(0.85,1,e)})`,
    }}>
      <div style={{width:34,height:34,borderRadius:10,background:'linear-gradient(135deg,#0085FF,#56E16A)',display:'flex',alignItems:'center',justifyContent:'center'}}>
        <svg width="17" height="17" viewBox="0 0 24 24" fill="none">
          <circle cx="12" cy="12" r="9" stroke="#fff" strokeWidth="1.8"/>
          <path d="M12 7 V12 L15.5 14" stroke="#fff" strokeWidth="1.8" strokeLinecap="round"/>
        </svg>
      </div>
      <div>
        <div className="f-mono" style={{fontSize:21, fontWeight:700, color:'#fff', lineHeight:1, letterSpacing:'0.02em'}}>{hora}</div>
        <div className="f-mono" style={{fontSize:9, fontWeight:600, color:'rgba(255,255,255,0.55)', letterSpacing:'2.5px', marginTop:3, textTransform:'uppercase'}}>{label}</div>
      </div>
    </div>
  );
}

// =====================================================================
// KeyCap — tecla física (F2, F6…) que aparece y "se pulsa" en pressT.
// =====================================================================
function KeyCap({ t, label, start=0, pressT=null, size=54 }){
  const p = clamp((t-start)/0.4, 0, 1);
  const e = Easing.easeOutBack(p);
  const pressing = pressT !== null && t >= pressT && t < pressT + 0.35;
  return (
    <span style={{
      display:'inline-flex', alignItems:'center', justifyContent:'center',
      minWidth:size, height:size, padding:'0 14px',
      background: pressing ? 'linear-gradient(180deg,#0085FF,#0066CC)' : 'linear-gradient(180deg,#FDFEFF,#E8EDF4)',
      color: pressing ? '#fff' : '#0F172A',
      border:`1px solid ${pressing ? '#0066CC' : '#C6CFDB'}`,
      borderBottom:`${pressing ? 2 : 4}px solid ${pressing ? '#00509E' : '#AAB6C6'}`,
      borderRadius:10,
      fontFamily:"'JetBrains Mono',monospace",
      fontSize:size*0.38, fontWeight:700,
      boxShadow: pressing ? '0 1px 4px rgba(0,133,255,0.4)' : '0 6px 14px rgba(15,23,42,0.14)',
      transform:`scale(${lerp(0.7,1,e)}) translateY(${pressing ? 2 : 0}px)`,
      opacity: clamp(p*1.3,0,1),
      transition:'background 120ms, border 120ms',
    }}>{label}</span>
  );
}

// =====================================================================
// TerminalChrome — chrome estilo terminal macOS/Linux (del deck dev).
// =====================================================================
function TerminalChrome({ title='bash — molino@dinaup', style }){
  return (
    <div style={{height:32, background:'#2D2D2D', display:'flex', alignItems:'center', padding:'0 12px', gap:8, borderBottom:'1px solid #1F1F1F', ...style}}>
      <div style={{display:'flex', gap:6}}>
        <div style={{width:12, height:12, borderRadius:100, background:'#FF5F56'}}/>
        <div style={{width:12, height:12, borderRadius:100, background:'#FFBD2E'}}/>
        <div style={{width:12, height:12, borderRadius:100, background:'#27C93F'}}/>
      </div>
      <div style={{flex:1, textAlign:'center', fontSize:11, color:'#999', fontFamily:"'JetBrains Mono',monospace"}}>{title}</div>
    </div>
  );
}

// =====================================================================
// HttpResponseBubble — respuesta HTTP con status coloreado (del deck dev).
// =====================================================================
function HttpResponseBubble({ status=200, time='80ms', body, t, start=0, style }){
  const p = clamp((t-start)/0.5, 0, 1);
  const e = Easing.easeOutBack(p);
  const color = status < 300 ? '#10B981' : status < 500 ? '#F59E0B' : '#EF4444';
  const bg    = status < 300 ? 'rgba(16,185,129,0.10)' : status < 500 ? 'rgba(245,158,11,0.10)' : 'rgba(239,68,68,0.10)';
  return (
    <div style={{
      display:'inline-flex', flexDirection:'column', gap:8,
      padding:'14px 18px',
      background:bg,
      border:`1px solid ${color}50`,
      borderRadius:10,
      fontFamily:"'JetBrains Mono',monospace",
      transform:`scale(${lerp(0.85,1,e)})`,
      opacity: clamp(p*1.2, 0, 1),
      ...style,
    }}>
      <div style={{display:'flex', alignItems:'center', gap:10, fontSize:13}}>
        <span style={{color, fontWeight:700, fontSize:16}}>{status}</span>
        <span style={{color:'#94A3B8'}}>{status===200?'OK':status===201?'Created':'Response'}</span>
        <span style={{color:'#64748B', marginLeft:'auto', fontSize:11}}>· {time}</span>
      </div>
      {body && <div style={{fontSize:11, color:'#A5B4CB', whiteSpace:'pre-wrap'}}>{body}</div>}
    </div>
  );
}

// =====================================================================
// ToolBadge — chip de herramienta externa (n8n, Zapier, tu app…).
// =====================================================================
function ToolBadge({ name, color='#0085FF', t, start=0, dark=false }){
  const p = clamp((t-start)/0.4, 0, 1);
  const e = Easing.easeOutBack(p);
  return (
    <div style={{
      display:'inline-flex', alignItems:'center', gap:10,
      padding:'10px 16px',
      background: dark ? 'rgba(255,255,255,0.05)' : '#fff',
      border:`1px solid ${dark ? 'rgba(255,255,255,0.12)' : '#E2E8F0'}`,
      borderRadius:100,
      transform:`scale(${lerp(0.7,1,e)})`,
      opacity:clamp(p*1.3, 0, 1),
      boxShadow: dark ? 'none' : '0 2px 8px rgba(15,23,42,0.06)',
    }}>
      <div style={{
        width:28, height:28, borderRadius:100, background:color,
        display:'flex', alignItems:'center', justifyContent:'center',
        color:'#fff', fontWeight:700, fontSize:13, fontFamily:"'IBM Plex Sans',sans-serif",
      }}>{name.charAt(0).toUpperCase()}</div>
      <span className="f-plex" style={{fontSize:14, fontWeight:600, color: dark ? '#fff' : '#0F172A'}}>{name}</span>
    </div>
  );
}

// =====================================================================
// PhoneFrame — marco de móvil sencillo para demos de fichaje/QR.
// =====================================================================
function PhoneFrame({ w=120, h=220, children, style }){
  return (
    <div style={{width:w, height:h, background:'#0F172A', borderRadius:18, padding:4, boxShadow:'0 14px 34px rgba(15,23,42,0.35)', ...style}}>
      <div style={{width:'100%', height:'100%', borderRadius:14, overflow:'hidden', background:'#fff', position:'relative'}}>
        {children}
        <div style={{position:'absolute', top:5, left:'50%', transform:'translateX(-50%)', width:w*0.32, height:5, borderRadius:100, background:'rgba(15,23,42,0.18)'}}/>
      </div>
    </div>
  );
}

// =====================================================================
// FingerTap — pulsación táctil: círculo que aparece y expande en (x,y)
// en cada instante de taps[]. Para demos TPV (dedo, no cursor).
// =====================================================================
function FingerTap({ t, taps=[] }){
  const active = taps.find(tp => t >= tp.t && t < tp.t + 0.5);
  if (!active) return null;
  const p = clamp((t - active.t)/0.5, 0, 1);
  return (
    <div style={{position:'absolute', left:active.x, top:active.y, zIndex:30, pointerEvents:'none', transform:'translate(-50%,-50%)'}}>
      <div style={{
        position:'absolute', left:'50%', top:'50%', transform:`translate(-50%,-50%) scale(${lerp(0.4,2.0,Easing.easeOutCubic(p))})`,
        width:44, height:44, borderRadius:100,
        border:'3px solid rgba(0,133,255,0.85)',
        opacity: 1-p,
      }}/>
      <div style={{
        position:'absolute', left:'50%', top:'50%', transform:'translate(-50%,-50%)',
        width:26, height:26, borderRadius:100,
        background:'rgba(0,133,255,0.35)',
        border:'2px solid rgba(255,255,255,0.9)',
        opacity: 1 - p*0.6,
      }}/>
    </div>
  );
}

// =====================================================================
// cursorPathAt — interpola frames [{t,x,y,arc?}] → {x,y} en el tiempo t.
// (extraído del patrón de pymes/slide-06 para reutilizar en tarjetas voladoras)
// =====================================================================
function cursorPathAt(frames, t){
  if (t <= frames[0].t) return { x:frames[0].x, y:frames[0].y };
  for (let i=0;i<frames.length-1;i++){
    if (t>=frames[i].t && t<=frames[i+1].t){
      const p = (t-frames[i].t)/(frames[i+1].t-frames[i].t);
      const e = Easing.easeInOutCubic(p);
      let x = lerp(frames[i].x, frames[i+1].x, e);
      let y = lerp(frames[i].y, frames[i+1].y, e);
      if (frames[i].arc) y -= Math.sin(p*Math.PI)*frames[i].arc;
      return {x,y};
    }
  }
  const last = frames[frames.length-1];
  return {x:last.x, y:last.y};
}

// =====================================================================
// DemoHeader — cabecera estándar de los slides demo: eyebrow + h2.
// =====================================================================
function DemoHeader({ t, eyebrow, title, color='var(--dn-primary)' }){
  const p = clamp(t/0.5, 0, 1);
  return (
    <div style={{position:'absolute',top:40,left:0,right:0,textAlign:'center',opacity:p,zIndex:5}}>
      <div className="f-plex" style={{fontSize:14,fontWeight:600,letterSpacing:'2px',color}}>{eyebrow}</div>
      <h2 className="f-plex" style={{fontSize:42,fontWeight:700,letterSpacing:'-0.03em',margin:'14px 0 0',color:'#0F172A'}}>{title}</h2>
    </div>
  );
}

Object.assign(window, { TimeBadge, KeyCap, TerminalChrome, HttpResponseBubble, ToolBadge, PhoneFrame, FingerTap, cursorPathAt, DemoHeader });
