/* BasedMTA — root module
   Exports window.BasedMTA, a React component that can be mounted
   anywhere on a host site. Self-contained: it only depends on
   styles.css being loaded and the panels having been registered
   on window (which the script order guarantees).
*/

const { useState: useStateApp, useEffect: useEffectApp } = React;

const TABS = [
{ id: "log", label: "Log" },
{ id: "exec", label: "Exec" },
{ id: "visuals", label: "Visuals" },
{ id: "aimbot", label: "Aimbot" },
{ id: "local", label: "Local" },
{ id: "scripts", label: "Scripts (378)" },
{ id: "resources", label: "Resources" },
{ id: "events", label: "Events (1462)" },
{ id: "dump", label: "Dump" },
{ id: "spoof", label: "Spoof" },
{ id: "bots", label: "Bots" },
{ id: "exploits", label: "Exploits" }];


function BasedMTA({
  initialTab = "log",
  serverIp = "172.202.89.86:22005",
  onClose,
  hideClose = true
}) {
  const [tab, setTab] = useStateApp(initialTab);
  const [fps, setFps] = useStateApp(71);

  // simulate fluctuating fps for life
  useEffectApp(() => {
    const id = setInterval(() => {
      setFps((f) => {
        const delta = Math.floor(Math.random() * 7) - 3;
        return Math.max(38, Math.min(120, f + delta));
      });
    }, 800);
    return () => clearInterval(id);
  }, []);

  const Panel = (() => {
    switch (tab) {
      case "log":return window.LogPanel;
      case "exec":return window.ExecPanel;
      case "visuals":return window.VisualsPanel;
      case "aimbot":return window.AimbotPanel;
      case "local":return window.LocalPanel;
      case "scripts":return window.ScriptsPanel;
      case "resources":return window.ResourcesPanel;
      case "events":return window.EventsPanel;
      case "dump":return window.DumpPanel;
      case "spoof":return window.SpoofPanel;
      case "bots":return window.BotsPanel;
      case "exploits":return window.ExploitsPanel;
      default:return null;
    }
  })();

  return (
    <div className="bmta">
      <div className="bmta-window">
        <div className="bmta-titlebar" style={{ borderColor: "rgb(26, 56, 92)" }}>
          <span className="bmta-titlebar-title" style={{ color: "rgb(217, 227, 242)" }}>BasedMTA v1.6</span>
          {!hideClose &&
          <span className="bmta-titlebar-close" onClick={onClose}>×</span>
          }
        </div>
        <div className="bmta-statusline">
          <span className="plus">[+]</span>
          <span>{serverIp}</span>
          <span className="sep">|</span>
          <span>{fps} fps</span>
        </div>
        <BmtaTabs tabs={TABS} active={tab} onSelect={setTab} />
        <div className="bmta-body">
          {Panel ? <Panel /> : <BmtaEmpty>Unknown panel: {tab}</BmtaEmpty>}
        </div>
      </div>
    </div>);

}

// Expose to host
window.BasedMTA = BasedMTA;
window.BasedMTA_TABS = TABS;
