// dc1c1.jsx — Diseño de Ingeniería I&C · Clase 1.1 «Cómo nace una planta».
// Después de di-lib.jsx, temp-art.jsx y di-art.jsx. Exporta SCENES_DC1C1.
const TIEMPOS_DC1C1 = [[0.6, 5.2], [0.6, 4.4, 8.85, 15.79], [0.6, 4.68, 9.37, 14.59, 21.55, 24.58, 30.48, 35.38, 39.02], [0.6], [0.6, 5.68, 7.32, 13.19, 16.81, 19.76, 25.11], [0.6, 3.18, 8.26, 10.93, 17.62, 21.38, 25.14], [0.6, 4.59, 8.09, 12.19, 18.34], [0.6], [0.6, 6.32, 9.73, 11.51, 16.52, 23.37, 29.03, 33.43], [0.6, 5.8, 11.25, 15.45, 20.22], [0.6, 3.67, 9.17, 14.62, 20.84], [0.6, 5.02], [0.6, 2.71, 5.36, 8.41, 11.34, 15.82, 21.18], [0.6, 3.44]]; // auto
const fr = (i, k) => (TIEMPOS_DC1C1[i] || [])[k] ?? 0.6 + k * 4;

function S_Before({ start, dur }) {
  const t = useTime(); const s = start; const I = 1;
  const a = (k) => pop4(t, s + fr(I, k));
  const docs = [['P&ID', 'Dónde va', 'pid', TL4.blue], ['Hoja de datos', 'Cómo es', 'table', TL4.orange], ['Diagrama de lazo', 'Cómo se conecta', 'logic', TL4.blueD]];
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="Antes de la planta">Antes de que exista una planta, <span style={{ color: TL4.orangeD }}>existen sus documentos</span>.</HeadM14>
      <StatM4 x={220} y={360} value="1 000 – 5 000" label="instrumentos en una planta mediana" appear={s + fr(I, 1)} t={t} />
      <svg style={SVG_T}>
        {docs.map((d, i) => <g key={i} opacity={a(2).op}><DocSheet x={1000 + i * 260} y={330} w={150} h={196} title={d[0]} kind={d[2]} color={d[3]} />
          <text x={1075 + i * 260} y={590} fill={TL4.mut} fontFamily={DISP4} fontSize="19" textAnchor="middle">{d[1]}</text></g>)}
      </svg>
      <div style={{ position: 'absolute', left: 220, top: 720, width: 1480, opacity: a(3).op }}>
        <NoteT bg={TL4.orangeWash} size={26}>En este curso aprendes a <b>leer</b> y a <b>crear</b> esos documentos, como se hace en una empresa de ingeniería y en un área de mantenimiento.</NoteT>
      </div>
    </SceneM4>
  );
}

function S_Phases({ start, dur }) {
  const t = useTime(); const s = start; const I = 2;
  const ph = [
    ['Conceptual', '¿Qué planta y si conviene?', '±40 %', 1, TL4.mut],
    ['Básica (FEED)', 'Proceso, equipos y P&ID', '±15 %', 3, TL4.blue],
    ['Detallada', 'Todo para comprar y construir', '±10 %', 5, TL4.orange],
    ['Procura y construcción', 'Se compra y se monta', '', 6, TL4.blueD],
    ['Puesta en marcha', 'Se prueba cada lazo', '', 7, FA.ok],
    ['Operación y mantenimiento', '30 años o más', '', 8, TL4.ink],
  ];
  const W = 250, x0 = 150;
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="Las fases de un proyecto">En cada fase <span style={{ color: TL4.orangeD }}>se sabe un poco más</span>.</HeadM14>
      <svg style={SVG_T}>
        <line x1={x0} y1={560} x2={x0 + 6 * (W + 20) - 20} y2={560} stroke={TL4.lineS} strokeWidth={4} opacity={pop4(t, s + fr(I, 0)).op} />
      </svg>
      {ph.map((p, i) => { const q = pop4(t, s + fr(I, p[3])); const big = i === 2; return (
        <div key={i} style={{ position: 'absolute', left: x0 + i * (W + 20), top: big ? 330 : 360, width: W, opacity: q.op, transform: `translateY(${q.ty}px)`, fontFamily: DISP4 }}>
          <div style={{ background: big ? TL4.orangeWash : TL4.paper, borderRadius: 14, boxShadow: big ? 'none' : TL4.shadowSm, borderTop: `6px solid ${p[4]}`, padding: '18px 18px', minHeight: big ? 200 : 170 }}>
            <div style={{ fontFamily: MONO4, fontSize: 15, color: TL4.mut, letterSpacing: '0.12em' }}>FASE {i + 1}</div>
            <div style={{ fontSize: 25, fontWeight: 700, marginTop: 6, color: TL4.ink, lineHeight: 1.15 }}>{p[0]}</div>
            <div style={{ fontSize: 18, color: TL4.mut, marginTop: 8, lineHeight: 1.35 }}>{p[1]}</div>
          </div>
          {p[2] && <div style={{ marginTop: 18, textAlign: 'center', fontFamily: MONO4, fontSize: 24, fontWeight: 700, color: TL4.orangeD, opacity: pop4(t, s + fr(I, p[3] + (i < 2 ? 1 : 0))).op }}>costo {p[2]}</div>}
        </div>); })}
      <div style={{ position: 'absolute', left: 150, top: 800, width: 1600, opacity: pop4(t, s + fr(I, 5)).op }}>
        <NoteT accent={TL4.orange} size={23}>La <b>ingeniería detallada</b> es la fase con más documentos: es donde empieza a trabajar la mayoría de los ingenieros junior y diseñadores.</NoteT>
      </div>
    </SceneM4>
  );
}

