import "./chunks/SuperConverter-BBrzKfHe.es.js";
import "./chunks/jszip-C49i9kUs.es.js";
import "./chunks/xml-js-CqGKpaft.es.js";
import { t as createHeadlessToolbar } from "./chunks/create-headless-toolbar-CnOrqu6V.es.js";
import "./chunks/constants-DrU4EASo.es.js";
import "./chunks/dist-B8HfvhaK.es.js";
import "./chunks/unified-Dsuw2be5.es.js";
import { useCallback, useEffect, useRef, useState } from "react";
var EMPTY_SNAPSHOT = {
	context: null,
	commands: {}
};
function useHeadlessToolbar(superdoc, commands) {
	const [snapshot, setSnapshot] = useState(EMPTY_SNAPSHOT);
	const controllerRef = useRef(null);
	useEffect(() => {
		if (!superdoc) return;
		const controller = 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: useCallback((id, payload) => {
			return controllerRef.current?.execute(id, payload) ?? false;
		}, [])
	};
}
export { useHeadlessToolbar };
