// dc1c3.jsx — Diseño de Ingeniería I&C · Clase 1.3 «Revisiones y control de cambios».
// Después de di-lib.jsx, temp-art.jsx y di-art.jsx. Exporta SCENES_DC1C3.
const TIEMPOS_DC1C3 = [[0.6], [0.6, 4.2, 11.54, 15.47], [0.6, 3.19, 7.51, 9.78, 13.21, 16.71, 18.75, 23.21, 26.79, 29.33, 32.37], [0.6, 3.41, 6.27, 8.45, 12.25, 13.99, 18.4], [0.6, 5.66], [0.6, 4.34, 7.35, 12.71, 19.05], [0.6, 4.66, 7.55, 12.74, 17.11], [0.6, 3.51, 10.14], [0.6], [0.6, 6.58, 9.8, 11.83, 13.33, 15.89, 18.1, 20.2], [0.6, 6.16, 8.07, 13.06, 17.55], [0.6, 10.89, 13.93, 18.22, 20.33, 24.13, 28.82], [0.6, 6.38], [0.6, 4.44]]; // auto
const fr = (i, k) => (TIEMPOS_DC1C3[i] || [])[k] ?? 0.6 + k * 4;

function S_Why({ start, dur }) {
  const t = useTime(); const s = start; const I = 1;
  const a = (k) => pop4(t, s + fr(I, k));
  const causes = ['Procesos ajusta un dato', 'El cliente comenta', 'El proveedor envía su información final'];
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="Por qué importa">Un mismo plano <span style={{ color: TL4.orangeD }}>cambia muchas veces</span>.</HeadM14>
      <svg style={SVG_T}>
        {['A', 'B', 'C', '0', '1'].map((r, i) => <g key={i} opacity={a(0).op}><DocSheet x={220 + i * 46} y={330 + i * 26} w={170} h={220} kind="logic" color={i === 4 ? TL4.orange : TL4.blueLt} code={`Rev. ${r}`} /></g>)}
      </svg>
      <Notes4 x={720} y={330} w={1000}>
        {causes.map((c, i) => <NoteT key={i} op={pop4(t, s + fr(I, 1) + i * 1.4).op} accent={TL4.blue} size={24}>{c}</NoteT>)}
      </Notes4>
      <div style={{ position: 'absolute', left: 220, top: 700, width: 1500, opacity: a(2).op }}>
        <NoteT bg={TL4.orangeWash} size={25}><b>El peligro:</b> dos personas trabajando con versiones distintas. {t > s + fr(I, 3) ? 'Un montador con la versión vieja conecta el cable en la bornera equivocada.' : ''}</NoteT>
      </div>
    </SceneM4>
  );
}