function S_Detail({ start, dur }) {
  const t = useTime(); const s = start; const I = 4;
  const a = (k) => pop4(t, s + fr(I, k));
  const items = [['P&ID completos', 'pid', TL4.blue, 3], ['Hojas de datos y cálculos', 'table', TL4.orange, 4], ['Diagramas lógicos, de lazo y conexionado', 'logic', TL4.blueD, 5], ['Típicos y lista de materiales', 'lines', FA.ok, 6]];
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="La ingeniería detallada">Comprar, montar y conectar <span style={{ color: TL4.orangeD }}>sin adivinar nada</span>.</HeadM14>
      <div style={{ position: 'absolute', left: 220, top: 300, width: 1480, opacity: a(1).op }}>
        <NoteT accent={TL4.blue} size={26}>La meta: que el comprador, el montador y el electricista <b>encuentren en los documentos todo lo que necesitan</b>.</NoteT>
      </div>
      <svg style={SVG_T}>
        {items.map((d, i) => <g key={i} opacity={a(d[3]).op}><DocSheet x={300 + i * 360} y={480} w={170} h={220} kind={d[1]} color={d[2]} /></g>)}
      </svg>
      {items.map((d, i) => <div key={i} style={{ position: 'absolute', left: 245 + i * 360, top: 720, width: 280, textAlign: 'center', opacity: a(d[3]).op, fontFamily: DISP4, fontSize: 23, fontWeight: 700, color: TL4.ink, lineHeight: 1.25 }}>{d[0]}</div>)}
    </SceneM4>
  );
}

function S_Disc({ start, dur }) {
  const t = useTime(); const s = start; const I = 5;
  const cx = 960, cy = 590;
  const nodes = [
    ['Procesos', 'P&ID y datos de operación', 430, 420, 1, TL4.blue, 'in'],
    ['Tuberías', 'conexiones y válvulas', 1490, 420, 3, TL4.orange, 'out'],
    ['Electricidad', 'consumos de los tableros', 1490, 760, 4, TL4.blueD, 'out'],
    ['Civil', 'bases y canalizaciones', 430, 760, 5, TL4.mut, 'out'],
  ];
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="Las disciplinas">Ninguna disciplina <span style={{ color: TL4.orangeD }}>trabaja sola</span>.</HeadM14>
      <svg style={SVG_T}>
        {nodes.map((n, i) => { const op = pop4(t, s + fr(I, n[4])).op; const [x1, y1, x2, y2] = n[6] === 'in' ? [n[2], n[3], cx, cy] : [cx, cy, n[2], n[3]]; return (
          <g key={i} opacity={op}><line x1={x1} y1={y1} x2={x2} y2={y2} stroke={n[5]} strokeWidth={4} strokeDasharray="10 8" strokeDashoffset={-t * 30} />
            <circle cx={x2 + (x1 - x2) * 0.18} cy={y2 + (y1 - y2) * 0.18} r={9} fill={n[5]} /></g>); })}
        <circle cx={cx} cy={cy} r={120} fill={TL4.orangeWash} stroke={TL4.orange} strokeWidth={4} opacity={pop4(t, s + fr(I, 0)).op} />
        <text x={cx} y={cy - 6} fill={TL4.orangeD} fontFamily={DISP4} fontSize="34" fontWeight="700" textAnchor="middle" opacity={pop4(t, s + fr(I, 0)).op}>I&amp;C</text>
        <text x={cx} y={cy + 30} fill={TL4.mut} fontFamily={DISP4} fontSize="18" textAnchor="middle" opacity={pop4(t, s + fr(I, 0)).op}>instrumentación y control</text>
      </svg>
      {nodes.map((n, i) => { const p = pop4(t, s + fr(I, n[4])); return (
        <div key={i} style={{ position: 'absolute', left: n[2] - 170, top: n[3] - 56, width: 340, opacity: p.op, background: TL4.paper, borderRadius: 14, boxShadow: TL4.shadowSm, borderLeft: `6px solid ${n[5]}`, padding: '14px 20px', fontFamily: DISP4 }}>
          <div style={{ fontSize: 26, fontWeight: 700 }}>{n[0]}</div>
          <div style={{ fontSize: 19, color: TL4.mut }}>{n[6] === 'in' ? 'entrega: ' : 'recibe: '}{n[1]}</div>
        </div>); })}
      <div style={{ position: 'absolute', left: 560, top: 900, width: 800, textAlign: 'center', opacity: pop4(t, s + fr(I, 6)).op, fontFamily: DISP4, fontSize: 24, color: TL4.ink }}>Un dato que llega <b style={{ color: TL4.orangeD }}>tarde o mal</b> se propaga a todas las disciplinas.</div>
    </SceneM4>
  );
}

