function parseHash() {
const h = (location.hash || "").replace(/^#\/?/, "");
const m = h.match(/^case\/(\d+)/);
if (m) return { view: "case", id: Number(m[1]) };
return { view: "hub" };
}
const DEFAULT_FILTERS = { q: "", system: null, cocom: null, level: null, acuity: null };
function App() {
const [route, setRoute] = useState(parseHash());
const [filters, setFiltersState] = useState(() => {
try { return { ...DEFAULT_FILTERS, ...(JSON.parse(localStorage.getItem("guidon.filters")) || {}) }; }
catch (e) { return DEFAULT_FILTERS; }
});
const setFilters = (f) => { setFiltersState(f); try { localStorage.setItem("guidon.filters", JSON.stringify(f)); } catch (e) {} };
useEffect(() => {
const on = () => { setRoute(parseHash()); window.scrollTo({ top: 0 }); };
window.addEventListener("hashchange", on);
return () => window.removeEventListener("hashchange", on);
}, []);
const go = (hash) => { location.hash = hash; };
const open = (id) => go("/case/" + id);
const home = () => go("/");
const liveCount = window.GUIDON_INDEX.filter(s => window.isLive(s.id)).length;
const liveSystems = window.GUIDON_TAX.SYSTEMS.filter(sys =>
window.GUIDON_INDEX.filter(s => s.system === sys.key).every(s => window.isLive(s.id))
).length;
return (
<div id="app">
<header className="topbar">
<div className="brand" onClick={home}>
<span className="brand-mark"><span>G</span></span>
<span>
<span className="brand-name">GUIDON</span>
<span className="brand-sub">Austere Medicine Trainer</span>
</span>
</div>
{route.view === "case" && (
<button className="crumb" onClick={home}>
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="M15 18l-6-6 6-6" /></svg>
Library
</button>
)}
<span className="spacer" />
<div className="topbar-meta">
<span><span className="dot">●</span> {liveCount}/{window.GUIDON_INDEX.length} BUILT</span>
<span><b>{liveSystems}</b> MODULES LIVE</span>
</div>
</header>
{route.view === "case"
? <CaseView id={route.id} onBack={home} />
: <Hub filters={filters} setFilters={setFilters} onOpen={open} />}
</div>
);
}
ReactDOM.createRoot(document.getElementById("root")).render(<App />);