function S_Status({ start, dur }) {
  const t = useTime(); const s = start; const I = 2;
  const st = [
    ['IFR', 'Emitido para revisión', 'El cliente lo mira y comenta', 1, TL4.mut],
    ['IFA', 'Emitido para aprobación', 'El cliente debe aprobarlo', 3, TL4.blue],
    ['IFD', 'Emitido para diseño', 'Otras disciplinas lo usan', 5, TL4.blueD],
    ['IFC', 'Emitido para construcción', 'Se compra y se monta', 7, TL4.orange],
    ['As built', 'Como construido', 'Igual a lo que quedó en campo', 9, FA.ok],
  ];
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="Estados de emisión">Cada emisión <span style={{ color: TL4.orangeD }}>lleva un estado</span>.</HeadM14>
      <svg style={SVG_T}><line x1={200} y1={470} x2={1720} y2={470} stroke={TL4.lineS} strokeWidth={4} opacity={pop4(t, s + fr(I, 0)).op} /></svg>
      {st.map((p, i) => { const q = pop4(t, s + fr(I, p[3])); const on = t > s + fr(I, p[3] + 1); return (
        <div key={i} style={{ position: 'absolute', left: 180 + i * 315, top: 400, width: 290, opacity: q.op, transform: `translateY(${q.ty}px)`, textAlign: 'center', fontFamily: DISP4 }}>
          <div style={{ margin: '0 auto', width: 140, height: 140, borderRadius: 70, background: i === 3 ? TL4.orangeWash : TL4.paper, border: `5px solid ${p[4]}`, display: 'flex', alignItems: 'center', justifyContent: 'center', fontFamily: MONO4, fontSize: p[0].length > 4 ? 26 : 36, fontWeight: 700, color: p[4] }}>{p[0]}</div>
          <div style={{ fontSize: 24, fontWeight: 700, marginTop: 18 }}>{p[1]}</div>
          <div style={{ fontSize: 20, color: TL4.mut, marginTop: 6, opacity: on ? 1 : 0.25 }}>{p[2]}</div>
        </div>); })}
      <div style={{ position: 'absolute', left: 200, top: 800, width: 1520, opacity: pop4(t, s + fr(I, 8)).op }}>
        <NoteT accent={TL4.orange} size={23}>Solo con un plano <b>IFC</b> (o posterior) se compra y se construye. Lo anterior es para revisar.</NoteT>
      </div>
    </SceneM4>
  );
}

function S_Letters({ start, dur }) {
  const t = useTime(); const s = start; const I = 3;
  const a = (k) => pop4(t, s + fr(I, k));
  const chip = (txt, c, on) => <span style={{ display: 'inline-flex', width: 96, height: 96, borderRadius: 16, alignItems: 'center', justifyContent: 'center', background: on ? c : TL4.paper, color: on ? '#fff' : c, border: `4px solid ${c}`, fontFamily: MONO4, fontSize: 46, fontWeight: 700, marginRight: 14 }}>{txt}</span>;
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="Letras y números">La revisión dice <span style={{ color: TL4.orangeD }}>si el plano está listo para la obra</span>.</HeadM14>
      <div style={{ position: 'absolute', left: 260, top: 330, opacity: a(1).op, fontFamily: DISP4 }}>
        <div style={{ fontSize: 28, fontWeight: 700, color: TL4.blue, marginBottom: 18 }}>Antes de construcción · letras</div>
        <div style={{ opacity: a(2).op }}>{chip('A', TL4.blue)}{chip('B', TL4.blue)}{chip('C', TL4.blue)}</div>
      </div>
      <div style={{ position: 'absolute', left: 1000, top: 330, opacity: a(3).op, fontFamily: DISP4 }}>
        <div style={{ fontSize: 28, fontWeight: 700, color: TL4.orangeD, marginBottom: 18 }}>Desde IFC · números</div>
        <div style={{ opacity: a(4).op }}>{chip('0', TL4.orange, true)}{chip('1', TL4.orange, true)}{chip('2', TL4.orange, true)}</div>
      </div>
      <Notes4 x={260} y={620} w={1400}>
        <NoteT op={a(5).op} accent={TL4.blue} size={24}>Con solo mirar el cajetín sabes si puedes usar el plano en la obra.</NoteT>
        <NoteT op={a(6).op} bg={TL4.orangeWash} size={24}><b>Ojo:</b> cada empresa define su sistema en el procedimiento de control de documentos del proyecto. Léelo el primer día.</NoteT>
      </Notes4>
    </SceneM4>
  );
}

