import { useEffect, useState, useCallback } from "react";
import { Outlet } from "react-router-dom";
import { TopBar } from "./TopBar";
import { LeftNav } from "./LeftNav";
import { StatusFooter } from "./StatusFooter";
import { RightInspector } from "./RightInspector";
import { ApiErrorBoundary } from "./ApiErrorBoundary";
import { EvidenceProvider, useEvidenceSubject } from "./evidenceContext";
import { EvidenceUrlSync } from "./evidenceUrlSync";
import { isAddressable, subjectToUrl } from "./evidenceAddress";
import { KeyboardHelp } from "./KeyboardHelp";
import { useGlobalKeyboard } from "./useGlobalKeyboard";
import { useCommandRegistry } from "./commandRegistry";
import { useWorkbenchPrefs } from "./workbenchPrefs";
import { SplitPane } from "../design/components/SplitPane/SplitPane";
function ShellInner() {
const { subject, inspectorOpen, toggleInspector, notifyAddressCopied } =
useEvidenceSubject();
const prefs = useWorkbenchPrefs();
const [helpOpen, setHelpOpen] = useState(false);
const [paletteOpen, setPaletteOpen] = useState(false);
const onTogglePalette = useCallback(() => {
setPaletteOpen((v) => !v);
}, []);
const onShowHelp = useCallback(() => {
setHelpOpen(true);
}, []);
const onCopyEvidenceLink = useCallback(() => {
if (!isAddressable(subject)) return;
if (!navigator.clipboard?.writeText) return;
const url = window.location.origin + subjectToUrl(subject);
navigator.clipboard.writeText(url).then(
() => notifyAddressCopied(),
(err) => console.error("Evidence link copy failed:", err),
);
}, [subject, notifyAddressCopied]);
useGlobalKeyboard({
onTogglePalette,
onToggleInspector: toggleInspector,
onShowHelp,
onCopyEvidenceLink,
});
// Action verbs in the palette (Wave R brief R0d): registered by the
// component that owns the behavior, unregistered on unmount.
const { register, unregister } = useCommandRegistry();
useEffect(() => {
register([
{
id: "action-toggle-inspector",
label: "Toggle inspector",
section: "Actions",
kind: "action",
shortcut: "\u2318I",
action: toggleInspector,
},
{
id: "action-copy-evidence-link",
label: "Copy evidence link",
section: "Actions",
kind: "action",
shortcut: "\u2318\u21E7C",
action: onCopyEvidenceLink,
},
]);
return () => unregister(["action-toggle-inspector", "action-copy-evidence-link"]);
}, [register, unregister, toggleInspector, onCopyEvidenceLink]);
const mainSurface = (