// === Caso de éxito 1 · Minigolf (15s) — Flex: la sección «Partidas», campo a campo ===
// Patrón común de los 3 casos de éxito (F4/F5/F6): badge oscuro arriba-izquierda
// («CASOS DE ÉXITO · n de 3», estilo TimeBadge sin hora) + título del caso centrado,
// UNA card de sección grande y centrada cuyo interior es un FORMULARIO de dos
// columnas que se rellena campo a campo (label mono + caja de input + valor de
// ejemplo + chip de tipo), mini-resumen conectado a la derecha (el dato existente
// se reutiliza) y sello final. Cadencia pausada: ~1,5s por campo.

function SlideFlexMinigolf({ t }){

  // --- Timeline (sincronizada con cues slide_flexminigolf) ---
  // 0.5-3.0  entra la card «Partidas» vacía        (cue «Caso real: un minigolf»)
  // 3.0-9.4  campos de uno en uno: 3.4/4.9/6.4/7.9 — cada beat: aparece el slot
  //          (label+caja vacía) y su valor se rellena (cues «Crea la sección…»)
  // 9.4-12.2 mini-resumen «Clientes» conectado      (cue «Cada campo, un clic»)
  // 12.2-14.2 sello «En su ERP. Sin Excel.» — reposo (cue «Su operativa entera…»)
  const FIELDS = [
    { at:3.4, label:'Hora de inicio',  value:'17:30',   type:'fecha',    typed:true,  x:0,   y:0,   w:282 },
    { at:4.9, label:'Nº de jugadores', value:'3',       type:'numero',   typed:true,  x:298, y:0,   w:282 },
    { at:6.4, label:'Pista',           value:'Pista 4', type:'selector', typed:false, x:0,   y:96,  w:282 },
    { at:7.9, label:'Ticket de venta', value:'TK-1041', type:'enlace',   typed:false, x:0,   y:192, w:580 },
  ];
  const clicks = FIELDS.map(f => f.at);
  const linkAt = 9.6;    // la línea conectora se dibuja
  const miniAt = 10.1;   // mini-card «Clientes (1.284)»
  const textAt = 10.8;   // «Los jugadores se eligen de Clientes»
  const chipAt = 11.3;   // chip «Ya existía»
  const sealAt = 12.4;   // sello final (termina ~13.2, ≥0.8s antes del dur 15)

  // --- Geometría ---
  // Card: 640×503 centrada → x 640-1280, y 205-708.
  // Formulario (IDÉNTICO en F4/F5/F6): zona de 580×258 en (30,123) rel. card.
  // 3 filas con paso vertical 96: fila 1 = dos celdas emparejadas de 282 (gutter 16),
  // fila 2 = una celda a media anchura, fila 3 = campo a ancho completo (580).
  // Cada campo: label mono 11px (h 14 + gap 6) + caja de input h 46 (borde #D3DDE8, radio 10).
  // Botón «+ Añadir campo» (rel. card): top 429, h 48 → click en (952, 658).
  // El input «Nº de jugadores» (celda dcha. de fila 1, centro abs. 371) ancla la línea a la mini-card Clientes.
  const CARD = { left:640, top:205, w:640, h:503 };
  const F_W = 580, F_LBL = 14, F_LBLGAP = 6, F_IN = 46;  // zona, label, gap, alto de input
  const fieldsDone = FIELDS.filter(f => t >= f.at + 1.0).length;

  // --- Catálogo de tipos de dato (paleta de chips: Número=azul, Texto=gris,
  // Fecha/Hora=violeta, Importe=verde, Selector=ámbar, Enlace=brand) ---
  const TYPES = {
    texto:    { label:'Texto',      fg:'#64748B', bg:'#F1F5F9',               brd:'#E2E8F0' },
    numero:   { label:'Número',     fg:'#1D4ED8', bg:'rgba(37,99,235,0.08)',  brd:'rgba(37,99,235,0.30)' },
    fecha:    { label:'Fecha/Hora', fg:'#7C3AED', bg:'rgba(124,58,237,0.08)', brd:'rgba(124,58,237,0.30)' },
    importe:  { label:'Importe €',  fg:'#059669', bg:'rgba(5,150,105,0.08)',  brd:'rgba(5,150,105,0.30)' },
    selector: { label:'Selector',   fg:'#B45309', bg:'rgba(217,119,6,0.10)',  brd:'rgba(217,119,6,0.32)' },
    enlace:   { label:'Enlace',     fg:'#0085FF', bg:'rgba(0,133,255,0.08)',  brd:'rgba(0,133,255,0.30)' },
  };
  const chipIcon = (kind, color) => {
    const s = { stroke:color, strokeWidth:2, strokeLinecap:'round', strokeLinejoin:'round', fill:'none' };
    if (kind === 'texto')    return <svg width="12" height="12" viewBox="0 0 24 24"><path d="M6 7 V5 H18 V7 M12 5 V19 M9.4 19 H14.6" {...s}/></svg>;
    if (kind === 'numero')   return <svg width="12" height="12" viewBox="0 0 24 24"><path d="M9.6 4.8 L8 19.2 M16 4.8 L14.4 19.2 M5.4 9.4 H19 M5 14.6 H18.6" {...s}/></svg>;
    if (kind === 'fecha')    return <svg width="12" height="12" viewBox="0 0 24 24"><rect x="4" y="5.5" width="16" height="14.5" rx="3" {...s}/><path d="M8 3.5 V7.5 M16 3.5 V7.5 M4 10.5 H20" {...s}/></svg>;
    if (kind === 'importe')  return <svg width="12" height="12" viewBox="0 0 24 24"><path d="M17 7.2 A6.4 6.4 0 1 0 17 16.8 M4.8 10.4 H12.2 M4.8 13.6 H11.4" {...s}/></svg>;
    if (kind === 'selector') return <svg width="12" height="12" viewBox="0 0 24 24"><rect x="3.6" y="6" width="16.8" height="12" rx="3" {...s}/><path d="M9.2 10.6 L12 13.4 L14.8 10.6" {...s}/></svg>;
    return <svg width="12" height="12" viewBox="0 0 24 24"><path d="M10 13 a5 5 0 0 0 7.5 .5 l2 -2 a5 5 0 0 0 -7 -7 l-1.2 1.2 M14 11 a5 5 0 0 0 -7.5 -.5 l-2 2 a5 5 0 0 0 7 7 l1.2 -1.2" {...s}/></svg>;
  };

  // --- Cursor: baja al botón, 4 clicks (uno por campo), se aparta ---
  const cursorFrames = [
    { t:2.55, x:1580, y:950 },
    { t:3.28, x:952,  y:650, arc:70 },
    { t:8.20, x:952,  y:650 },
    { t:8.95, x:1580, y:935, arc:50 },
  ];
  const cur = cursorPathAt(cursorFrames, t);
  const clicking = clicks.some(c => t >= c && t < c + 0.5);
  const btnPressed = clicks.some(c => t >= c && t < c + 0.22);

  // --- Iconos SVG de línea (sin recuadro, identidad Dinaup) ---
  const icon = (kind, size=22, color='var(--dn-primary)') => {
    const s = { stroke:color, strokeWidth:1.9, strokeLinecap:'round', strokeLinejoin:'round', fill:'none' };
    if (kind === 'flag') return (
      <svg width={size} height={size} viewBox="0 0 24 24">
        <path d="M6 21 V4" {...s}/>
        <path d="M6 4.6 H16.8 L14.2 8 L16.8 11.4 H6" {...s}/>
      </svg>
    );
    if (kind === 'hole') return (
      <svg width={size} height={size} viewBox="0 0 24 24">
        <path d="M12 15.5 V3.6" {...s}/>
        <path d="M12 4 L18.4 6.2 L12 8.6 Z" {...s}/>
        <ellipse cx="12" cy="18.6" rx="6.5" ry="2.3" {...s}/>
        <circle cx="7.6" cy="14.9" r="1.5" {...s}/>
      </svg>
    );
    // people (Clientes)
    return (
      <svg width={size} height={size} viewBox="0 0 24 24">
        <circle cx="9.4" cy="8.4" r="3.4" {...s}/>
        <path d="M3.8 19.4 A5.9 5.9 0 0 1 15 19.4" {...s}/>
        <circle cx="16.8" cy="9.6" r="2.5" {...s}/>
        <path d="M16.6 15.9 A4.5 4.5 0 0 1 20.6 19.4" {...s}/>
      </svg>
    );
  };

  // --- Entradas de cabecera y card ---
  const badgeP = clamp((t-0.4)/0.5, 0, 1);
  const badgeE = Easing.easeOutBack(badgeP);
  const titleP = clamp((t-0.7)/0.7, 0, 1);
  const titleE = Easing.easeOutCubic(titleP);
  const cardP  = clamp((t-0.9)/0.8, 0, 1);
  const cardE  = Easing.easeOutCubic(cardP);
  const emptyP = clamp((t-1.8)/0.5, 0, 1) * clamp((3.4-t)/0.3, 0, 1);
  const btnP   = clamp((t-2.0)/0.5, 0, 1);

  // Realce suave del campo «Nº de jugadores» mientras vive el mini-resumen
  const hlP = clamp((t-linkAt)/0.5, 0, 1) * (1 - clamp((t-12.2)/0.6, 0, 1));

  return (
    <SlideCanvas variant="light">

      {/* ===== Badge del acto (estilo TimeBadge, sin hora) ===== */}
      <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(badgeP*1.3,0,1), transform:`translateY(${(1-badgeE)*-14}px) scale(${lerp(0.85,1,badgeE)})`}}>
        <div style={{width:34, height:34, borderRadius:10, background:'linear-gradient(135deg,#0085FF,#56E16A)', display:'flex', alignItems:'center', justifyContent:'center'}}>
          {icon('flag', 17, '#fff')}
        </div>
        <div>
          <div className="f-mono" style={{fontSize:13, fontWeight:700, color:'#fff', lineHeight:1, letterSpacing:'1.5px'}}>CASOS DE ÉXITO</div>
          <div className="f-mono" style={{fontSize:9, fontWeight:600, color:'rgba(255,255,255,0.55)', letterSpacing:'2.5px', marginTop:3}}>1 DE 3</div>
        </div>
      </div>

      {/* ===== Título del caso ===== */}
      <div style={{position:'absolute', top:50, left:0, right:0, textAlign:'center', zIndex:5, opacity:titleE, transform:`translateY(${(1-titleE)*-10}px)`}}>
        <div style={{display:'inline-flex', alignItems:'center', gap:16}}>
          {icon('flag', 34)}
          <h2 className="f-plex" style={{fontSize:44, fontWeight:700, letterSpacing:'-0.03em', color:'#0F172A', margin:0}}>Minigolf</h2>
        </div>
      </div>

      {/* ===== Card de sección «Partidas» ===== */}
      <div style={{position:'absolute', left:CARD.left, top:CARD.top, width:CARD.w, height:CARD.h,
        background:'#fff', border:'1px solid #E2E8F0', borderRadius:18,
        boxShadow:'0 30px 80px rgba(0,133,255,0.14), 0 4px 14px rgba(15,23,42,0.06)',
        opacity:cardE, transform:`translateY(${(1-cardE)*30}px) scale(${lerp(0.975,1,cardE)})`}}>

        {/* Cabecera de la card */}
        <div style={{position:'absolute', top:26, left:30, right:30, height:64, display:'flex', alignItems:'center', gap:16}}>
          <div style={{opacity:clamp((t-1.1)/0.4,0,1), transform:`scale(${lerp(0.6,1,Easing.easeOutBack(clamp((t-1.1)/0.45,0,1)))})`}}>
            {icon('hole', 44)}
          </div>
          <div style={{flex:1, minWidth:0, opacity:clamp((t-1.25)/0.4,0,1), transform:`translateY(${(1-Easing.easeOutCubic(clamp((t-1.25)/0.4,0,1)))*8}px)`}}>
            <div className="f-plex" style={{fontSize:27, fontWeight:700, color:'#0F172A', letterSpacing:'-0.02em', lineHeight:1.1}}>Partidas</div>
            <div className="f-mono" style={{fontSize:11, fontWeight:600, color:'var(--dn-primary)', letterSpacing:'1.8px', marginTop:4, textTransform:'uppercase'}}>Nueva sección</div>
          </div>
          <div className="f-mono" style={{fontSize:12, color:'#94A3B8', opacity:clamp((t-1.4)/0.4,0,1)}}>
            {fieldsDone} {fieldsDone === 1 ? 'campo' : 'campos'}
          </div>
        </div>

        <div style={{position:'absolute', top:106, left:30, right:30, height:1, background:'#EEF2F7', opacity:clamp((t-1.5)/0.4,0,1)}}/>

        {/* Zona de campos: FORMULARIO de dos columnas (geometría idéntica en F4/F5/F6) */}
        <div style={{position:'absolute', top:123, left:30, width:F_W, height:258}}>

          {/* Estado vacío */}
          {emptyP > 0 && (
            <div style={{position:'absolute', inset:0, border:'1.5px dashed #D3DDE8', borderRadius:12,
              display:'flex', alignItems:'center', justifyContent:'center', opacity:emptyP, pointerEvents:'none'}}>
              <span style={{fontSize:13, fontStyle:'italic', color:'#94A3B8'}}>Sin campos todavía</span>
            </div>
          )}

          {/* Campos: cada beat = slot (label + caja vacía) → valor (typewriter o fade) → chip de tipo */}
          {FIELDS.map((f, i) => {
            if (t < f.at) return null;
            const ty = TYPES[f.type];
            const typeDur = f.typed ? Math.min(0.7, 0.22 + 0.055*f.value.length) : 0.35;
            const slotP = clamp((t-f.at)/0.4, 0, 1);                       // slot: label + caja vacía
            const slotE = Easing.easeOutCubic(slotP);
            const valP  = clamp((t-(f.at+0.42))/typeDur, 0, 1);            // valor de ejemplo
            const valE  = Easing.easeOutCubic(valP);
            const chipP = clamp((t-(f.at+0.42+typeDur+0.12))/0.4, 0, 1);   // chip al acabar el valor
            const chipE = Easing.easeOutBack(chipP);
            const focus = clamp((t-f.at)/0.25, 0, 1) * (1 - clamp((t-(f.at+0.42+typeDur+0.1))/0.45, 0, 1));
            const shown = f.typed ? f.value.slice(0, Math.ceil(valP*f.value.length)) : f.value;
            const caretOn = f.typed && t >= f.at+0.3 && valP < 1;
            const bR = Math.round(lerp(211,0,focus)), bG = Math.round(lerp(221,133,focus)), bB = Math.round(lerp(232,255,focus));
            const hl = (i === 1) ? hlP : 0;   // «Nº de jugadores» ancla la mini-card Clientes
            return (
              <div key={i} style={{position:'absolute', left:f.x, top:f.y, width:f.w,
                opacity:clamp(slotP*1.5,0,1), transform:`translateY(${(1-slotE)*10}px)`}}>
                <div className="f-mono" style={{height:F_LBL, lineHeight:`${F_LBL}px`, fontSize:11, fontWeight:600, letterSpacing:'1.2px', textTransform:'uppercase', color:'#94A3B8', whiteSpace:'nowrap'}}>{f.label}</div>
                <div style={{marginTop:F_LBLGAP, height:F_IN, background:'#fff', borderRadius:10,
                  border:`1px solid rgb(${bR},${bG},${bB})`,
                  boxShadow:`0 1px 2px rgba(15,23,42,0.04), 0 0 0 3px rgba(0,133,255,${0.12*focus}), 0 0 0 2px rgba(0,133,255,${0.18*hl})`,
                  display:'flex', alignItems:'center', gap:10, padding:'0 14px'}}>
                  <span style={{display:'inline-flex', alignItems:'center', minWidth:0}}>
                    <span className="f-plex" style={{fontSize:16, fontWeight:600, whiteSpace:'pre',
                      color: f.type === 'enlace' ? '#0085FF' : '#0F172A',
                      textDecoration: f.type === 'enlace' ? 'underline' : 'none',
                      textDecorationColor:'rgba(0,133,255,0.35)', textUnderlineOffset:3,
                      opacity: f.typed ? 1 : valE,
                      transform: f.typed ? 'none' : `translateY(${(1-valE)*6}px)`}}>{shown}</span>
                    {caretOn && <span style={{width:1.5, height:20, marginLeft:2, background:'#0F172A', opacity:Math.sin(t*10) > 0 ? 0.9 : 0.15}}/>}
                  </span>
                  <span style={{flex:1}}/>
                  {f.type === 'selector' && (
                    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" style={{flexShrink:0, opacity:slotE}}>
                      <path d="M6.5 9.5 L12 15 L17.5 9.5" stroke="#94A3B8" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"/>
                    </svg>
                  )}
                  {chipP > 0 && (
                    <span style={{display:'inline-flex', alignItems:'center', gap:5, height:24, padding:'0 9px', borderRadius:100,
                      background:ty.bg, border:`1px solid ${ty.brd}`, flexShrink:0,
                      opacity:clamp(chipP*1.4,0,1), transform:`scale(${lerp(0.6,1,chipE)})`, transformOrigin:'right center'}}>
                      {chipIcon(f.type, ty.fg)}
                      <span className="f-mono" style={{fontSize:10, fontWeight:700, letterSpacing:'0.3px', color:ty.fg, whiteSpace:'nowrap'}}>{ty.label}</span>
                    </span>
                  )}
                </div>
              </div>
            );
          })}
        </div>

        {/* Botón «+ Añadir campo» */}
        <div style={{position:'absolute', top:429, left:30, right:30, height:48, borderRadius:12,
          border:`1.5px dashed ${btnPressed ? 'rgba(0,133,255,0.6)' : '#C6CFDB'}`,
          background: btnPressed ? 'rgba(0,133,255,0.06)' : 'transparent',
          display:'flex', alignItems:'center', justifyContent:'center', gap:8,
          color: btnPressed ? 'var(--dn-primary)' : '#64748B',
          opacity:btnP, transform:`scale(${btnPressed ? 0.97 : 1})`}}>
          <span style={{fontSize:17, fontWeight:600, lineHeight:1}}>+</span>
          <span className="f-plex" style={{fontSize:13.5, fontWeight:600}}>Añadir campo</span>
        </div>
      </div>

      {/* ===== Mini-resumen: el dato existente se reutiliza ===== */}
      {t >= linkAt && (
        <svg style={{position:'absolute', inset:0, pointerEvents:'none', zIndex:4}} width="1920" height="1080" viewBox="0 0 1920 1080">
          {(() => {
            // Parte del borde dcho. del input «Nº de jugadores» (celda dcha. fila 1, centro abs 371)
            const drawP = Easing.easeInOutCubic(clamp((t-linkAt)/0.7, 0, 1));
            return (
              <g>
                <path d="M 1254 371 C 1330 371, 1364 500, 1444 500" stroke="var(--dn-primary)" strokeWidth="2" fill="none"
                  pathLength="1" strokeDasharray="1" strokeDashoffset={1-drawP} opacity="0.75"/>
                <circle cx="1254" cy="371" r="4" fill="var(--dn-primary)" opacity={clamp((t-linkAt)/0.2,0,1)}/>
                <circle cx="1444" cy="500" r="4" fill="var(--dn-primary)" opacity={clamp((t-linkAt-0.55)/0.2,0,1)}/>
              </g>
            );
          })()}
        </svg>
      )}

      {t >= textAt && (() => {
        const p = clamp((t-textAt)/0.6, 0, 1);
        const e = Easing.easeOutCubic(p);
        return (
          <div className="f-plex" style={{position:'absolute', left:1436, top:372, width:300, textAlign:'center',
            fontSize:18, fontWeight:500, color:'#334155', lineHeight:1.35, letterSpacing:'-0.01em',
            opacity:e, transform:`translateY(${(1-e)*10}px)`}}>
            Los jugadores se eligen de <span style={{fontWeight:700, color:'#0F172A'}}>Clientes</span>
          </div>
        );
      })()}

      {t >= miniAt && (() => {
        const p = clamp((t-miniAt)/0.5, 0, 1);
        const e = Easing.easeOutBack(p);
        const chipP = clamp((t-chipAt)/0.4, 0, 1);
        const chipE = Easing.easeOutBack(chipP);
        return (
          <div style={{position:'absolute', left:1448, top:452, width:276, height:96,
            background:'#fff', border:'1px solid #E2E8F0', borderRadius:16,
            boxShadow:'0 18px 50px rgba(0,133,255,0.12), 0 3px 10px rgba(15,23,42,0.05)',
            display:'flex', alignItems:'center', gap:14, padding:'0 20px',
            opacity:clamp(p*1.3,0,1), transform:`translateY(${(1-e)*12}px) scale(${lerp(0.75,1,e)})`}}>
            {icon('people', 30)}
            <div style={{flex:1, minWidth:0}}>
              <div className="f-plex" style={{fontSize:18, fontWeight:700, color:'#0F172A', letterSpacing:'-0.01em'}}>Clientes</div>
              <div className="f-mono" style={{fontSize:11.5, color:'#64748B', marginTop:3}}>1.284 fichas</div>
            </div>
            {chipP > 0 && (
              <span className="f-mono" style={{position:'absolute', top:-11, right:14, fontSize:9.5, fontWeight:700, letterSpacing:'1.2px',
                padding:'4px 10px', borderRadius:100, background:'#ECFDF5', border:'1px solid #A7F3D0', color:'#059669',
                boxShadow:'0 4px 10px rgba(16,185,129,0.15)',
                opacity:clamp(chipP*1.3,0,1), transform:`scale(${lerp(0.6,1,chipE)})`}}>YA EXISTÍA</span>
            )}
          </div>
        );
      })()}

      {/* ===== Sello final ===== */}
      {t >= sealAt && (() => {
        const p = clamp((t-sealAt)/0.7, 0, 1);
        const e = Easing.easeOutCubic(p);
        return (
          <div style={{position:'absolute', top:788, left:0, right:0, textAlign:'center', opacity:e, transform:`translateY(${(1-e)*14}px)`}}>
            <div className="f-plex" style={{fontSize:40, fontWeight:800, letterSpacing:'-0.03em', lineHeight:1.15}}>
              <span style={{color:'#0F172A'}}>En su ERP. </span>
              <span style={{color:'#059669'}}>Sin Excel.</span>
            </div>
          </div>
        );
      })()}

      {/* Cursor */}
      {t >= 2.5 && (
        <div style={{position:'absolute', inset:0, opacity:clamp((t-2.5)/0.4,0,1), pointerEvents:'none', zIndex:25}}>
          <CineCursor x={cur.x} y={cur.y} clicking={clicking}/>
        </div>
      )}

      <SocialCaption t={t} cues={CAPTIONS.slide_flexminigolf}/>
    </SlideCanvas>
  );
}

Object.assign(window, { SlideFlexMinigolf });
