/* App.jsx — shell que compone Sidebar + EquipmentList + DashboardArea + ActionBar
   en una sola superficie de operaciones HVAC. */
const { useState: useStateApp } = React;

const UNITS = [
  { id: 'u-901', name: 'Condensadora 30-ton Bay-2', sku: 'SKU-IND-901', kind: 'Evaporador industrial',
    client: 'Almacén Frío del Pacífico', location: 'Houston TX · Bahía 2',
    status: 'maintenance', reading: '−17.4°C',
    metrics: { reading: '−17.4°C', setpoint: '−18.0°C', capacity: '30 ton', refrigerant: 'R-32' },
    events: [
      { time: '14:02', msg: 'Ciclo de descarche iniciado · operador remoto' },
      { time: '13:48', msg: 'Alerta de carga térmica · automática' },
      { time: '09:10', msg: 'Inspección rutinaria · técnico M. Ortega' },
    ] },
  { id: 'u-642', name: 'Rooftop 10-ton — Office West',  sku: 'SKU-COM-642', kind: 'Split comercial',
    client: 'Houston Logistics Park', location: 'Houston TX · Edif. C',
    status: 'operational', reading: '22.1°C',
    metrics: { reading: '22.1°C', setpoint: '22.0°C', capacity: '10 ton', refrigerant: 'R-410A' },
    events: [
      { time: '12:30', msg: 'Cambio de filtro programado · OK' },
      { time: '08:00', msg: 'Arranque automático · turno A' },
    ] },
  { id: 'u-431', name: 'Cámara congelación A1', sku: 'SKU-IND-431', kind: 'Cámara industrial',
    client: 'Distribuidora Norte', location: 'Dallas TX · Planta 1',
    status: 'fault', reading: '−10.2°C',
    metrics: { reading: '−10.2°C', setpoint: '−20.0°C', capacity: '45 ton', refrigerant: 'R-507A' },
    events: [
      { time: '14:11', msg: 'Falla crítica · sensor de baja presión activado' },
      { time: '14:09', msg: 'Caída de eficiencia detectada' },
    ] },
  { id: 'u-220', name: 'Split 5-ton — Showroom', sku: 'SKU-COM-220', kind: 'Split residencial-comercial',
    client: 'Auto Houston', location: 'Houston TX · Sala',
    status: 'operational', reading: '23.0°C',
    metrics: { reading: '23.0°C', setpoint: '23.0°C', capacity: '5 ton', refrigerant: 'R-410A' },
    events: [{ time: '07:45', msg: 'Arranque programado · turno A' }] },
  { id: 'u-118', name: 'Chiller 60-ton — Plant',  sku: 'SKU-IND-118', kind: 'Chiller agua',
    client: 'Procesadora Sur', location: 'San Antonio TX', status: 'offline', reading: '—',
    metrics: { reading: '—', setpoint: '4.5°C', capacity: '60 ton', refrigerant: 'R-134a' },
    events: [{ time: 'Ayer', msg: 'Apagado programado · mantenimiento mayor' }] },
];

function App() {
  const [activeSection, setActiveSection] = useStateApp('dashboard');
  const [selectedId,    setSelectedId]    = useStateApp(UNITS[0].id);
  const selected = UNITS.find(u => u.id === selectedId) || UNITS[0];

  return (
    <div className="ax-shell">
      <Sidebar active={activeSection} onSelect={setActiveSection} />
      <div className="ax-shell__main">
        <EquipmentList items={UNITS} selectedId={selectedId} onSelect={setSelectedId} />
        <div className="ax-shell__workspace">
          <DashboardArea unit={selected} />
          <ActionBar onSubmit={({ type, text }) => console.log('submit', type, text)} />
        </div>
      </div>
    </div>
  );
}

window.App = App;
