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/ScaleModal.tsx
var ScaleModal_exports = {};
__export(ScaleModal_exports, {
  DEFAULT_SECONDARY_DISPLAY_SETTINGS: () => DEFAULT_SECONDARY_DISPLAY_SETTINGS,
  SECONDARY_DISPLAY_DEFAULT_SCALE: () => SECONDARY_DISPLAY_DEFAULT_SCALE,
  SECONDARY_DISPLAY_MAX_SCALE: () => SECONDARY_DISPLAY_MAX_SCALE,
  SECONDARY_DISPLAY_MIN_SCALE: () => SECONDARY_DISPLAY_MIN_SCALE,
  SECONDARY_PRODUCTS_PER_ROW_MAX: () => SECONDARY_PRODUCTS_PER_ROW_MAX,
  SECONDARY_PRODUCTS_PER_ROW_MIN: () => SECONDARY_PRODUCTS_PER_ROW_MIN,
  SecondaryScreenSettingsModal: () => SecondaryScreenSettingsModal,
  getStoredSecondaryDisplayScale: () => getStoredSecondaryDisplayScale,
  getStoredSecondaryDisplaySettings: () => getStoredSecondaryDisplaySettings,
  hasPersistedSecondaryDisplaySettings: () => hasPersistedSecondaryDisplaySettings,
  normalizeSecondaryDisplaySettings: () => normalizeSecondaryDisplaySettings,
  persistSecondaryDisplayScale: () => persistSecondaryDisplayScale,
  persistSecondaryDisplaySettings: () => persistSecondaryDisplaySettings
});
module.exports = __toCommonJS(ScaleModal_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_utils = require("@pisell/utils");
var import_materials = require("@pisell/materials");
var SECONDARY_DISPLAY_DEFAULT_SCALE = 2.5;
var SECONDARY_DISPLAY_MIN_SCALE = 0.25;
var SECONDARY_DISPLAY_MAX_SCALE = 5;
var SECONDARY_PRODUCTS_PER_ROW_MIN = 1;
var SECONDARY_PRODUCTS_PER_ROW_MAX = 8;
var DEFAULT_SECONDARY_DISPLAY_SETTINGS = {
  scale: SECONDARY_DISPLAY_DEFAULT_SCALE,
  productsPerRow: 1,
  showCustomerInfo: true
};
var SECONDARY_DISPLAY_SETTINGS_STORAGE_KEY = "pisell-ticket-booking-secondary-display-settings";
var 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 < SECONDARY_DISPLAY_MIN_SCALE) return SECONDARY_DISPLAY_MIN_SCALE;
  if (scale > SECONDARY_DISPLAY_MAX_SCALE) return SECONDARY_DISPLAY_MAX_SCALE;
  return scale;
}
function clampProductsPerRow(n) {
  const v = Math.floor(Number(n));
  if (!Number.isFinite(v) || v < SECONDARY_PRODUCTS_PER_ROW_MIN) {
    return SECONDARY_PRODUCTS_PER_ROW_MIN;
  }
  return Math.min(v, SECONDARY_PRODUCTS_PER_ROW_MAX);
}
function normalizeSecondaryDisplaySettings(partial) {
  return {
    scale: clampScale(
      partial.scale ?? DEFAULT_SECONDARY_DISPLAY_SETTINGS.scale
    ),
    productsPerRow: clampProductsPerRow(
      partial.productsPerRow ?? DEFAULT_SECONDARY_DISPLAY_SETTINGS.productsPerRow
    ),
    showCustomerInfo: partial.showCustomerInfo !== false
  };
}
function hasPersistedSecondaryDisplaySettings() {
  try {
    if (typeof localStorage === "undefined") return false;
    return localStorage.getItem(SECONDARY_DISPLAY_SETTINGS_STORAGE_KEY) != null;
  } catch {
    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 < SECONDARY_DISPLAY_MIN_SCALE || n > SECONDARY_DISPLAY_MAX_SCALE) {
      return null;
    }
    return n;
  } catch {
    return null;
  }
}
function getStoredSecondaryDisplaySettings(propsFallback) {
  try {
    if (typeof localStorage === "undefined") {
      return normalizeSecondaryDisplaySettings({
        ...DEFAULT_SECONDARY_DISPLAY_SETTINGS,
        ...propsFallback
      });
    }
    if (hasPersistedSecondaryDisplaySettings()) {
      const raw = localStorage.getItem(
        SECONDARY_DISPLAY_SETTINGS_STORAGE_KEY
      );
      if (raw) {
        const parsed = JSON.parse(raw);
        return normalizeSecondaryDisplaySettings(parsed);
      }
    }
    const legacyScale = readLegacyScaleOnly();
    return normalizeSecondaryDisplaySettings({
      ...DEFAULT_SECONDARY_DISPLAY_SETTINGS,
      ...legacyScale != null ? { scale: legacyScale } : {},
      ...propsFallback
    });
  } catch {
    return normalizeSecondaryDisplaySettings({
      ...DEFAULT_SECONDARY_DISPLAY_SETTINGS,
      ...propsFallback
    });
  }
}
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 {
  }
}
function getStoredSecondaryDisplayScale() {
  return getStoredSecondaryDisplaySettings().scale;
}
function persistSecondaryDisplayScale(scale) {
  const cur = getStoredSecondaryDisplaySettings();
  persistSecondaryDisplaySettings({ ...cur, scale: clampScale(scale) });
}
var SecondaryScreenSettingsModal = (props) => {
  const { open, settings, onCancel, onConfirm } = props;
  const [draft, setDraft] = (0, import_react.useState)(settings);
  (0, import_react.useEffect)(() => {
    if (open) {
      setDraft(normalizeSecondaryDisplaySettings(settings));
    }
  }, [open, settings]);
  const handleOk = () => {
    onConfirm(normalizeSecondaryDisplaySettings(draft));
  };
  return /* @__PURE__ */ import_react.default.createElement(
    import_materials.PisellModal,
    {
      open,
      title: import_utils.locales.getText("pisell2.ticket-booking.secondary-settings-title"),
      onOk: handleOk,
      onCancel,
      okText: import_utils.locales.getText("pisell2.ticket-booking.secondary-settings-ok"),
      cancelText: import_utils.locales.getText(
        "pisell2.ticket-booking.secondary-settings-cancel"
      ),
      destroyOnClose: true,
      size: "small"
    },
    /* @__PURE__ */ import_react.default.createElement("div", { style: { marginBottom: 12 } }, /* @__PURE__ */ import_react.default.createElement("div", { style: { marginBottom: 8 } }, import_utils.locales.getText("pisell2.ticket-booking.secondary-settings-scale")), /* @__PURE__ */ import_react.default.createElement(
      import_antd.InputNumber,
      {
        style: { width: "100%" },
        min: SECONDARY_DISPLAY_MIN_SCALE,
        max: SECONDARY_DISPLAY_MAX_SCALE,
        step: 0.1,
        value: draft.scale,
        onChange: (v) => {
          if (v === null || v === void 0) return;
          setDraft((d) => ({ ...d, scale: v }));
        }
      }
    )),
    /* @__PURE__ */ import_react.default.createElement("div", { style: { marginBottom: 12 } }, /* @__PURE__ */ import_react.default.createElement("div", { style: { marginBottom: 8 } }, import_utils.locales.getText(
      "pisell2.ticket-booking.secondary-settings-products-per-row"
    )), /* @__PURE__ */ import_react.default.createElement(
      import_antd.InputNumber,
      {
        style: { width: "100%" },
        min: SECONDARY_PRODUCTS_PER_ROW_MIN,
        max: SECONDARY_PRODUCTS_PER_ROW_MAX,
        step: 1,
        precision: 0,
        value: draft.productsPerRow,
        onChange: (v) => {
          if (v === null || v === void 0) return;
          setDraft((d) => ({ ...d, productsPerRow: v }));
        }
      }
    )),
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        style: {
          display: "flex",
          alignItems: "center",
          justifyContent: "space-between",
          gap: 12
        }
      },
      /* @__PURE__ */ import_react.default.createElement("span", null, import_utils.locales.getText(
        "pisell2.ticket-booking.secondary-settings-show-customer"
      )),
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Switch,
        {
          checked: draft.showCustomerInfo,
          onChange: (checked) => setDraft((d) => ({ ...d, showCustomerInfo: checked }))
        }
      )
    )
  );
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DEFAULT_SECONDARY_DISPLAY_SETTINGS,
  SECONDARY_DISPLAY_DEFAULT_SCALE,
  SECONDARY_DISPLAY_MAX_SCALE,
  SECONDARY_DISPLAY_MIN_SCALE,
  SECONDARY_PRODUCTS_PER_ROW_MAX,
  SECONDARY_PRODUCTS_PER_ROW_MIN,
  SecondaryScreenSettingsModal,
  getStoredSecondaryDisplayScale,
  getStoredSecondaryDisplaySettings,
  hasPersistedSecondaryDisplaySettings,
  normalizeSecondaryDisplaySettings,
  persistSecondaryDisplayScale,
  persistSecondaryDisplaySettings
});
