import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { FLOOR_MAP_IMAGE_ELEMENT_KIND, FLOOR_MAP_STAGE_ELEMENT_KIND } from "../types.js";
import cloneDeep from "lodash/cloneDeep";
import isEqual from "lodash/isEqual";
//#region src/components/pisellFloorMapLayout/utils/floorMapViewConfigDiff.ts
/**
* 平面图 FloorMapViewConfig：与 props 同步时的规范化、以及草稿与持久化配置是否一致的比较
*/
/**
* 与 {@link useFloorMapEditState} 中 `useEffect` 逻辑一致：补全 `canvasUi`、空 `elementKinds` 时的默认调色板、`sceneElements`。
* 用于从上游 prop 得到「可与当前 draft 公平比较」的基准配置。
*/
function normalizeFloorMapViewConfigFromProp(floorMapConfigProp) {
	var _src$canCreate, _src$canEdit;
	const src = floorMapConfigProp;
	const base = src.canvasUi != null ? cloneDeep(src) : cloneDeep(_objectSpread2(_objectSpread2({}, src), {}, { canvasUi: {
		canCreate: (_src$canCreate = src.canCreate) !== null && _src$canCreate !== void 0 ? _src$canCreate : false,
		canEdit: (_src$canEdit = src.canEdit) !== null && _src$canEdit !== void 0 ? _src$canEdit : false
	} }));
	if (base.canvasUi.canCreate && (!base.elementKinds || base.elementKinds.length === 0)) {
		base.elementKindCategories = [{
			id: "furniture",
			label: "桌椅设施",
			order: 0
		}, {
			id: "decoration",
			label: "装饰与区域",
			order: 1
		}];
		base.elementKinds = [
			{
				value: "table",
				label: "方桌",
				categoryId: "furniture",
				dataBindingPolicy: "optional",
				allowedDataSourceKeys: ["sales"],
				showInPalette: true
			},
			{
				value: "marker",
				label: "标记",
				categoryId: "decoration",
				dataBindingPolicy: "none",
				showInPalette: true
			},
			{
				value: FLOOR_MAP_STAGE_ELEMENT_KIND,
				label: "舞台/区域",
				categoryId: "decoration",
				dataBindingPolicy: "none",
				showInPalette: true
			},
			{
				value: FLOOR_MAP_IMAGE_ELEMENT_KIND,
				label: "图片（底图）",
				categoryId: "decoration",
				dataBindingPolicy: "none",
				showInPalette: true
			},
			{
				value: "icon",
				label: "图标",
				categoryId: "decoration",
				dataBindingPolicy: "none",
				defaultShape: "circle",
				showInPalette: true
			}
		];
	}
	if (!base.sceneElements) base.sceneElements = [];
	return base;
}
function sortStableForCompare(config) {
	var _c$sceneElements, _c$elementKinds, _c$elementKindCategor, _c$edges;
	const c = cloneDeep(config);
	c.canvases = [...c.canvases].sort((a, b) => String(a.id).localeCompare(String(b.id)));
	c.sceneElements = [...(_c$sceneElements = c.sceneElements) !== null && _c$sceneElements !== void 0 ? _c$sceneElements : []].sort((a, b) => String(a.instanceId).localeCompare(String(b.instanceId)));
	if ((_c$elementKinds = c.elementKinds) === null || _c$elementKinds === void 0 ? void 0 : _c$elementKinds.length) c.elementKinds = [...c.elementKinds].sort((a, b) => String(a.value).localeCompare(String(b.value)));
	if ((_c$elementKindCategor = c.elementKindCategories) === null || _c$elementKindCategor === void 0 ? void 0 : _c$elementKindCategor.length) c.elementKindCategories = [...c.elementKindCategories].sort((a, b) => String(a.id).localeCompare(String(b.id)));
	if ((_c$edges = c.edges) === null || _c$edges === void 0 ? void 0 : _c$edges.length) c.edges = [...c.edges].sort((a, b) => String(a.id).localeCompare(String(b.id)));
	return c;
}
/** 判断当前编辑草稿是否与基准配置一致（数组顺序无关） */
function floorMapViewConfigsEqual(a, b) {
	return isEqual(sortStableForCompare(a), sortStableForCompare(b));
}
//#endregion
export { floorMapViewConfigsEqual, normalizeFloorMapViewConfigFromProp };
