import { parseJsonPointerPath } from "../helpers/json/json-pointer-path.js";
import { ensureJsonPointerLinkSupport } from "../helpers/json/json-pointer-links.js";
import { onScopeDispose, toValue, watch } from "vue";
//#region src/v2/features/editor/hooks/use-json-pointer-link-support.ts
var JSON_LANGUAGE_ID = "json";
/**
* Enables clickable JSON Pointer links when the editor model is JSON.
* Relates link support to the current model and uses the provided editor API to navigate.
*
* Call this hook with the return value of useEditor (or a ref to it) and the same model
* passed to useEditor. When the model's language is JSON, links like "#/paths/..." in
* string values become clickable and trigger focusPath on the editor.
*/
var useJsonPointerLinkSupport = (editorApi, model) => {
	let disposeLinkSupport = null;
	const setupOrDispose = () => {
		const api = toValue(editorApi);
		const currentModel = toValue(model);
		if (disposeLinkSupport) {
			disposeLinkSupport();
			disposeLinkSupport = null;
		}
		if (!api?.focusPath || !currentModel) return;
		if (currentModel.model.getLanguageId() !== JSON_LANGUAGE_ID) return;
		const navigate = async (pointer) => {
			const path = parseJsonPointerPath(pointer);
			if (!path) return;
			await api.focusPath(path.map(String));
		};
		disposeLinkSupport = ensureJsonPointerLinkSupport(navigate).dispose;
	};
	watch(() => [toValue(editorApi), toValue(model)], () => {
		setupOrDispose();
	}, { immediate: true });
	onScopeDispose(() => {
		if (disposeLinkSupport) {
			disposeLinkSupport();
			disposeLinkSupport = null;
		}
	});
};
//#endregion
export { useJsonPointerLinkSupport };

//# sourceMappingURL=use-json-pointer-link-support.js.map