function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
/**
 * 预约页与 RecordBoard 共用的纯函数：内置列表判定、筛参合并、按营业日改 booking 窗口、持久化 bodyView 读取。
 */

import { PISELL_RESERVATION_BODY_VIEW_STORAGE_KEY } from "../reservationConstants";
import { bookingTimeWindowForAnchorDay } from "../hooks/usePisellReservationBookingData";

/**
 * 是否使用内置预约/资源请求：
 * - 未传 `data` / `null`；
 * - 或低代码只绑了空数组作占位，且未同时受控 total / onPageChange。
 *   （仅有 pagination 占位而无 onPageChange 时仍走内置，否则会永不请求列表。）
 */
export function shouldUseBuiltinReservationList(dataProp, totalProp, paginationProp, onPageChangeProp) {
  if (dataProp == null) return true;
  return Array.isArray(dataProp) && dataProp.length === 0 && totalProp === undefined && onPageChangeProp === undefined;
}

/**
 * 表格筛选若未带支付态默认值，接口可能返回空；与 QuickFilter/高级筛选项合并时保留 monitor 默认。
 */
export function mergeGridBookingSearchParams(params) {
  var p = params && _typeof(params) === 'object' ? _objectSpread({}, params) : {};
  var filterRaw = p.filter;
  var filter = _typeof(filterRaw) === 'object' && filterRaw !== null && !Array.isArray(filterRaw) ? _objectSpread({}, filterRaw) : {};
  var valuesRaw = filter.values;
  var values = _typeof(valuesRaw) === 'object' && valuesRaw !== null && !Array.isArray(valuesRaw) ? _objectSpread({}, valuesRaw) : {};
  if (!Array.isArray(values.order_payment_status) || values.order_payment_status.length === 0) {
    values.order_payment_status = undefined;
  }
  return _objectSpread(_objectSpread({}, p), {}, {
    filter: _objectSpread(_objectSpread({}, filter), {}, {
      values: values
    })
  });
}

/** 列表请求：仅平面图模式用营业日锚定更新 booking_time_start_between */
export function mergeSearchParamsBookingWindow(prev, anchorDay) {
  var prevFilter = _typeof(prev.filter) === 'object' && prev.filter ? prev.filter : {};
  var prevValues = _typeof(prevFilter.values) === 'object' && prevFilter.values ? prevFilter.values : {};
  return _objectSpread(_objectSpread({}, prev), {}, {
    filter: _objectSpread(_objectSpread({}, prevFilter), {}, {
      values: _objectSpread(_objectSpread({}, prevValues), {}, {
        booking_time_start_between: bookingTimeWindowForAnchorDay(anchorDay)
      })
    })
  });
}

/**
 * 按任意 key 读取表格/平面图偏好（与 PisellRecordBoard 内 read 规则一致）。
 */
export function readBodyViewFromStorageKey(key) {
  if (typeof window === 'undefined' || !key) return 'floorMap';
  try {
    var raw = localStorage.getItem(key);
    if (raw === 'grid' || raw === 'floorMap') return raw;
  } catch (_unused) {
    /* quota / private mode */
  }
  return 'floorMap';
}

/**
 * 预约页默认持久化 key：有合法 localStorage 则用，否则平面图。
 */
export function readPersistedReservationBodyView() {
  return readBodyViewFromStorageKey(PISELL_RESERVATION_BODY_VIEW_STORAGE_KEY);
}