function S_Clouds({ start, dur }) {
  const t = useTime(); const s = start; const I = 5;
  const a = (k) => pop4(t, s + fr(I, k)).op;
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="Nubes y triángulos">Encuentra <span style={{ color: TL4.orangeD }}>lo que cambió</span> sin leer todo el plano.</HeadM14>
      <svg style={SVG_T}>
        <g opacity={a(0)}>
          <rect x={200} y={300} width={1040} height={560} fill="#fbfdff" stroke={DI.ink} strokeWidth={2.5} />
          <IsaBubble x={320} y={460} r={46} tag="PT" num="110" />
          <SigLine x1={366} y1={460} x2={560} y2={460} type="electric" />
          <TermStrip x={560} y={400} n={3} labels={['+', '−', 'S']} name="JB-11" />
          <SigLine x1={624} y1={420} x2={860} y2={420} type="electric" />
          <TermStrip x={860} y={400} n={3} labels={['5', '6', '7']} name="MT-02" hi={t > s + fr(I, 2) ? [0, 1] : []} />
          <BoxSym x={1010} y={380} w={200} h={150} title="DCS · AI" sub="Tarjeta 3 · canal 4" />
        </g>
        <g opacity={a(2)}><RevCloud x={840} y={385} w={110} h={150} /><RevTri x={985} y={350} n="1" /></g>
        <g opacity={a(3)}><TitleBlock x={700} y={680} w={520} rows={[['REV', 'DESCRIPCIÓN · FECHA', false], ['0', 'Emitido para construcción · 15-03', false], ['1', 'Cambio de borneras MT-02 · 02-05', true]]} /></g>
      </svg>
      <Notes4 x={1300} y={330} w={460}>
        <NoteT op={a(1)} accent={DI.alarm} size={22}><b>La nube</b> encierra el cambio.</NoteT>
        <NoteT op={a(2)} accent={DI.alarm} size={22}><b>El triángulo</b> dice en qué revisión cambió.</NoteT>
        <NoteT op={a(3)} accent={TL4.blue} size={22}><b>La tabla de revisiones</b> dice qué cambió, cuándo y quién lo aprobó.</NoteT>
      </Notes4>
    </SceneM4>
  );
}

function S_Codes({ start, dur }) {
  const t = useTime(); const s = start; const I = 6;
  const cards = [
    ['Código 1', 'Aprobado. Se puede seguir.', FA.ok, 1], ['Código 2', 'Aprobado con comentarios. Se incorporan en la siguiente revisión.', TL4.orange, 2], ['Código 3', 'Rechazado. Hay que corregir y volver a emitir.', DI.alarm, 3],
  ];
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="Comentarios del cliente">El documento vuelve <span style={{ color: TL4.orangeD }}>con un código</span>.</HeadM14>
      {cards.map((c, i) => <InfoCardM4 key={i} x={220 + i * 510} y={330} w={460} h={280} accent={c[2]} title={c[0]} sub={c[1]} appear={s + fr(I, c[3])} t={t} />)}
      <div style={{ position: 'absolute', left: 220, top: 680, width: 1480, opacity: pop4(t, s + fr(I, 4)).op }}>
        <NoteT bg={TL4.orangeWash} size={24}>Cada comentario y su respuesta van en la <b>hoja de comentarios</b>. Ningún comentario se cierra sin respuesta.</NoteT>
      </div>
    </SceneM4>
  );
}

function S_Transmittal({ start, dur }) {
  const t = useTime(); const s = start; const I = 7;
  const rows = [['P420-110-IC-HD-0040', '1', 'IFC'], ['P420-110-IC-DL-0031', '1', 'IFC'], ['P420-110-IC-IN-0001', 'C', 'IFA']];
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="El transmittal">Los documentos <span style={{ color: TL4.orangeD }}>nunca viajan sueltos</span>.</HeadM14>
      <div style={{ position: 'absolute', left: 300, top: 320, width: 900, opacity: pop4(t, s + fr(I, 1)).op, background: TL4.paper, borderRadius: 14, boxShadow: TL4.shadow, padding: '26px 32px', fontFamily: DISP4 }}>
        <div style={{ fontFamily: MONO4, fontSize: 18, color: TL4.mut, letterSpacing: '0.12em' }}>TRANSMITTAL N.º TR-0087 · 02-05</div>
        <div style={{ fontSize: 26, fontWeight: 700, marginTop: 8 }}>De: Ingeniería I&C · Para: Petroandina</div>
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 100px 120px', gap: 8, marginTop: 22, fontFamily: MONO4, fontSize: 19 }}>
          {['Documento', 'Rev.', 'Estado'].map(h => <div key={h} style={{ color: TL4.blueD, fontWeight: 700 }}>{h}</div>)}
          {rows.flat().map((v, i) => <div key={i} style={{ padding: '8px 0', borderTop: `1px solid ${TL4.line}` }}>{v}</div>)}
        </div>
      </div>
      <div style={{ position: 'absolute', left: 1260, top: 380, width: 460, opacity: pop4(t, s + fr(I, 2)).op }}>
        <NoteT bg={TL4.orangeWash} size={25}>El transmittal es la <b>prueba</b> de qué se entregó, en qué revisión y cuándo.</NoteT>
      </div>
    </SceneM4>
  );
}

