// vc1c3.jsx — Válvulas de Control · M1 · Clase 1.3 «Válvulas rotativas: tipos y partes»
// Después de valve-lib.jsx, pf-valves.jsx y vc-art.jsx (dibujos en corte). Exporta SCENES_VC1C3.

function PanelR({ x, y, w = 520, h = 560, at, title, sub, accent = SL.sun, children }) {
  const t = useTime();
  const p = popS(t, at);
  return (
    <g opacity={p.op} transform={`translate(0 ${p.ty})`}>
      <rect x={x} y={y} width={w} height={h} rx="18" fill={SL.paper} stroke={SL.lineS} strokeWidth="2" />
      <rect x={x} y={y} width={w} height="6" rx="3" fill={accent} />
      {children}
      <text x={x + w / 2} y={y + h - 100} fill={SL.ink} fontFamily={DISP} fontSize="29" fontWeight="700" textAnchor="middle">{title}</text>
      <foreignObject x={x + 24} y={y + h - 84} width={w - 48} height="80">
        <div style={{ fontFamily: DISP, fontSize: 19, color: SL.mut, textAlign: 'center', lineHeight: 1.35 }}>{sub}</div>
      </foreignObject>
    </g>
  );
}

// ── Tres tipos ─────────────────────────────────────────────────────────────
function S_RotaryTypes({ start, dur }) {
  const t = useTime(); const s = start;
  const lt = Math.max(0, t - s);
  const u = 0.5 + 0.42 * Math.sin(lt * 0.8);
  const X = (i) => 140 + i * 560, Y = 270;
  // tiempos de la voz: bola 0,6 · mariposa 10,3 · tapón excéntrico 18,5
  return (
    <SceneS start={start} dur={dur}>
      <HeadS s={s} dur={dur} kicker="Tres válvulas rotativas de control" title={<>Un cuarto de vuelta, tres formas de <span style={{ color: SL.sun }}>recortar el paso</span>.</>} y="15%" size={46} />
      <svg style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', overflow: 'visible' }}>
        <ValveDefs />
        <PanelR x={X(0)} y={Y} at={s + 1.2} title="Bola segmentada (en V)" sub="Un casquete de bola con muesca en V: corte de sólidos y fibras, y gran rangeabilidad.">
          <g transform={`translate(${X(0) + 200} ${Y + 210}) scale(0.62)`}><VBallArt angle={u * 90} t={t} /></g>
          <g transform={`translate(${X(0) + 430} ${Y + 340}) scale(0.5)`}><VNotchView k={u} /></g>
          <text x={X(0) + 430} y={Y + 420} fill={SL.mut} fontFamily={MONO} fontSize="14" textAnchor="middle">vista de frente</text>
        </PanelR>
        <PanelR x={X(1)} y={Y} at={s + 10.3} title="Mariposa de alto rendimiento" sub="Disco con eje desplazado del sello: cierra hermético y se usa en tamaños grandes.">
          <g transform={`translate(${X(1) + 260} ${Y + 230}) scale(0.72)`}><ButterflyOffsetArt offset="double" angle={u * 90} t={t} /></g>
        </PanelR>
        <PanelR x={X(2)} y={Y} at={s + 18.5} title="Tapón excéntrico" sub="Un tapón que gira sobre un eje excéntrico y se separa del asiento: lodos y fluidos erosivos.">
          <g transform={`translate(${X(2) + 260} ${Y + 240}) scale(0.72)`}><EccPlugArt angle={u * 60} t={t} /></g>
        </PanelR>
      </svg>
    </SceneS>
  );
}