function S_IcDoes({ start, dur }) {
  const t = useTime(); const s = start; const I = 6;
  const rows = [
    ['1 · Especificar', 'Elegir cada instrumento: tipo, rango, materiales y señal. Hojas de datos y cálculos.', TL4.blue],
    ['2 · Controlar y proteger', 'Cómo se controla el proceso y qué lo protege: lazos, lógicas y enclavamientos.', TL4.orange],
    ['3 · Conectar', 'Cada señal desde el campo hasta el sistema de control: cables, cajas y borneras.', TL4.blueD],
    ['4 · Mostrar', 'Lo que el operador ve: pantallas HMI y alarmas.', FA.ok],
  ];
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="Qué hace I&C">Cuatro trabajos <span style={{ color: TL4.orangeD }}>de la disciplina</span>.</HeadM14>
      <RowsM14 s={s} t={t} rows={rows} y={320} cols="400px 1fr" ats={[1, 2, 3, 4].map(k => fr(I, k))} />
    </SceneM4>
  );
}

function S_Life({ start, dur }) {
  const t = useTime(); const s = start; const I = 8;
  const st = [
    ['Conceptual', '«Hay que medir el nivel»', 1, TL4.mut],
    ['Básica', 'Aparece en el P&ID con su lazo y alarmas', 3, TL4.blue],
    ['Detallada', 'Hoja de datos, cálculo, lazo y típico', 4, TL4.orange],
    ['Procura', 'La hoja de datos → orden de compra', 5, TL4.blueD],
    ['Construcción', 'El típico dice cómo montarlo', 6, FA.ok],
    ['Mantenimiento', 'Se calibra con la misma hoja', 7, TL4.ink],
  ];
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="La vida de un instrumento">El LT-101 <span style={{ color: TL4.orangeD }}>de principio a fin</span>.</HeadM14>
      <svg style={SVG_T}>
        <g opacity={pop4(t, s + fr(I, 0)).op}>
          <Vessel x={200} y={330} w={190} h={330} level={0.45 + 0.05 * Math.sin(t * 0.8)} t={t} name="V-100" />
          <line x1={390} y1={420} x2={450} y2={420} stroke={DI.ink} strokeWidth={3} /><line x1={390} y1={600} x2={450} y2={600} stroke={DI.ink} strokeWidth={3} />
          <line x1={450} y1={420} x2={450} y2={600} stroke={DI.ink} strokeWidth={3} />
          <SigLine x1={450} y1={510} x2={520} y2={510} type="electric" />
          <IsaBubble x={570} y={510} r={50} tag="LT" num="101" />
        </g>
      </svg>
      {st.map((p, i) => { const q = pop4(t, s + fr(I, p[2])); return (
        <div key={i} style={{ position: 'absolute', left: 720 + (i % 2) * 560, top: 320 + Math.floor(i / 2) * 170, width: 520, opacity: q.op, transform: `translateY(${q.ty}px)`, background: i === 2 ? TL4.orangeWash : TL4.paper, borderRadius: 14, boxShadow: i === 2 ? 'none' : TL4.shadowSm, borderLeft: `6px solid ${p[3]}`, padding: '16px 22px', fontFamily: DISP4 }}>
          <div style={{ fontFamily: MONO4, fontSize: 15, color: TL4.mut, letterSpacing: '0.12em' }}>{String(i + 1).padStart(2, '0')} · {p[0].toUpperCase()}</div>
          <div style={{ fontSize: 23, fontWeight: 600, marginTop: 6 }}>{p[1]}</div>
        </div>); })}
    </SceneM4>
  );
}

