/**
 * SET 58 — the new UI shell. 100% new software: composition + admin overlay
 * only. Aggregate numbers render exclusively inside the Admin overlay.
 */
import { useEffect, useState } from 'react';
import { AdminView } from '../AdminView';
import { Diagnostics } from './Diagnostics';
import { ErrorShield, installGlobalErrorHooks } from './ErrorShield';
import { RunPane } from './RunPane';
import { Sidebar } from './Sidebar';
import { startStore, stopStore } from './store';
import './shell.css';

export function Shell() {
  const [adminOpen, setAdminOpen] = useState(false);
  useEffect(() => {
    installGlobalErrorHooks();
    startStore();
    return () => stopStore();
  }, []);
  return (
    <ErrorShield>
      <div className="sh-root" data-rha-boot="shell">
        <Sidebar />
        <main className="sh-content">
          {adminOpen ? (
            <ErrorShield>
              <AdminView onClose={() => setAdminOpen(false)} />
            </ErrorShield>
          ) : (
            <ErrorShield>
              <RunPane />
            </ErrorShield>
          )}
          <div className="sh-foot">
            <button type="button" className="sh-linkbtn dim" onClick={() => setAdminOpen(v => !v)}>
              {adminOpen ? 'close admin' : 'admin'}
            </button>
            <Diagnostics />
          </div>
        </main>
      </div>
    </ErrorShield>
  );
}