// ── Excentricidad en mariposas ─────────────────────────────────────────────
function S_Offsets({ start, dur }) {
  const t = useTime(); const s = start;
  const lt = Math.max(0, t - s);
  const a = clamp(45 - 50 * Math.cos(lt * 0.6), 0, 90);
  // tiempos de la voz: concéntrica 3,9 · doble 11,3 · triple 16,9
  const view = (x, offset, title, sub, at) => {
    const p = popS(t, s + at);
    return (
      <g opacity={p.op}>
        <rect x={x - 250} y={300} width="500" height="560" rx="18" fill={SL.paper} stroke={SL.lineS} />
        <g transform={`translate(${x} 540) scale(0.8)`}><ButterflyOffsetArt offset={offset} angle={a} t={t} /></g>
        <text x={x} y={790} fill={SL.ink} fontFamily={DISP} fontSize="28" fontWeight="700" textAnchor="middle">{title}</text>
        <foreignObject x={x - 220} y={804} width="440" height="56"><div style={{ fontFamily: DISP, fontSize: 18, color: SL.mut, textAlign: 'center', lineHeight: 1.3 }}>{sub}</div></foreignObject>
      </g>
    );
  };
  return (
    <SceneS start={start} dur={dur}>
      <HeadS s={s} dur={dur} kicker="Mariposas: excentricidad" title={<>Mover el eje <span style={{ color: SL.sun }}>fuera del centro</span> despega el disco del sello.</>} y="15%" size={46} />
      <svg style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', overflow: 'visible' }}>
        <ValveDefs />
        {view(420, 'conc', 'Concéntrica', 'El disco roza el sello en todo el giro (en rojo): sello blando, servicios sencillos.', 3.9)}
        {view(960, 'double', 'Doble excéntrica', 'Eje detrás del sello y desplazado: el disco se despega al abrir. Alto rendimiento.', 11.3)}
        {view(1500, 'triple', 'Triple excéntrica', 'Superficies cónicas sin roce: cierre metal-metal para alta temperatura.', 16.9)}
        <text x={960} y={920} fill={SL.mut} fontFamily={MONO} fontSize="20" textAnchor="middle" opacity={segS(t, s + 4)}>giro {Math.round(a)}°</text>
      </svg>
    </SceneS>
  );
}

// ── Partes y actuador rotativo ─────────────────────────────────────────────
function S_RotaryParts({ start, dur }) {
  const t = useTime(); const s = start;
  const lt = Math.max(0, t - s);
  const u = 0.5 + 0.45 * Math.sin(lt * 0.8);
  return (
    <SceneS start={start} dur={dur}>
      <HeadS s={s} dur={dur} kicker="Partes de una válvula rotativa" title={<>Un actuador lineal puede <span style={{ color: SL.sun }}>girar</span> el eje con una palanca.</>} y="15%" size={46} />
      <svg style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', overflow: 'visible' }}>
        <ValveDefs />
        <g opacity={segS(t, s + 1)}>
          <g transform="translate(620 760) scale(0.95)"><RotaryLinkArt angle={u * 90} t={t} air={u} /></g>
          <text x={620} y={940} fill={SL.ink} fontFamily={MONO} fontSize="20" textAnchor="middle">giro {Math.round(u * 90)}°</text>
          <text x={760} y={600} fill={SL.sunD} fontFamily={MONO} fontSize="18" fontWeight="700" opacity={segS(t, s + 10.1)}>palanca</text>
          <text x={430} y={350} fill={SL.cc} fontFamily={MONO} fontSize="18" fontWeight="700" opacity={segS(t, s + 10.1)}>actuador de diafragma</text>
        </g>
      </svg>
      <ListS x={1080} y={300} w={760} size={27} items={[
        { k: 'Cuerpo bridado o tipo wafer', d: 'El wafer va apretado entre las bridas de la tubería: más corto y liviano.', at: s + 1.5 },
        { k: 'Eje y cojinetes', d: 'Transmiten el giro; el eje estriado evita juego entre actuador y disco.', at: s + 4 },
        { k: 'Sello o anillo de asiento', d: 'Blando para cierre hermético o metálico para temperatura.', at: s + 6.5 },
        { k: 'Actuador rotativo', d: 'Diafragma con palanca, pistón con piñón y cremallera o yugo escocés.', at: s + 10.1 },
      ]} />
    </SceneS>
  );
}