function S_Moc({ start, dur }) {
  const t = useTime(); const s = start; const I = 9;
  const st = [['Proponer', 'Qué y por qué', 1, TL4.blue], ['Evaluar el riesgo', 'Qué puede salir mal', 2, TL4.blueD], ['Aprobar y ejecutar', 'Con permiso y plan', 4, TL4.orange], ['Actualizar documentos', 'Lo más olvidado', 5, DI.alarm]];
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="Gestión del cambio (MOC)">En una planta que opera, <span style={{ color: TL4.orangeD }}>ningún cambio es informal</span>.</HeadM14>
      {st.map((p, i) => { const q = pop4(t, s + fr(I, p[2])); return (
        <div key={i} style={{ position: 'absolute', left: 190 + i * 400, top: 360, width: 360, opacity: q.op, transform: `translateY(${q.ty}px)`, fontFamily: DISP4 }}>
          <div style={{ background: i === 3 ? '#fde8ea' : TL4.paper, borderRadius: 14, boxShadow: TL4.shadowSm, borderTop: `6px solid ${p[3]}`, padding: '24px 24px', minHeight: 200 }}>
            <div style={{ fontFamily: MONO4, fontSize: 42, fontWeight: 700, color: p[3] }}>{i + 1}</div>
            <div style={{ fontSize: 28, fontWeight: 700, marginTop: 6 }}>{p[0]}</div>
            <div style={{ fontSize: 21, color: TL4.mut, marginTop: 6 }}>{p[1]}</div>
          </div>
          {i < 3 && <div style={{ position: 'absolute', right: -34, top: 90, fontSize: 40, color: TL4.dim }}>→</div>}
        </div>); })}
      <div style={{ position: 'absolute', left: 190, top: 680, width: 1560, opacity: pop4(t, s + fr(I, 7)).op }}>
        <NoteT bg={TL4.orangeWash} size={25}>Un cambio sin documentos actualizados es <b>una trampa para el próximo técnico</b>.</NoteT>
      </div>
    </SceneM4>
  );
}

