const require_rolldown_runtime = require("./rolldown-runtime-C34Jxks9.cjs");
const require_create_headless_toolbar = require("./create-headless-toolbar-BUr9TmNG.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;
		}, [])
	};
}
Object.defineProperty(exports, "useHeadlessToolbar", {
	enumerable: true,
	get: function() {
		return useHeadlessToolbar;
	}
});
