Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const require_rolldown_runtime = require("./chunks/rolldown-runtime-C34Jxks9.cjs");
require("./chunks/SuperConverter-BFs3Wrk0.cjs");
require("./chunks/jszip-4KbV_vHe.cjs");
require("./chunks/xml-js-B2J5tNmr.cjs");
const require_create_headless_toolbar = require("./chunks/create-headless-toolbar-BC6RwkXA.cjs");
require("./chunks/constants-DDSbERiY.cjs");
require("./chunks/dist-kRpWoWUg.cjs");
require("./chunks/unified-DgEQofGI.cjs");
let react = require("react");
var EMPTY_SNAPSHOT = {
	context: null,
	commands: {}
};
function useHeadlessToolbar(superdoc, commands) {
	const [snapshot, setSnapshot] = (0, react.useState)(EMPTY_SNAPSHOT);
	const controllerRef = (0, react.useRef)(null);
	(0, react.useEffect)(() => {
		if (!superdoc) return;
		const controller = require_create_headless_toolbar.createHeadlessToolbar({
			superdoc,
			commands
		});
		controllerRef.current = controller;
		setSnapshot(controller.getSnapshot());
		const unsub = controller.subscribe(({ snapshot: s }) => setSnapshot(s));
		return () => {
			unsub();
			controller.destroy();
			controllerRef.current = null;
		};
	}, [superdoc]);
	return {
		snapshot,
		execute: (0, react.useCallback)((id, payload) => {
			return controllerRef.current?.execute(id, payload) ?? false;
		}, [])
	};
}
exports.useHeadlessToolbar = useHeadlessToolbar;
