import { computed, ref } from "vue";
import { defineStore } from "pinia";
//#region src/stores/reactiveCanvasBuilderStore.ts
/** Built-in block types exposed by the palette in the MVP. */
var REACTIVE_CANVAS_BLOCK_TYPES = [
	"text-block",
	"image-block",
	"button-block",
	"spacer-block",
	"container-block"
];
var DEFAULT_CANVAS_WIDTH = 800;
var DEFAULT_CANVAS_HEIGHT = 600;
var DEFAULT_BLOCK_WIDTH = 160;
var DEFAULT_BLOCK_HEIGHT = 80;
var idCounter = 0;
function nextId(prefix) {
	idCounter += 1;
	return `${prefix}-${Date.now()}-${idCounter}`;
}
/** Test helper to make ids deterministic. */
function __resetReactiveCanvasBuilderIdCounter() {
	idCounter = 0;
}
function emptySchema() {
	return {
		width: DEFAULT_CANVAS_WIDTH,
		height: DEFAULT_CANVAS_HEIGHT,
		blocks: []
	};
}
function defaultPropsForType(type) {
	switch (type) {
		case "text-block": return { text: "Sample text" };
		case "image-block": return {
			src: "",
			alt: ""
		};
		case "button-block": return {
			label: "Click me",
			action: ""
		};
		case "spacer-block": return {};
		case "container-block": return { padding: 8 };
		default: return {};
	}
}
var useReactiveCanvasBuilderStore = defineStore("gx-modui/reactiveCanvasBuilder", () => {
	const builders = ref({});
	const selections = ref({});
	function ensureBuilder(builderId) {
		if (!builders.value[builderId]) {
			builders.value[builderId] = emptySchema();
			selections.value[builderId] = { id: null };
		}
		return builders.value[builderId];
	}
	function loadSchema(builderId, schema) {
		builders.value[builderId] = {
			width: schema.width,
			height: schema.height,
			blocks: schema.blocks.map((b) => ({
				...b,
				props: { ...b.props }
			}))
		};
		selections.value[builderId] = { id: null };
	}
	function resetBuilder(builderId) {
		delete builders.value[builderId];
		delete selections.value[builderId];
	}
	/** Append a new block of `type` and return its id. */
	function addBlock(builderId, type) {
		const schema = ensureBuilder(builderId);
		const id = nextId(`block-${type}`);
		schema.blocks = [...schema.blocks, {
			id,
			type,
			x: 16,
			y: 16,
			width: DEFAULT_BLOCK_WIDTH,
			height: DEFAULT_BLOCK_HEIGHT,
			props: defaultPropsForType(type)
		}];
		return id;
	}
	function removeBlock(builderId, blockId) {
		const schema = ensureBuilder(builderId);
		schema.blocks = schema.blocks.filter((b) => b.id !== blockId);
		if (selections.value[builderId]?.id === blockId) selections.value[builderId] = { id: null };
	}
	function updateBlock(builderId, blockId, patch) {
		const schema = ensureBuilder(builderId);
		const idx = schema.blocks.findIndex((b) => b.id === blockId);
		if (idx < 0) return;
		const current = schema.blocks[idx];
		const list = [...schema.blocks];
		list[idx] = {
			...current,
			...patch
		};
		schema.blocks = list;
	}
	function setCanvasSize(builderId, patch) {
		const schema = ensureBuilder(builderId);
		if (patch.width !== void 0) schema.width = patch.width;
		if (patch.height !== void 0) schema.height = patch.height;
	}
	function select(builderId, id) {
		selections.value[builderId] = { id };
	}
	function getSelection(builderId) {
		return selections.value[builderId] ?? { id: null };
	}
	function getSchema(builderId) {
		return ensureBuilder(builderId);
	}
	return {
		builders,
		selections,
		ensureBuilder,
		loadSchema,
		resetBuilder,
		addBlock,
		removeBlock,
		updateBlock,
		setCanvasSize,
		select,
		getSelection,
		getSchema
	};
});
/** Composable wrapper around `useReactiveCanvasBuilderStore`. */
function useReactiveCanvasBuilder(builderId) {
	const store = useReactiveCanvasBuilderStore();
	store.ensureBuilder(builderId);
	return {
		schema: computed(() => store.getSchema(builderId)),
		selection: computed(() => store.getSelection(builderId)),
		addBlock: (type) => store.addBlock(builderId, type),
		removeBlock: (id) => store.removeBlock(builderId, id),
		updateBlock: (id, patch) => store.updateBlock(builderId, id, patch),
		setCanvasSize: (patch) => store.setCanvasSize(builderId, patch),
		select: (id) => store.select(builderId, id),
		loadSchema: (schema) => store.loadSchema(builderId, schema),
		reset: () => store.resetBuilder(builderId)
	};
}
//#endregion
export { useReactiveCanvasBuilderStore as i, __resetReactiveCanvasBuilderIdCounter as n, useReactiveCanvasBuilder as r, REACTIVE_CANVAS_BLOCK_TYPES as t };

//# sourceMappingURL=reactiveCanvasBuilderStore-wPcgR7hD.js.map