import { computed, ref } from "vue";
import { defineStore } from "pinia";
//#region src/stores/presetBuilderStore.ts
var idCounter = 0;
function nextId(prefix) {
	idCounter += 1;
	return `${prefix}-${Date.now()}-${idCounter}`;
}
/** Test helper to make ids deterministic. */
function __resetPresetBuilderIdCounter() {
	idCounter = 0;
}
function emptyState(builderId) {
	return {
		presetName: "",
		presetDescription: "",
		innerBuilderId: `${builderId}::inner`
	};
}
var usePresetBuilderStore = defineStore("gx-modui/presetBuilder", () => {
	const builders = ref({});
	function ensureBuilder(builderId) {
		if (!builders.value[builderId]) builders.value[builderId] = emptyState(builderId);
		return builders.value[builderId];
	}
	function getState(builderId) {
		return ensureBuilder(builderId);
	}
	function setName(builderId, name) {
		const state = ensureBuilder(builderId);
		state.presetName = name;
	}
	function setDescription(builderId, description) {
		const state = ensureBuilder(builderId);
		state.presetDescription = description;
	}
	function resetBuilder(builderId) {
		delete builders.value[builderId];
	}
	/**
	* Used internally by the composable to seed name + description from
	* a `PresetBuilderSchema`. Inner schema seeding is handled by the
	* composition directly because the inner FormBuilder store has its
	* own `loadSchema` entrypoint.
	*/
	function loadMeta(builderId, meta) {
		const state = ensureBuilder(builderId);
		state.presetName = meta.presetName ?? "";
		state.presetDescription = meta.presetDescription ?? "";
	}
	return {
		builders,
		ensureBuilder,
		getState,
		setName,
		setDescription,
		resetBuilder,
		loadMeta
	};
});
/** Composable wrapper around `usePresetBuilderStore` for one builder. */
function usePresetBuilder(builderId) {
	const store = usePresetBuilderStore();
	store.ensureBuilder(builderId);
	if (!builderId) nextId("preset");
	return {
		state: computed(() => store.getState(builderId)),
		setName: (name) => store.setName(builderId, name),
		setDescription: (description) => store.setDescription(builderId, description),
		loadMeta: (meta) => store.loadMeta(builderId, meta),
		reset: () => store.resetBuilder(builderId)
	};
}
//#endregion
export { usePresetBuilder as n, usePresetBuilderStore as r, __resetPresetBuilderIdCounter as t };

//# sourceMappingURL=presetBuilderStore-BfY6aqur.js.map