function S_Maint({ start, dur }) {
  const t = useTime(); const s = start; const I = 9;
  const a = (k) => pop4(t, s + fr(I, k));
  const docs = [['P&ID', '¿Qué controla este transmisor?', 'pid', TL4.blue, 1], ['Diagrama de lazo', '¿Dónde está su cable y su bornera?', 'logic', TL4.blueD, 2], ['Hoja de datos', '¿Qué repuesto pido?', 'table', TL4.orange, 3]];
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="En mantenimiento">Las <span style={{ color: TL4.orangeD }}>3 de la mañana</span>: el nivel marca cero.</HeadM14>
      <svg style={SVG_T}>
        <g opacity={a(0).op}>
          <HmiFrame x={190} y={330} w={420} h={260} title="V-100 · Separador">
            <HmiValue x={40} y={40} tag="LT-101" value="0,0" unit="%" alarm="LL" />
            <HmiBar x={300} y={30} h={200} v={0.02} lo={0.3} hi={0.7} alarm />
          </HmiFrame>
        </g>
        {docs.map((d, i) => <g key={i} opacity={a(d[4]).op}><DocSheet x={800 + i * 330} y={330} w={150} h={196} kind={d[2]} color={d[3]} title={d[0]} /></g>)}
      </svg>
      {docs.map((d, i) => <div key={i} style={{ position: 'absolute', left: 755 + i * 330, top: 590, width: 240, textAlign: 'center', opacity: a(d[4]).op, fontFamily: DISP4, fontSize: 20, color: TL4.mut, lineHeight: 1.3 }}>{d[1]}</div>)}
      <div style={{ position: 'absolute', left: 190, top: 770, width: 1540, opacity: a(4).op }}>
        <NoteT bg={TL4.orangeWash} size={26}>Con buenos documentos, una falla de <b>10 minutos</b> sigue siendo de 10 minutos. Sin ellos, se vuelve una <b>parada de horas</b>.</NoteT>
      </div>
    </SceneM4>
  );
}

function S_Roles({ start, dur }) {
  const t = useTime(); const s = start; const I = 10;
  const cards = [
    ['Diseñador o dibujante', 'Dibuja P&ID, lazos y típicos en AutoCAD, SmartPlant o similares.', TL4.blue, 1],
    ['Ingeniero junior', 'Cálculos, hojas de datos, índice de instrumentos y listas.', TL4.orange, 2],
    ['Ingeniero líder', 'Revisa, coordina con las otras disciplinas y firma.', TL4.blueD, 3],
    ['Técnico de mantenimiento', 'Usa los documentos cada día: calibra, repara y marca cambios.', FA.ok, 4],
  ];
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="Quién usa los documentos">Cuatro puestos, <span style={{ color: TL4.orangeD }}>los mismos documentos</span>.</HeadM14>
      {cards.map((c, i) => <InfoCardM4 key={i} x={150 + i * 420} y={360} w={380} h={330} accent={c[2]} title={c[0]} sub={c[1]} appear={s + fr(I, c[3])} t={t} />)}
    </SceneM4>
  );
}

function S_Map({ start, dur }) {
  const t = useTime(); const s = start; const I = 12;
  const mods = [
    ['1', 'El proyecto y sus normas', 1], ['2', 'P&ID y simbología ISA 5.1', 2], ['3', 'Hojas de datos y cálculos', 3],
    ['4', 'Lógica y filosofía de control', 4], ['5', 'Lazos y conexionado', 4], ['6', 'Típicos y áreas clasificadas', 5],
    ['7', 'HMI y alarmas', 6], ['8', 'Puesta en marcha y mantenimiento', 6],
  ];
  return (
    <SceneM4 start={start} dur={dur}>
      <HeadM14 s={s} dur={dur} kicker="El mapa del curso">Ocho módulos, <span style={{ color: TL4.orangeD }}>del P&ID a la pantalla</span>.</HeadM14>
      {mods.map((m, i) => { const p = pop4(t, s + fr(I, m[2])); return (
        <div key={i} style={{ position: 'absolute', left: 190 + (i % 4) * 390, top: 330 + Math.floor(i / 4) * 230, width: 360, height: 190, opacity: p.op, transform: `translateY(${p.ty}px)`, background: TL4.paper, borderRadius: 14, boxShadow: TL4.shadowSm, padding: '20px 24px', fontFamily: DISP4 }}>
          <div style={{ fontFamily: MONO4, fontSize: 40, fontWeight: 700, color: i % 2 ? TL4.orangeD : TL4.blue }}>{m[0].padStart(2, '0')}</div>
          <div style={{ fontSize: 25, fontWeight: 700, marginTop: 8, lineHeight: 1.2 }}>{m[1]}</div>
        </div>); })}
    </SceneM4>
  );
}

