/* eslint-disable */
/* global React, ReactDOM, useLang, LangProvider, HeroNav, Footer */
/* soluciones/controller.jsx — landing "Soluciones" para /soluciones/controller
   (redesign 2026-09, Sprint 3). Textos definitivos del handoff: no
   reescribir, salvo un desvío señalado al usuario: la sección de
   Seguridad decía "SOC 2 Type II, permisos por rol..." — se corrigió a
   la única redacción de compliance correcta sitewide (SOC 2 Type I
   certificado, Type II en curso), igual que en seguridad.jsx,
   mcp.jsx y gobernanza-trazabilidad.jsx. También se reemplazó el
   logo "soc2-type2.png" (no vigente) por el link de texto al trust
   center. Página en español únicamente (sin toggle EN) — mismo criterio
   que el resto de las páginas de Producto/Soluciones. Reusa
   product.css/hero-nav.css tal cual quedaron después del pase de
   consistencia con la home. */

const VIVE_CARDS = [
  { icon: 'ph-clock-countdown', title: '"Consolidar me ocupa el 70% de la semana"', body: 'La parte de valor — analizar desvíos, entender la causa, proponer acciones — queda para el final, apurada. Teramot invierte esa proporción.' },
  { icon: 'ph-shield-check', title: '"El auditor me consume una semana por trimestre"', body: 'Con log completo y trazabilidad, la respuesta al auditor es un export, no una reconstrucción.' },
  { icon: 'ph-copy', title: '"Cada área me pide su reporte y yo repito el mismo trabajo"', body: 'Los reportes recurrentes se automatizan una vez; después se entregan solos.' },
];

const AUTOMATIZA_CARDS = [
  { icon: 'ph-stack', title: 'Consolidación automática', body: 'ERP + planillas, sin bajar CSVs.' },
  { icon: 'ph-git-commit', title: 'Ajustes con log', body: 'De cambios y responsable identificado.' },
  { icon: 'ph-envelope', title: 'Reportes recurrentes', body: 'Entregados automáticamente por mail.' },
  { icon: 'ph-chart-bar', title: 'Análisis de desvíos', body: 'Budget vs actual con drill-down al ERP.' },
  { icon: 'ph-download-simple', title: 'Export auditor-friendly', body: 'Todo el log con un click.' },
  { icon: 'ph-function', title: 'Fórmulas visibles', body: 'Cada número se puede verificar en segundos.' },
];

const DIA_A_DIA_LINKS = [
  { href: '/cierre-mensual.html', icon: 'ph-check-square-offset', title: 'Cierre contable mensual', body: 'Del cierre de dos semanas al número en dos minutos' },
  { href: '/presupuesto-forecast.html', icon: 'ph-chart-line-up', title: 'Presupuesto & Forecast', body: 'Escenarios sin romper el modelo' },
  { href: '/rentabilidad.html', icon: 'ph-coins', title: 'Rentabilidad', body: 'Margen real, tres ejes.' },
  { href: '/reportes-ad-hoc.html', icon: 'ph-chat-circle-text', title: 'Reportes Ad-hoc con IA', body: 'El número en la reunión.' },
];

const { useEffect: useEffectPC, useRef: useRefPC } = React;

/* Scroll reveal — mismo hook que el resto de las páginas de Producto. */
const useScrollReveal = (rootRef) => {
  useEffectPC(() => {
    if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
    const root = rootRef.current;
    if (!root) return;
    const groups = [];
    root.querySelectorAll('section, footer').forEach((sec) => {
      const wrap = sec.firstElementChild && sec.children.length === 1 ? sec.firstElementChild : sec;
      const kids = Array.from(wrap.children).filter((el) => (
        el.nodeType === 1 && !el.classList.contains('tm-drawer') && !el.classList.contains('tm-drawer-overlay')
      ));
      if (kids.length) groups.push(kids);
    });
    const io = new IntersectionObserver((entries) => {
      entries.forEach((en) => {
        if (en.isIntersecting) {
          en.target.classList.add('rv-in');
          io.unobserve(en.target);
        }
      });
    }, { rootMargin: '0px 0px -8% 0px', threshold: 0.08 });
    groups.forEach((kids) => kids.forEach((el, i) => {
      el.classList.add('rv');
      el.style.transitionDelay = Math.min(i, 4) * 70 + 'ms';
      io.observe(el);
    }));
    return () => io.disconnect();
  }, []);
};

