import { t as createHeadlessToolbar } from "./create-headless-toolbar-BeX8jwVX.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 as t };