// ── Lineal o rotativa ──────────────────────────────────────────────────────
function S_Compare({ start, dur }) {
  const t = useTime(); const s = start;
  const rows = [
    ['Capacidad por tamaño', 'Menor', 'Mayor'],
    ['Costo en tamaños grandes', 'Alto', 'Bajo'],
    ['Rangeabilidad', 'Buena', 'Muy buena (bola en V)'],
    ['ΔP alta y cavitación', 'Mejor, con trims especiales', 'Recupera más presión: cavita antes'],
    ['Peso y espacio', 'Mayor', 'Menor'],
  ];
  return (
    <SceneS start={start} dur={dur}>
      <HeadS s={s} dur={dur} kicker="¿Vástago deslizante o rotativa?" title={<>No hay una mejor: hay <span style={{ color: SL.sun }}>una adecuada</span> para cada servicio.</>} y="15%" size={46} />
      <div style={{ position: 'absolute', left: 200, top: 300, width: 1520, fontFamily: DISP }}>
        <div style={{ display: 'grid', gridTemplateColumns: '1.2fr 1fr 1fr', gap: 12 }}>
          <div />
          {['Vástago deslizante', 'Rotativa'].map((h, i) => {
            const p = popS(t, s + 1 + i * 0.3);
            return <div key={h} style={{ opacity: p.op, background: SL.paper, borderRadius: 12, padding: '10px 20px', borderTop: `6px solid ${i ? SL.ca : SL.sun}`, fontSize: 27, fontWeight: 700, color: SL.ink, boxShadow: SL.shadowSm, display: 'flex', alignItems: 'center', gap: 16 }}>
              <svg viewBox={i ? '-300 -160 600 320' : '-440 -560 880 830'} style={{ width: 110, height: i ? 60 : 104, flex: '0 0 auto' }}><ValveDefs />{i ? <ButterflyArt angle={60} t={t} /> : <GlobeAssembly open={0.5} air={0.5} t={t} show={vcOnly(['body', 'seat', 'cage', 'plug', 'stem', 'bonnet'])} />}</svg>{h}</div>;
          })}
          {rows.map((r, ri) => r.map((c, ci) => {
            const p = popS(t, s + [3.3, 5.5, 7.5, 11.4, 9.5][ri]);
            return (
              <div key={`${ri}-${ci}`} style={{ opacity: p.op, transform: `translateY(${p.ty}px)`, background: ci ? SL.paper : 'transparent', borderRadius: 10, padding: '14px 20px', fontFamily: ci ? DISP : MONO, fontSize: ci ? 22 : 18, color: ci ? SL.ink : SL.mut, textTransform: ci ? 'none' : 'uppercase', letterSpacing: ci ? 0 : '0.06em', border: ci ? `1px solid ${SL.lineS}` : 'none', display: 'flex', alignItems: 'center' }}>{c}</div>
            );
          }))}
        </div>
      </div>
    </SceneS>
  );
}

const SCENES_VC1C3 = [
  { C: (p) => <TitleCardS {...p} moduleNo={1} claseNo={3} title="Válvulas rotativas" objetivo="Bola segmentada, mariposa de alto rendimiento y tapón excéntrico, la excentricidad, sus partes y cuándo conviene frente a una de vástago deslizante." />, dur: 18, label: 'Apertura' },
  { C: S_RotaryTypes, dur: 27, label: 'Tres tipos' },
  { C: S_Offsets, dur: 24, label: 'Excentricidad' },
  { C: S_RotaryParts, dur: 20, label: 'Partes' },
  { C: S_Compare, dur: 24, label: 'Comparación' },
  { C: (p) => <ClosingS {...p} line="Las rotativas ganan en capacidad, costo y peso; las de vástago deslizante, en presiones diferenciales altas." question="Para agua de enfriamiento en una línea de 24 pulgadas con poca caída de presión, ¿qué tipo de válvula elegirías y por qué?" />, dur: 16, label: 'Cierre' },
];

window.SCENES_VC1C3 = SCENES_VC1C3;