const Q_DC1C1_1 = { id: 'dc1c1-q1', q: '¿En qué fase se produce la mayor cantidad de planos y hojas de datos para comprar y construir?', options: ['Ingeniería conceptual', 'Ingeniería básica (FEED)', 'Ingeniería detallada', 'Operación'], answer: 2, explain: 'La ingeniería detallada produce todo lo necesario para comprar, montar y conectar: hojas de datos, diagramas, típicos y listas.', hints: ['En la conceptual apenas se decide si la planta conviene.', 'La básica define el proceso y los P&ID, pero no el detalle para construir.', null, 'En operación se usan los documentos, no se crean.'] };
const Q_DC1C1_2 = { id: 'dc1c1-q2', q: '¿Quién le entrega a instrumentación los datos de presión, temperatura y caudal de cada línea?', options: ['Tuberías', 'Procesos', 'Electricidad', 'Civil'], answer: 1, explain: 'Procesos define las condiciones de operación y los P&ID: son la entrada de instrumentación.', hints: ['Tuberías recibe de instrumentación dónde van las conexiones.', null, 'Electricidad recibe los consumos de los tableros.', 'Civil recibe las bases y canalizaciones.'] };
const Q_DC1C1_3 = { id: 'dc1c1-q3', q: 'A las 3 de la mañana falla un transmisor. ¿Qué documento te dice en qué bornera está su cable?', options: ['La hoja de datos', 'El P&ID', 'El diagrama de lazo', 'La lista de materiales'], answer: 2, explain: 'El diagrama de lazo muestra cada conexión del instrumento: cables, cajas, borneras y la tarjeta del sistema de control.', hints: ['La hoja de datos dice cómo es el instrumento, no cómo se conecta.', 'El P&ID muestra la función, no los cables ni las borneras.', null, 'La lista de materiales dice qué se compra.'] };

const SCENES_DC1C1 = [
  { C: (p) => <TitleCardM4 {...p} claseNo={1} title="Cómo nace una planta" dudur="6 min" objetivo="Las fases de un proyecto, qué produce la ingeniería detallada, cómo se relacionan las disciplinas, qué hace instrumentación y control, y por qué mantenimiento depende de los documentos." />, dur: 15, label: 'Apertura' },
  { C: S_Before, dur: 23, label: 'Antes de la planta' },
  { C: S_Phases, dur: 46, label: 'Las fases' },
  { C: QuizSceneM4, dur: 12, label: 'Pregunta 1', quiz: Q_DC1C1_1 },
  { C: S_Detail, dur: 32, label: 'La ingeniería detallada' },
  { C: S_Disc, dur: 34, label: 'Las disciplinas' },
  { C: S_IcDoes, dur: 32, label: 'Qué hace I&C' },
  { C: QuizSceneM4, dur: 12, label: 'Pregunta 2', quiz: Q_DC1C1_2 },
  { C: S_Life, dur: 42, label: 'La vida de un instrumento' },
  { C: S_Maint, dur: 30, label: 'Mantenimiento' },
  { C: S_Roles, dur: 30, label: 'Los puestos' },
  { C: QuizSceneM4, dur: 12, label: 'Pregunta 3', quiz: Q_DC1C1_3 },
  { C: S_Map, dur: 30, label: 'El mapa del curso' },
  { C: (p) => <><ClosingM4 {...p} line="Una planta se construye primero en papel. Quien sabe leer y crear esos documentos tiene trabajo en ingeniería y en mantenimiento." activity="Consigue un P&ID o un diagrama de lazo real (de tu trabajo o de internet) y anota qué disciplinas participaron en él." /><QuizScoreM4 {...p} /></>, dur: 16, label: 'Cierre' },
];
window.SCENES_DC1C1 = SCENES_DC1C1;
