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/plus/pisellReservation/data/reservationDataUtils.ts
var reservationDataUtils_exports = {};
__export(reservationDataUtils_exports, {
  mergeGridBookingSearchParams: () => mergeGridBookingSearchParams,
  mergeSearchParamsBookingRange: () => mergeSearchParamsBookingRange,
  mergeSearchParamsBookingWindow: () => mergeSearchParamsBookingWindow,
  readBodyViewFromStorageKey: () => readBodyViewFromStorageKey,
  readPersistedReservationBodyView: () => readPersistedReservationBodyView,
  readReservationFloorMapAppearanceMode: () => readReservationFloorMapAppearanceMode,
  shouldUseBuiltinReservationList: () => shouldUseBuiltinReservationList,
  stripCalendarOnlyFlags: () => stripCalendarOnlyFlags,
  writeReservationFloorMapAppearanceMode: () => writeReservationFloorMapAppearanceMode
});
module.exports = __toCommonJS(reservationDataUtils_exports);
var import_dayjs = __toESM(require("dayjs"));
var import_reservationConstants = require("../reservationConstants");
var import_reservationConstants2 = require("../reservationConstants");
var import_usePisellReservationBookingData = require("../hooks/usePisellReservationBookingData");
function isSameBookingTimeWindow(a, b) {
  if (!Array.isArray(a) || !Array.isArray(b)) return false;
  if (a.length !== 2 || b.length !== 2) return false;
  try {
    for (let i = 0; i < 2; i++) {
      const av = (0, import_dayjs.default)(a[i]).valueOf();
      const bv = (0, import_dayjs.default)(b[i]).valueOf();
      if (!Number.isFinite(av) || !Number.isFinite(bv)) return false;
      if (av !== bv) return false;
    }
    return true;
  } catch {
    return false;
  }
}
function shouldUseBuiltinReservationList(dataProp, totalProp, paginationProp, onPageChangeProp) {
  if (dataProp == null) return true;
  return Array.isArray(dataProp) && dataProp.length === 0 && totalProp === void 0 && onPageChangeProp === void 0;
}
function mergeGridBookingSearchParams(params) {
  const p = params && typeof params === "object" ? { ...params } : {};
  const filterRaw = p.filter;
  const filter = typeof filterRaw === "object" && filterRaw !== null && !Array.isArray(filterRaw) ? { ...filterRaw } : {};
  const valuesRaw = filter.values;
  const values = typeof valuesRaw === "object" && valuesRaw !== null && !Array.isArray(valuesRaw) ? { ...valuesRaw } : {};
  if (!Array.isArray(values.order_payment_status) || values.order_payment_status.length === 0) {
    values.order_payment_status = void 0;
  }
  return {
    ...p,
    filter: {
      ...filter,
      values
    }
  };
}
function mergeSearchParamsBookingWindow(prev, anchorDay, operatingDayBoundary, timelineRange = import_reservationConstants2.RESERVATION_TIMELINE_BUSINESS_RANGE, wallClock = (0, import_dayjs.default)()) {
  const prevFilter = typeof prev.filter === "object" && prev.filter ? prev.filter : {};
  const prevValues = typeof prevFilter.values === "object" && prevFilter.values ? prevFilter.values : {};
  const nextWindow = (0, import_usePisellReservationBookingData.bookingTimeWindowForReservationView)(
    anchorDay,
    operatingDayBoundary,
    timelineRange,
    wallClock
  );
  if (isSameBookingTimeWindow(prevValues.booking_time_start_between, nextWindow)) {
    return prev;
  }
  return {
    ...prev,
    filter: {
      ...prevFilter,
      values: {
        ...prevValues,
        booking_time_start_between: nextWindow
      }
    }
  };
}
function stripCalendarOnlyFlags(prev) {
  const prevFilter = typeof prev.filter === "object" && prev.filter ? prev.filter : {};
  const prevValuesRaw = typeof prevFilter.values === "object" && prevFilter.values ? prevFilter.values : {};
  if (!("compact_fields" in prevValuesRaw) && !("enable_remote_memory_cache" in prevValuesRaw)) {
    return prev;
  }
  const nextValues = { ...prevValuesRaw };
  delete nextValues.compact_fields;
  delete nextValues.enable_remote_memory_cache;
  return {
    ...prev,
    filter: {
      ...prevFilter,
      values: nextValues
    }
  };
}
function mergeSearchParamsBookingRange(prev, rangeStart, rangeEnd, operatingDayBoundary) {
  const prevFilter = typeof prev.filter === "object" && prev.filter ? prev.filter : {};
  const prevValues = typeof prevFilter.values === "object" && prevFilter.values ? prevFilter.values : {};
  return {
    ...prev,
    filter: {
      ...prevFilter,
      values: {
        ...prevValues,
        booking_time_start_between: (0, import_usePisellReservationBookingData.bookingTimeWindowForCalendarRange)(
          rangeStart,
          rangeEnd,
          operatingDayBoundary
        )
      }
    }
  };
}
function readBodyViewFromStorageKey(key) {
  if (typeof window === "undefined" || !key) return "floorMap";
  try {
    const raw = localStorage.getItem(key);
    if (raw === "grid" || raw === "floorMap" || raw === "calendar" || raw === "resourceWall")
      return raw;
  } catch {
  }
  return "floorMap";
}
function readPersistedReservationBodyView() {
  return readBodyViewFromStorageKey(import_reservationConstants.PISELL_RESERVATION_BODY_VIEW_STORAGE_KEY);
}
function getFloorMapAppearanceStorageKey(floorPlanCode) {
  return `${import_reservationConstants.PISELL_RESERVATION_FLOOR_MAP_APPEARANCE_STORAGE_PREFIX}:${floorPlanCode || "default"}`;
}
function readReservationFloorMapAppearanceMode(floorPlanCode) {
  if (typeof window === "undefined") return "light";
  try {
    const raw = localStorage.getItem(
      getFloorMapAppearanceStorageKey(floorPlanCode)
    );
    if (raw === "dark" || raw === "light") return raw;
  } catch {
  }
  return "light";
}
function writeReservationFloorMapAppearanceMode(floorPlanCode, mode) {
  if (typeof window === "undefined") return;
  try {
    localStorage.setItem(getFloorMapAppearanceStorageKey(floorPlanCode), mode);
  } catch {
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  mergeGridBookingSearchParams,
  mergeSearchParamsBookingRange,
  mergeSearchParamsBookingWindow,
  readBodyViewFromStorageKey,
  readPersistedReservationBodyView,
  readReservationFloorMapAppearanceMode,
  shouldUseBuiltinReservationList,
  stripCalendarOnlyFlags,
  writeReservationFloorMapAppearanceMode
});