const ControllerHero = () => {
  const { c } = useLang();
  return (
    <section className="tm-hero-gradient">
      <HeroNav current="controller" />
      <div className="tm-prod-hero-grid">
        <div className="tm-prod-hero-copy">
          <p className="tm-prod-hero-eyebrow">Control de gestión · Automatización · Trazabilidad</p>
          <h1>Software para Controller: <span>menos tiempo consolidando</span>, más tiempo analizando.</h1>
          <p className="tm-prod-hero-sub">Automatizá lo repetitivo del control de gestión y quedate con la parte que suma.</p>
          <div className="tm-prod-hero-actions">
            <a href={c.links.call} target="_blank" rel="noopener noreferrer" className="tm-hero-btn tm-hero-btn-lg tm-hero-btn-white">Pedí tu demo <i className="ph ph-arrow-right" /></a>
            <a href={c.links.app} className="tm-hero-btn tm-hero-btn-lg tm-hero-btn-ghost-light"><i className="ph ph-play-circle" style={{ fontSize: 21 }} /> Comenzá Gratis</a>
          </div>
        </div>
        <div className="tm-prod-hero-art">
          <div className="tm-prod-hero-art-glow" />
          <div className="tm-prod-hero-mockup" style={{ position: 'relative', zIndex: 1, width: '100%', background: 'rgba(255,255,255,.96)', border: '1px solid rgba(255,255,255,.55)', borderRadius: 16, padding: 18, boxShadow: '0 2px 4px rgba(11,15,20,.05), 0 1px 2px rgba(11,15,20,.03)' }} role="img" aria-label="Panel de control de gestión en Teramot">
            <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12 }}>
              <span style={{ display: 'inline-flex', alignItems: 'center', gap: 7, padding: '6px 12px', borderRadius: 9999, background: '#253DE5', color: '#fff', fontSize: 11, fontWeight: 600, whiteSpace: 'nowrap' }}><i className="ph-bold ph-stack" style={{ fontSize: 12 }} /> Control de gestión</span>
              <span style={{ fontSize: 10.5, fontWeight: 600, letterSpacing: '.12em', textTransform: 'uppercase', color: '#6B7280' }}>Semana 12</span>
            </div>
            <div style={{ marginTop: 16, borderRadius: 10, background: '#fff', border: '1px solid #EEF0F4', overflow: 'hidden' }}>
              {[
                { icon: 'ph-stack', label: 'Consolidación ERP + planillas', status: 'Automática' },
                { icon: 'ph-git-commit', label: 'Ajustes con log', status: 'Listo' },
                { icon: 'ph-chart-bar', label: 'Análisis de desvíos', status: 'Listo' },
                { icon: 'ph-envelope', label: 'Reportes recurrentes', status: 'Programados', neutral: true },
              ].map((row, i, arr) => (
                <div key={row.label} style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 14, padding: '14px 16px', borderBottom: i < arr.length - 1 ? '1px solid rgba(11,15,20,.05)' : 'none' }}>
                  <div style={{ display: 'flex', alignItems: 'center', gap: 10, minWidth: 0 }}><i className={`ph ${row.icon}`} style={{ fontSize: 15, color: '#253DE5', flex: 'none' }} /><span style={{ fontSize: 13.5, fontWeight: 500, letterSpacing: '-.005em', color: '#0B0F14' }}>{row.label}</span></div>
                  {row.neutral ? (
                    <span style={{ flex: 'none', whiteSpace: 'nowrap', padding: '4px 10px', borderRadius: 9999, border: '1px solid #E5E7EB', background: '#fff', fontSize: 10.5, fontWeight: 600, color: '#4B5563' }}>{row.status}</span>
                  ) : (
                    <span style={{ flex: 'none', whiteSpace: 'nowrap', display: 'inline-flex', alignItems: 'center', gap: 5, padding: '4px 10px', borderRadius: 9999, background: 'rgba(123,193,173,.22)', fontSize: 10.5, fontWeight: 600, color: '#2F6B58' }}><i className="ph-bold ph-check" style={{ fontSize: 11 }} /> {row.status}</span>
                  )}
                </div>
              ))}
            </div>
            <div style={{ display: 'flex', alignItems: 'flex-end', minHeight: 80, padding: '18px 176px 0 4px' }}>
              <p style={{ fontSize: 11.5, fontWeight: 500, lineHeight: 1.45, color: '#4B5563' }}>La respuesta al auditor es un export, no una reconstrucción</p>
            </div>
          </div>
          <div style={{ position: 'absolute', right: -16, bottom: -24, zIndex: 2, width: 172, background: '#fff', border: '1px solid #E5E7EB', borderRadius: 11, boxShadow: '0 2px 4px rgba(11,15,20,.06), 0 1px 2px rgba(11,15,20,.04)', padding: '12px 13px' }}>
            <p style={{ fontSize: 8.5, fontWeight: 600, letterSpacing: '.14em', textTransform: 'uppercase', color: '#9CA3AF' }}>Auditoría · Q1</p>
            <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginTop: 9 }}>
              <span style={{ flex: 'none', width: 22, height: 22, borderRadius: 9999, background: '#263185', display: 'flex', alignItems: 'center', justifyContent: 'center' }}><i className="ph-bold ph-check" style={{ color: '#91DFC8', fontSize: 11 }} /></span>
              <span style={{ fontSize: 12.5, fontWeight: 600, letterSpacing: '-.01em', color: '#0B0F14' }}>Log completo</span>
            </div>
            <div style={{ display: 'flex', alignItems: 'center', gap: 6, marginTop: 9, paddingTop: 9, borderTop: '1px solid #EEF0F4' }}>
              <i className="ph ph-git-commit" style={{ color: '#253DE5', fontSize: 12, flex: 'none' }} />
              <span style={{ fontSize: 10, fontWeight: 500, lineHeight: 1.35, color: '#4B5563' }}>Cada número se verifica en segundos</span>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
};

