const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
//#region src/components/ticketBooking/components/ticketBooking/ScaleModal.tsx
/** 副屏内容缩放系数：与 transform 中 scale 含义一致 */
const SECONDARY_DISPLAY_DEFAULT_SCALE = 2.5;
const SECONDARY_DISPLAY_MIN_SCALE = .25;
const DEFAULT_SECONDARY_DISPLAY_SETTINGS = {
	scale: SECONDARY_DISPLAY_DEFAULT_SCALE,
	productsPerRow: 1,
	showCustomerInfo: true
};
const SECONDARY_DISPLAY_SETTINGS_STORAGE_KEY = "pisell-ticket-booking-secondary-display-settings";
/** 历史仅缩放键，读取后迁移到新 JSON 并可在首次保存时删除 */
const SECONDARY_DISPLAY_SCALE_STORAGE_KEY_LEGACY = "pisell-ticket-booking-secondary-display-scale";
function clampScale(scale) {
	if (!Number.isFinite(scale)) return SECONDARY_DISPLAY_DEFAULT_SCALE;
	if (scale < .25) return SECONDARY_DISPLAY_MIN_SCALE;
	if (scale > 5) return 5;
	return scale;
}
function clampProductsPerRow(n) {
	const v = Math.floor(Number(n));
	if (!Number.isFinite(v) || v < 1) return 1;
	return Math.min(v, 8);
}
/** 将任意部分字段归一化为完整配置 */
function normalizeSecondaryDisplaySettings(partial) {
	var _partial$scale, _partial$productsPerR;
	return {
		scale: clampScale((_partial$scale = partial.scale) !== null && _partial$scale !== void 0 ? _partial$scale : DEFAULT_SECONDARY_DISPLAY_SETTINGS.scale),
		productsPerRow: clampProductsPerRow((_partial$productsPerR = partial.productsPerRow) !== null && _partial$productsPerR !== void 0 ? _partial$productsPerR : DEFAULT_SECONDARY_DISPLAY_SETTINGS.productsPerRow),
		showCustomerInfo: partial.showCustomerInfo !== false
	};
}
/** 是否已保存过完整 JSON（保存后低代码 props 不再覆盖列数/客户信息） */
function hasPersistedSecondaryDisplaySettings() {
	try {
		if (typeof localStorage === "undefined") return false;
		return localStorage.getItem(SECONDARY_DISPLAY_SETTINGS_STORAGE_KEY) != null;
	} catch (_unused) {
		return false;
	}
}
function readLegacyScaleOnly() {
	try {
		if (typeof localStorage === "undefined") return null;
		const raw = localStorage.getItem(SECONDARY_DISPLAY_SCALE_STORAGE_KEY_LEGACY);
		if (raw == null) return null;
		const n = parseFloat(raw);
		if (Number.isNaN(n) || n < .25 || n > 5) return null;
		return n;
	} catch (_unused2) {
		return null;
	}
}
/**
* 读取副屏展示配置（仅应在副屏场景调用；主屏不应依赖此结果驱动 UI）。
* - 若已存在新 JSON 键：仅使用本地存储（低代码 props 不覆盖）。
* - 否则：默认 + 旧 scale 迁移 + propsFallback（每行商品数、客户信息）合并。
*/
function getStoredSecondaryDisplaySettings(propsFallback) {
	try {
		if (typeof localStorage === "undefined") return normalizeSecondaryDisplaySettings(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, DEFAULT_SECONDARY_DISPLAY_SETTINGS), propsFallback));
		if (hasPersistedSecondaryDisplaySettings()) {
			const raw = localStorage.getItem(SECONDARY_DISPLAY_SETTINGS_STORAGE_KEY);
			if (raw) return normalizeSecondaryDisplaySettings(JSON.parse(raw));
		}
		const legacyScale = readLegacyScaleOnly();
		return normalizeSecondaryDisplaySettings(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, DEFAULT_SECONDARY_DISPLAY_SETTINGS), legacyScale != null ? { scale: legacyScale } : {}), propsFallback));
	} catch (_unused3) {
		return normalizeSecondaryDisplaySettings(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, DEFAULT_SECONDARY_DISPLAY_SETTINGS), propsFallback));
	}
}
/** 持久化完整配置；写入后删除旧 scale 单键，避免双源 */
function persistSecondaryDisplaySettings(settings) {
	const next = normalizeSecondaryDisplaySettings(settings);
	try {
		if (typeof localStorage !== "undefined") {
			localStorage.setItem(SECONDARY_DISPLAY_SETTINGS_STORAGE_KEY, JSON.stringify(next));
			localStorage.removeItem(SECONDARY_DISPLAY_SCALE_STORAGE_KEY_LEGACY);
		}
	} catch (_unused4) {}
}
/**
* 副屏设置弹窗：缩放、购物车每行商品数、是否显示客户信息；确认后由外层持久化。
*/
const SecondaryScreenSettingsModal = (props) => {
	const { open, settings, onCancel, onConfirm } = props;
	const [draft, setDraft] = (0, react.useState)(settings);
	(0, react.useEffect)(() => {
		if (open) setDraft(normalizeSecondaryDisplaySettings(settings));
	}, [open, settings]);
	const handleOk = () => {
		onConfirm(normalizeSecondaryDisplaySettings(draft));
	};
	return /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellModal, {
		open,
		title: _pisell_utils.locales.getText("pisell2.ticket-booking.secondary-settings-title"),
		onOk: handleOk,
		onCancel,
		okText: _pisell_utils.locales.getText("pisell2.ticket-booking.secondary-settings-ok"),
		cancelText: _pisell_utils.locales.getText("pisell2.ticket-booking.secondary-settings-cancel"),
		destroyOnClose: true,
		size: "small"
	}, /* @__PURE__ */ react.default.createElement("div", { style: { marginBottom: 12 } }, /* @__PURE__ */ react.default.createElement("div", { style: { marginBottom: 8 } }, _pisell_utils.locales.getText("pisell2.ticket-booking.secondary-settings-scale")), /* @__PURE__ */ react.default.createElement(antd.InputNumber, {
		style: { width: "100%" },
		min: SECONDARY_DISPLAY_MIN_SCALE,
		max: 5,
		step: .1,
		value: draft.scale,
		onChange: (v) => {
			if (v === null || v === void 0) return;
			setDraft((d) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, d), {}, { scale: v }));
		}
	})), /* @__PURE__ */ react.default.createElement("div", { style: { marginBottom: 12 } }, /* @__PURE__ */ react.default.createElement("div", { style: { marginBottom: 8 } }, _pisell_utils.locales.getText("pisell2.ticket-booking.secondary-settings-products-per-row")), /* @__PURE__ */ react.default.createElement(antd.InputNumber, {
		style: { width: "100%" },
		min: 1,
		max: 8,
		step: 1,
		precision: 0,
		value: draft.productsPerRow,
		onChange: (v) => {
			if (v === null || v === void 0) return;
			setDraft((d) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, d), {}, { productsPerRow: v }));
		}
	})), /* @__PURE__ */ react.default.createElement("div", { style: {
		display: "flex",
		alignItems: "center",
		justifyContent: "space-between",
		gap: 12
	} }, /* @__PURE__ */ react.default.createElement("span", null, _pisell_utils.locales.getText("pisell2.ticket-booking.secondary-settings-show-customer")), /* @__PURE__ */ react.default.createElement(antd.Switch, {
		checked: draft.showCustomerInfo,
		onChange: (checked) => setDraft((d) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, d), {}, { showCustomerInfo: checked }))
	})));
};
//#endregion
exports.DEFAULT_SECONDARY_DISPLAY_SETTINGS = DEFAULT_SECONDARY_DISPLAY_SETTINGS;
exports.SecondaryScreenSettingsModal = SecondaryScreenSettingsModal;
exports.getStoredSecondaryDisplaySettings = getStoredSecondaryDisplaySettings;
exports.hasPersistedSecondaryDisplaySettings = hasPersistedSecondaryDisplaySettings;
exports.persistSecondaryDisplaySettings = persistSecondaryDisplaySettings;
