//#region src/components/pisellFloorMapLayout/utils/floorMapDropUtils.ts
/**
* 平面图编辑态：侧栏图元拖拽到画布的 DataTransfer 与坐标
*/
/** 与 setData 一致，用于识别左侧图元栏发起的拖拽 */
const FLOOR_MAP_PALETTE_DRAG_MIME = "application/x-pisell-floor-map-element";
/**
* 与 {@link useFloorMapEditState} 落点一致：内容区 drop 的 offset 减去内容区 padding 偏移
*/
function sceneXYFromContentDropOffset(offsetX, offsetY, contentOffset) {
	return {
		x: Math.round(offsetX - contentOffset.x),
		y: Math.round(offsetY - contentOffset.y)
	};
}
/** 是否为左侧图元栏拖拽（非本地文件 / 外链图片） */
function isFloorMapPaletteDrag(dt) {
	var _dt$types;
	if (!dt) return false;
	return Array.from((_dt$types = dt.types) !== null && _dt$types !== void 0 ? _dt$types : []).includes(FLOOR_MAP_PALETTE_DRAG_MIME);
}
/**
* 解析侧栏拖拽 payload；非法时返回 null
*/
function parsePaletteDragPayload(dt) {
	try {
		const raw = dt.getData(FLOOR_MAP_PALETTE_DRAG_MIME);
		if (!raw) return null;
		const o = JSON.parse(raw);
		if (!o || typeof o !== "object") return null;
		const rec = o;
		const elementKind = rec.elementKind;
		if (typeof elementKind !== "string" || !elementKind) return null;
		const dataSourceKey = typeof rec.dataSourceKey === "string" ? rec.dataSourceKey : void 0;
		const recordId = typeof rec.recordId === "string" ? rec.recordId : void 0;
		let recordIds;
		const rawIds = rec.recordIds;
		if (Array.isArray(rawIds)) {
			recordIds = rawIds.filter((x) => typeof x === "string" && x);
			if (recordIds.length === 0) recordIds = void 0;
		}
		const builtinShapeKey = typeof rec.builtinShapeKey === "string" && rec.builtinShapeKey ? rec.builtinShapeKey : void 0;
		return {
			elementKind,
			dataSourceKey,
			recordId,
			recordIds,
			builtinShapeKey
		};
	} catch (_unused) {
		return null;
	}
}
//#endregion
export { FLOOR_MAP_PALETTE_DRAG_MIME, isFloorMapPaletteDrag, parsePaletteDragPayload, sceneXYFromContentDropOffset };