const ViveSection = () => (
  <section className="tm-prod-section tm-prod-section-paper">
    <div className="tm-container">
      <div className="tm-prod-head">
        <h2>Lo que un controller vive todas las semanas</h2>
      </div>
      <div className="tm-prod-cards">
        {VIVE_CARDS.map((card) => (
          <article className="tm-prod-card" key={card.title}>
            <div className="tm-prod-card-icon"><i className={`ph ${card.icon}`} /></div>
            <h3>{card.title}</h3>
            <p>{card.body}</p>
          </article>
        ))}
      </div>
    </div>
  </section>
);

const AutomatizaSection = () => (
  <section className="tm-prod-section tm-prod-section-white">
    <div className="tm-container">
      <div className="tm-prod-head">
        <h2>Qué automatiza Teramot</h2>
      </div>
      <div className="tm-prod-cards">
        {AUTOMATIZA_CARDS.map((card) => (
          <article className="tm-prod-card" key={card.title}>
            <div className="tm-prod-card-icon"><i className={`ph ${card.icon}`} /></div>
            <h3>{card.title}</h3>
            <p>{card.body}</p>
          </article>
        ))}
      </div>
    </div>
  </section>
);

const DiaADiaSection = () => (
  <section className="tm-prod-section tm-prod-section-wash">
    <div className="tm-container">
      <div className="tm-prod-head">
        <h2>Cómo se ve Teramot en el día a día del Controller</h2>
      </div>
      <div className="tm-prod-cards">
        {DIA_A_DIA_LINKS.map((item) => (
          <a className="tm-prod-card" href={item.href} key={item.title} style={{ display: 'block', textDecoration: 'none' }}>
            <div className="tm-prod-card-icon"><i className={`ph ${item.icon}`} /></div>
            <h3>{item.title}</h3>
            <p>{item.body}</p>
            <span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, marginTop: 16, fontSize: 12.5, fontWeight: 600, color: '#253DE5' }}>Ver más <i className="ph-bold ph-arrow-right" style={{ fontSize: 12 }} /></span>
          </a>
        ))}
      </div>
    </div>
  </section>
);

const SeguridadSection = () => (
  <section className="tm-prod-section tm-prod-section-paper" style={{ textAlign: 'center' }}>
    <div className="tm-container" style={{ maxWidth: 820 }}>
      <h2 style={{ fontSize: 'clamp(26px,2.6vw,34px)', lineHeight: 1.18, fontWeight: 600, letterSpacing: '-.035em', color: '#1C2536', textWrap: 'pretty' }}>SOC 2 Type I certificado, permisos por rol, trazabilidad completa</h2>
      <p style={{ marginTop: 16, fontSize: 15.5, lineHeight: 1.6, color: '#4B5563' }}>Antes de que el CISO pregunte. <a href="/seguridad.html" style={{ fontWeight: 600 }}>Ver trust center <i className="ph-bold ph-arrow-right" style={{ fontSize: 12 }} /></a></p>
    </div>
  </section>
);

const CtaFinalSection = () => {
  const { c } = useLang();
  return (
    <section id="demo" className="tm-prod-cta">
      <div className="tm-prod-cta-inner">
        <p className="tm-prod-cta-kicker">Empezá ahora</p>
        <h2>Recuperá tu semana</h2>
        <p className="tm-prod-cta-sub">30 minutos y te mostramos cómo se ve el proceso automatizado.</p>
        <div className="tm-prod-cta-actions">
          <a href={c.links.call} target="_blank" rel="noopener noreferrer" className="tm-btn tm-btn-lg" style={{ background: '#fff', color: '#253DE5', borderColor: 'transparent', borderRadius: 9999, fontWeight: 600 }}>Pedí tu demo</a>
          <a href={c.links.app} className="tm-btn tm-btn-lg" style={{ background: 'transparent', color: '#fff', border: '1px solid rgba(255,255,255,.5)', borderRadius: 9999, fontWeight: 600 }}>Comenzá Gratis</a>
        </div>
        <p className="tm-prod-cta-fine">Sin proyecto de IT · Setup en semanas, no meses · Tus planillas siguen funcionando</p>
      </div>
    </section>
  );
};

const ParaControllerApp = () => {
  const rootRef = useRefPC(null);
  useScrollReveal(rootRef);
  return (
    <main ref={rootRef} className="tm-prod">
      <ControllerHero />
      <ViveSection />
      <AutomatizaSection />
      <DiaADiaSection />
      <SeguridadSection />
      <CtaFinalSection />
      <Footer />
    </main>
  );
};

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <LangProvider defaultLang="es">
    <ParaControllerApp />
  </LangProvider>
);
