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/booking/info/utils.ts
var utils_exports = {};
__export(utils_exports, {
  editSessionProduct: () => editSessionProduct,
  formatServiceListByTime: () => formatServiceListByTime,
  getIsBundleOrCombination: () => getIsBundleOrCombination,
  getMultiDayPrices: () => getMultiDayPrices,
  isBooking4Shop: () => isBooking4Shop,
  isDayBooking: () => isDayBooking,
  isInterval: () => isInterval,
  isOpenAddTime: () => isOpenAddTime,
  isShowAddTime: () => isShowAddTime,
  moveItemToFront: () => moveItemToFront,
  uniqueByField: () => uniqueByField
});
module.exports = __toCommonJS(utils_exports);
var import_dayjs = __toESM(require("dayjs"));
var import_utils = require("../utils");
var import_utils2 = require("../info2/service/addTimeModal/utils");
var import_utils3 = require("../info2/service/addService/utils");
var getIsBundleOrCombination = (productDetail) => {
  var _a;
  if ((_a = productDetail == null ? void 0 : productDetail.bundle_group) == null ? void 0 : _a.length) {
    return true;
  }
  return false;
};
var uniqueByField = (arr, field) => {
  const seen = /* @__PURE__ */ new Set();
  return arr.filter((item) => {
    const fieldValue = item[field];
    if (seen.has(fieldValue)) {
      return false;
    } else {
      seen.add(fieldValue);
      return true;
    }
  });
};
var moveItemToFront = (arr, targetId) => {
  const index = arr.findIndex((item) => item.id === targetId);
  if (index !== -1) {
    const targetItem = arr[index];
    arr.splice(index, 1);
    arr.unshift(targetItem);
  }
  return arr;
};
var isInterval = (time1, time2, interval = 1e3) => {
  if (time2 === time1) {
    return false;
  }
  return Math.abs(time2 - time1) < interval;
};
var formatServiceListByTime = (list) => {
  var _a, _b;
  try {
    let _list = [...list];
    const length = _list.length;
    if (length > 1) {
      let start = (_a = _list[length - 2]) == null ? void 0 : _a._time;
      let end = (_b = _list[length - 1]) == null ? void 0 : _b._time;
      if (start && end && isInterval(start, end)) {
        _list.pop();
        return _list;
      } else {
        return list;
      }
    } else {
      return list;
    }
  } catch (err) {
    return list;
  }
};
var isBooking4Shop = (shopId, renderType, businessUtils) => {
  if (renderType === "eventBooking") {
    return false;
  }
  const booking4Shops = [
    8390,
    1350,
    1401,
    3013,
    7154,
    7572,
    7007,
    8119,
    7320,
    7362,
    6497,
    6087,
    6303,
    6726,
    8191,
    6812,
    6813,
    6814,
    7651,
    8586,
    8581,
    9,
    2155,
    8030,
    1749,
    8194,
    2327,
    8609,
    8610,
    8782,
    1285,
    6124,
    8727,
    5538,
    6988,
    8872,
    6930,
    8824,
    8913,
    8918,
    6413,
    8943
  ];
  return booking4Shops.includes(shopId) || (businessUtils == null ? void 0 : businessUtils.getAppByModal("resourcekit"));
};
function generateDateRange(start, end) {
  const dateRange = [];
  let currentDate = (0, import_dayjs.default)(start);
  while (currentDate.isBefore((0, import_dayjs.default)(end).add(1, "day"))) {
    dateRange.push(currentDate.format("YYYY-MM-DD"));
    currentDate = currentDate.add(1, "day");
  }
  return dateRange;
}
var getMultiDayPrices = (data) => {
  const result = {};
  data.forEach((entry) => {
    const dateRange = generateDateRange(entry.start_date, entry.end_date);
    dateRange.forEach((date) => {
      result[date] = entry;
    });
  });
  return result;
};
var isDayBooking = (shopId) => {
  const dayBookingShops = [9];
  return dayBookingShops.includes(shopId);
};
var getAddTimeProducts = (state, currentService) => {
  return (state.addTimeProducts || []).some(
    (item) => (0, import_utils2.isUsableProduct)(item.add_time, currentService)
  );
};
var isOpenAddTime = (state) => {
  var _a, _b, _c;
  const appointment_card = ((_c = (_b = (_a = state == null ? void 0 : state.bookingConfig) == null ? void 0 : _a.config) == null ? void 0 : _b.information_tab) == null ? void 0 : _c.appointment_card) || {
    quick_time: 1
  };
  if ((state == null ? void 0 : state.renderType) === "eventBooking") {
    return false;
  }
  if (state == null ? void 0 : state.disabledEdit) {
    return false;
  }
  if (appointment_card.quick_time !== 1) {
    return false;
  }
  return true;
};
var isShowAddTime = (state, currentService) => {
  if ((0, import_utils3.isMultiDayProduct)(currentService)) {
    return false;
  }
  if (!isOpenAddTime(state)) {
    return false;
  }
  if ((0, import_utils.getIsEdit)(state)) {
    return false;
  }
  if (!getAddTimeProducts(state, currentService)) {
    return false;
  }
  return true;
};
var editSessionProduct = (cacheItem, session) => {
  if ((0, import_utils.isSessionProduct)(cacheItem) && session) {
    cacheItem._extend.start_date = session.start_at;
    cacheItem._extend.startDate = session.start_at;
    cacheItem._extend.start_time = session.start_time;
    cacheItem._extend.end_time = session.end_time;
    cacheItem._extend.end_date = session.end_at;
    cacheItem._extend.endDate = session.end_at;
    cacheItem._extend.duration = (0, import_utils.getDays)({ _extend: cacheItem._extend }, "minutes");
    return {
      duration: cacheItem._extend.duration,
      start_time: session.start_time
    };
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  editSessionProduct,
  formatServiceListByTime,
  getIsBundleOrCombination,
  getMultiDayPrices,
  isBooking4Shop,
  isDayBooking,
  isInterval,
  isOpenAddTime,
  isShowAddTime,
  moveItemToFront,
  uniqueByField
});