function S_Redline({ start, dur }) {
  const t = useTime(); const s = start; const I = 10;
  const a = (k) => pop4(t, s + fr(I, k)).op;
  const asb = t > s + fr(I, 3);
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="Red lines y as built">Lo que cambia en campo <span style={{ color: TL4.orangeD }}>vuelve al plano</span>.</HeadM14>
      <svg style={SVG_T}>
        <g opacity={a(0)}>
          <rect x={220} y={320} width={760} height={460} fill="#fbfdff" stroke={DI.ink} strokeWidth={2.5} />
          <text x={240} y={350} fill={DI.mut} fontFamily={MONO4} fontSize="16">DL-0031 · Rev. 1 · copia de campo</text>
          <TermStrip x={360} y={420} n={4} labels={['5', '6', '7', '8']} name="MT-02" />
          <SigLine x1={250} y1={460} x2={360} y2={460} type="electric" />
          <SigLine x1={250} y1={500} x2={360} y2={500} type="electric" />
          <BoxSym x={600} y={420} w={300} h={160} title="DCS · AI" sub="Tarjeta 3 · canal 4" />
        </g>
        <g opacity={a(2)}>
          <line x1={372} y1={448} x2={412} y2={472} stroke={DI.alarm} strokeWidth={4} /><line x1={372} y1={488} x2={412} y2={512} stroke={DI.alarm} strokeWidth={4} />
          <path d="M250 460 C 300 470, 320 530, 360 540" fill="none" stroke={DI.alarm} strokeWidth={4} /><path d="M250 500 C 300 520, 320 570, 360 580" fill="none" stroke={DI.alarm} strokeWidth={4} />
          <text x={440} y={650} fill={DI.alarm} fontFamily={MONO4} fontSize="20" fontWeight="700">pasa a 7 y 8 (5 dañada) · JR 03-06</text>
        </g>
        <g opacity={a(3)} transform="translate(1040 0)">
          <rect x={0} y={320} width={680} height={460} fill="#fbfdff" stroke={FA.ok} strokeWidth={3} />
          <text x={20} y={350} fill={FA.ok} fontFamily={MONO4} fontSize="16" fontWeight="700">DL-0031 · Rev. 2 · AS BUILT</text>
          <TermStrip x={140} y={420} n={4} labels={['5', '6', '7', '8']} name="MT-02" hi={[2, 3]} />
          <SigLine x1={30} y1={540} x2={140} y2={540} type="electric" />
          <SigLine x1={30} y1={580} x2={140} y2={580} type="electric" />
          <RevCloud x={120} y={520} w={110} h={80} /><RevTri x={270} y={520} n="2" />
        </g>
      </svg>
      <div style={{ position: 'absolute', left: 220, top: 830, width: 1500, opacity: a(4) }}>
        <NoteT bg={TL4.orangeWash} size={24}>Si nadie pasa las red lines al as built, <b>el plano deja de decir la verdad</b>.</NoteT>
      </div>
    </SceneM4>
  );
}

function S_Example({ start, dur }) {
  const t = useTime(); const s = start; const I = 11;
  const rows = [
    ['Hoja de datos', 'Cambia el rango: 0–16 bar', true, 2], ['Índice de instrumentos', 'Cambia la columna de rango', true, 3],
    ['Configuración del DCS y alarmas', 'Nuevo rango y nuevos puntos de alarma', true, 4], ['Diagrama de lazo', 'No cambia: mismos cables y borneras', false, 5],
  ];
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="Ejemplo">PT-110: de <span style={{ color: TL4.orangeD }}>0–10 bar a 0–16 bar</span>.</HeadM14>
      <div style={{ position: 'absolute', left: 220, top: 320, width: 1480, display: 'flex', flexDirection: 'column', gap: 14, fontFamily: DISP4 }}>
        {rows.map((r, i) => { const q = pop4(t, s + fr(I, r[3])); return (
          <div key={i} style={{ opacity: q.op, transform: `translateY(${q.ty}px)`, display: 'grid', gridTemplateColumns: '130px 440px 1fr', alignItems: 'center', gap: 16, background: TL4.paper, borderRadius: 12, padding: '18px 24px', boxShadow: TL4.shadowSm, borderLeft: `6px solid ${r[2] ? TL4.orange : FA.ok}` }}>
            <span style={{ fontFamily: MONO4, fontSize: 30, fontWeight: 700, color: r[2] ? TL4.orangeD : FA.ok }}>{r[2] ? '↑ rev' : '='}</span>
            <span style={{ fontSize: 26, fontWeight: 700 }}>{r[0]}</span><span style={{ fontSize: 22, color: TL4.mut }}>{r[1]}</span>
          </div>); })}
      </div>
      <div style={{ position: 'absolute', left: 220, top: 820, width: 1480, opacity: pop4(t, s + fr(I, 6)).op }}>
        <NoteT accent={TL4.blue} size={24}>Cada documento que cambia <b>sube una revisión</b> y sale con su nube y su triángulo.</NoteT>
      </div>
    </SceneM4>
  );
}

