var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/ticketBooking/components/ticketBooking/useTicketBookingSecondaryScreen.tsx
var useTicketBookingSecondaryScreen_exports = {};
__export(useTicketBookingSecondaryScreen_exports, {
  useTicketBookingSecondaryScreen: () => useTicketBookingSecondaryScreen
});
module.exports = __toCommonJS(useTicketBookingSecondaryScreen_exports);
var import_react = __toESM(require("react"));
var import_ahooks = require("ahooks");
var import_ScaleModal = require("./ScaleModal");
var MAIN_CONTENT_TAP_WINDOW_MS = 800;
var MAIN_CONTENT_TAP_COUNT = 5;
function useTicketBookingSecondaryScreen(runtime, displayConfig) {
  const isSecondaryScreen = (0, import_react.useMemo)(
    () => (runtime == null ? void 0 : runtime.role) === "secondary-screen",
    [runtime]
  );
  const [secondaryDisplaySettings, setSecondaryDisplaySettings] = (0, import_react.useState)(
    () => (runtime == null ? void 0 : runtime.role) === "secondary-screen" ? (0, import_ScaleModal.getStoredSecondaryDisplaySettings)(displayConfig) : import_ScaleModal.DEFAULT_SECONDARY_DISPLAY_SETTINGS
  );
  const [settingsModalOpen, setSettingsModalOpen] = (0, import_react.useState)(false);
  (0, import_react.useEffect)(() => {
    if (!isSecondaryScreen) {
      setSecondaryDisplaySettings(import_ScaleModal.DEFAULT_SECONDARY_DISPLAY_SETTINGS);
      setSettingsModalOpen(false);
      return;
    }
    if ((0, import_ScaleModal.hasPersistedSecondaryDisplaySettings)()) {
      setSecondaryDisplaySettings((0, import_ScaleModal.getStoredSecondaryDisplaySettings)());
      return;
    }
    setSecondaryDisplaySettings(
      (0, import_ScaleModal.getStoredSecondaryDisplaySettings)(displayConfig)
    );
  }, [
    isSecondaryScreen,
    displayConfig == null ? void 0 : displayConfig.productsPerRow,
    displayConfig == null ? void 0 : displayConfig.showCustomerInfo
  ]);
  const secondaryScaleTapRef = (0, import_react.useRef)({ count: 0, resetTimer: null });
  (0, import_react.useEffect)(() => {
    return () => {
      const { resetTimer } = secondaryScaleTapRef.current;
      if (resetTimer) clearTimeout(resetTimer);
    };
  }, []);
  const secondaryProductsPerRow = (0, import_react.useMemo)(() => {
    if (!isSecondaryScreen) return 1;
    return secondaryDisplaySettings.productsPerRow;
  }, [isSecondaryScreen, secondaryDisplaySettings.productsPerRow]);
  const showSecondaryCustomerInfo = (0, import_react.useMemo)(() => {
    if (!isSecondaryScreen) return true;
    return secondaryDisplaySettings.showCustomerInfo;
  }, [isSecondaryScreen, secondaryDisplaySettings.showCustomerInfo]);
  const bookingInfoModules = (0, import_react.useMemo)(
    () => ({
      client: isSecondaryScreen && !showSecondaryCustomerInfo ? 0 : 1,
      date: 0,
      service: 1,
      holder: 1,
      note: 1
    }),
    [isSecondaryScreen, showSecondaryCustomerInfo]
  );
  const transformStyle = (0, import_react.useMemo)(() => {
    if (!isSecondaryScreen) {
      return { width: 400 };
    }
    const scale = secondaryDisplaySettings.scale;
    return {
      width: `${100 / scale}%`,
      height: `${100 / scale}%`,
      transform: `scale(${scale})`,
      transformOrigin: "top left"
    };
  }, [isSecondaryScreen, secondaryDisplaySettings.scale]);
  const handleMainContentClick = (0, import_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, import_ahooks.useMemoizedFn)(
    (next) => {
      if (!isSecondaryScreen) return;
      setSecondaryDisplaySettings(next);
      (0, import_ScaleModal.persistSecondaryDisplaySettings)(next);
      setSettingsModalOpen(false);
    }
  );
  const mainContentWrapperProps = (0, import_react.useMemo)(
    () => ({
      id: "ticket-booking-main-content",
      className: "ticket-booking-main-content",
      style: {
        flexShrink: 0,
        ...transformStyle
      },
      onClick: handleMainContentClick
    }),
    [transformStyle, handleMainContentClick]
  );
  const secondaryScreenSettingsModal = isSecondaryScreen ? /* @__PURE__ */ import_react.default.createElement(
    import_ScaleModal.SecondaryScreenSettingsModal,
    {
      open: settingsModalOpen,
      settings: secondaryDisplaySettings,
      onCancel: () => setSettingsModalOpen(false),
      onConfirm: handleSettingsConfirm
    }
  ) : null;
  return {
    isSecondaryScreen,
    secondaryDisplaySettings,
    secondaryProductsPerRow,
    showSecondaryCustomerInfo,
    bookingInfoModules,
    mainContentWrapperProps,
    secondaryScreenSettingsModal
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useTicketBookingSecondaryScreen
});
