const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_ScaleModal = require("./ScaleModal.js");
let react = require("react");
react = require_runtime.__toESM(react);
let ahooks = require("ahooks");
//#region src/components/ticketBooking/components/ticketBooking/useTicketBookingSecondaryScreen.tsx
const MAIN_CONTENT_TAP_WINDOW_MS = 800;
const MAIN_CONTENT_TAP_COUNT = 5;
/**
* 票务预约副屏：角色判断、主内容区 transform、连点打开设置弹窗、本地持久化展示配置。
*/
function useTicketBookingSecondaryScreen(runtime, displayConfig) {
	const isSecondaryScreen = (0, react.useMemo)(() => (runtime === null || runtime === void 0 ? void 0 : runtime.role) === "secondary-screen", [runtime]);
	const [secondaryDisplaySettings, setSecondaryDisplaySettings] = (0, react.useState)(() => (runtime === null || runtime === void 0 ? void 0 : runtime.role) === "secondary-screen" ? require_ScaleModal.getStoredSecondaryDisplaySettings(displayConfig) : require_ScaleModal.DEFAULT_SECONDARY_DISPLAY_SETTINGS);
	const [settingsModalOpen, setSettingsModalOpen] = (0, react.useState)(false);
	/**
	* 主屏：不读副屏 localStorage，固定默认配置并关闭设置弹窗。
	* 副屏：已持久化则只读存储；否则存储迁移 + props 兜底，且随 props 更新。
	*/
	(0, react.useEffect)(() => {
		if (!isSecondaryScreen) {
			setSecondaryDisplaySettings(require_ScaleModal.DEFAULT_SECONDARY_DISPLAY_SETTINGS);
			setSettingsModalOpen(false);
			return;
		}
		if (require_ScaleModal.hasPersistedSecondaryDisplaySettings()) {
			setSecondaryDisplaySettings(require_ScaleModal.getStoredSecondaryDisplaySettings());
			return;
		}
		setSecondaryDisplaySettings(require_ScaleModal.getStoredSecondaryDisplaySettings(displayConfig));
	}, [
		isSecondaryScreen,
		displayConfig === null || displayConfig === void 0 ? void 0 : displayConfig.productsPerRow,
		displayConfig === null || displayConfig === void 0 ? void 0 : displayConfig.showCustomerInfo
	]);
	const secondaryScaleTapRef = (0, react.useRef)({
		count: 0,
		resetTimer: null
	});
	(0, react.useEffect)(() => {
		return () => {
			const { resetTimer } = secondaryScaleTapRef.current;
			if (resetTimer) clearTimeout(resetTimer);
		};
	}, []);
	const secondaryProductsPerRow = (0, react.useMemo)(() => {
		if (!isSecondaryScreen) return 1;
		return secondaryDisplaySettings.productsPerRow;
	}, [isSecondaryScreen, secondaryDisplaySettings.productsPerRow]);
	const showSecondaryCustomerInfo = (0, react.useMemo)(() => {
		if (!isSecondaryScreen) return true;
		return secondaryDisplaySettings.showCustomerInfo;
	}, [isSecondaryScreen, secondaryDisplaySettings.showCustomerInfo]);
	const bookingInfoModules = (0, react.useMemo)(() => ({
		client: isSecondaryScreen && !showSecondaryCustomerInfo ? 0 : 1,
		date: 0,
		service: 1,
		holder: 1,
		note: 1
	}), [isSecondaryScreen, showSecondaryCustomerInfo]);
	const transformStyle = (0, react.useMemo)(() => {
		if (!isSecondaryScreen) return { width: 400 };
		const scale = secondaryDisplaySettings.scale;
		return {
			flex: ` 0 0 ${100 / scale}%`,
			height: `${100 / scale}%`,
			transform: `scale(${scale})`,
			transformOrigin: "top left"
		};
	}, [isSecondaryScreen, secondaryDisplaySettings.scale]);
	const handleMainContentClick = (0, ahooks.useMemoizedFn)(() => {
		if (!isSecondaryScreen) return;
		const box = secondaryScaleTapRef.current;
		if (box.resetTimer) {
			clearTimeout(box.resetTimer);
			box.resetTimer = null;
		}
		box.count += 1;
		if (box.count >= MAIN_CONTENT_TAP_COUNT) {
			box.count = 0;
			setSettingsModalOpen(true);
			return;
		}
		box.resetTimer = setTimeout(() => {
			box.count = 0;
			box.resetTimer = null;
		}, MAIN_CONTENT_TAP_WINDOW_MS);
	});
	const handleSettingsConfirm = (0, ahooks.useMemoizedFn)((next) => {
		if (!isSecondaryScreen) return;
		setSecondaryDisplaySettings(next);
		require_ScaleModal.persistSecondaryDisplaySettings(next);
		setSettingsModalOpen(false);
	});
	return {
		isSecondaryScreen,
		secondaryDisplaySettings,
		secondaryProductsPerRow,
		showSecondaryCustomerInfo,
		bookingInfoModules,
		mainContentWrapperProps: (0, react.useMemo)(() => ({
			id: "ticket-booking-main-content",
			className: "ticket-booking-main-content",
			style: require_objectSpread2._objectSpread2({ flexShrink: 0 }, transformStyle),
			onClick: handleMainContentClick
		}), [transformStyle, handleMainContentClick]),
		secondaryScreenSettingsModal: isSecondaryScreen ? /* @__PURE__ */ react.default.createElement(require_ScaleModal.SecondaryScreenSettingsModal, {
			open: settingsModalOpen,
			settings: secondaryDisplaySettings,
			onCancel: () => setSettingsModalOpen(false),
			onConfirm: handleSettingsConfirm
		}) : null
	};
}
//#endregion
exports.useTicketBookingSecondaryScreen = useTicketBookingSecondaryScreen;