const Q_DC1C3_1 = { id: 'dc1c3-q1', q: 'Recibes un diagrama de lazo en revisión B. ¿Puedes usarlo para conectar los cables en campo?', options: ['Sí, cualquier revisión sirve', 'No: las letras son revisiones previas a construcción', 'Sí, si tiene nubes', 'Solo si es de noche'], answer: 1, explain: 'Las revisiones con letras son para revisar. Para montar y conectar se usa la emisión para construcción (IFC), con número.', hints: ['Usar una versión no aprobada para montar es un error típico.', null, 'Las nubes solo marcan cambios.', 'La hora no cambia el estado del plano.'] };
const Q_DC1C3_2 = { id: 'dc1c3-q2', q: 'El cliente devuelve una hoja de datos con código 2. ¿Qué significa?', options: ['Rechazada', 'Aprobada con comentarios: se incorporan en la siguiente revisión', 'Aprobada sin comentarios', 'Pendiente de revisar'], answer: 1, explain: 'Código 2: se puede seguir trabajando, pero los comentarios deben incorporarse en la siguiente revisión.', hints: ['Eso es el código 3.', null, 'Eso es el código 1.', 'Si la devolvió con código, ya la revisó.'] };
const Q_DC1C3_3 = { id: 'dc1c3-q3', q: 'Un técnico conecta un cable en otra bornera porque la original estaba dañada. ¿Qué debe hacer?', options: ['Nada, funciona igual', 'Marcarlo en rojo en el plano (red line) para que se pase al as built', 'Avisar solo de palabra', 'Cambiar el número del instrumento'], answer: 1, explain: 'La red line registra el cambio en campo; después la ingeniería la pasa al plano como construido.', hints: ['El próximo técnico buscará el cable en la bornera original.', null, 'De palabra se olvida.', 'El TAG no cambia por cambiar una bornera.'] };

const SCENES_DC1C3 = [
  { C: (p) => <TitleCardM4 {...p} claseNo={3} title="Revisiones y control de cambios" dudur="6 min" objetivo="Los estados de emisión, las revisiones con letras y números, las nubes, los códigos de comentarios, el transmittal, la gestión del cambio y las red lines." />, dur: 14, label: 'Apertura' },
  { C: S_Why, dur: 28, label: 'Por qué importa' },
  { C: S_Status, dur: 42, label: 'Estados de emisión' },
  { C: S_Letters, dur: 30, label: 'Letras y números' },
  { C: QuizSceneM4, dur: 12, label: 'Pregunta 1', quiz: Q_DC1C3_1 },
  { C: S_Clouds, dur: 32, label: 'Nubes y triángulos' },
  { C: S_Codes, dur: 32, label: 'Comentarios' },
  { C: S_Transmittal, dur: 24, label: 'El transmittal' },
  { C: QuizSceneM4, dur: 12, label: 'Pregunta 2', quiz: Q_DC1C3_2 },
  { C: S_Moc, dur: 38, label: 'Gestión del cambio' },
  { C: S_Redline, dur: 32, label: 'Red lines y as built' },
  { C: S_Example, dur: 38, label: 'Ejemplo' },
  { C: QuizSceneM4, dur: 12, label: 'Pregunta 3', quiz: Q_DC1C3_3 },
  { C: (p) => <><ClosingM4 {...p} line="Un plano solo sirve si es la versión vigente y dice la verdad." activity="Busca el procedimiento de control de documentos de tu empresa o de un proyecto: ¿qué estados y qué códigos de revisión usa?" /><QuizScoreM4 {...p} /></>, dur: 16, label: 'Cierre' },
];
window.SCENES_DC1C3 = SCENES_DC1C3;
