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/utils.ts
var utils_exports = {};
__export(utils_exports, {
  deleteCacheParams: () => deleteCacheParams,
  findNextDuration: () => findNextDuration,
  findNextSlice: () => findNextSlice,
  flexibleObj: () => flexibleObj,
  formatProductListByCategory: () => formatProductListByCategory,
  formatResource: () => formatResource,
  formatTimes: () => formatTimes,
  getCacheParams: () => getCacheParams,
  getDays: () => getDays,
  getDiscountTime: () => getDiscountTime,
  getDiscountTimeByDayMinutes: () => getDiscountTimeByDayMinutes,
  getDuration: () => getDuration,
  getEndDate: () => getEndDate,
  getErrorList: () => getErrorList,
  getIsEdit: () => getIsEdit,
  getIsEject: () => getIsEject,
  getIsOnlySession: () => getIsOnlySession,
  getLastServer: () => getLastServer,
  getMainPrice: () => getMainPrice,
  getNowTime: () => getNowTime,
  getProductTotalPrice: () => getProductTotalPrice,
  getResourceTimeIsUsable: () => getResourceTimeIsUsable,
  getServeStartTime: () => getServeStartTime,
  getServerItemExtend: () => getServerItemExtend,
  getServiceTime: () => getServiceTime,
  getServiceTimes: () => getServiceTimes,
  getShopOpeningHours: () => getShopOpeningHours,
  isNowTime: () => isNowTime,
  isSessionProduct: () => isSessionProduct,
  isWalkIn: () => isWalkIn,
  memoize: () => memoize,
  request: () => request,
  sliceDayIntoFiveMinutes: () => sliceDayIntoFiveMinutes
});
module.exports = __toCommonJS(utils_exports);
var import_dayjs = __toESM(require("dayjs"));
var import_utils = require("@pisell/utils");
var import_utils2 = require("./info/service2/utils");
var import_lodash = require("lodash");
var import_utilsByBooking = require("./info2/utilsByBooking");
var import_decimal = __toESM(require("decimal.js"));
var import_utils3 = require("./info2/service/addService/utils");
function memoize(fn) {
  const cache = /* @__PURE__ */ new Map();
  return function(...args) {
    const key = JSON.stringify(args);
    if (cache.has(key)) {
      return cache.get(key);
    }
    const result = fn.apply(this, args);
    cache.set(key, result);
    return result;
  };
}
var Request = class {
  request = {};
  constructor() {
  }
  setRequest(val) {
    this.request = val;
  }
  getRequest() {
    return this.request;
  }
};
var request = new Request();
var getDiscountTime = (service_times, isDay) => {
  if (!service_times || service_times < 0) {
    return "";
  }
  if (isDay) {
    return `${service_times} ${import_utils.locales.getText("pisell2.text.day")(service_times)}`;
  }
  if (service_times < 60) {
    return `${service_times} ${import_utils.locales.getText("pisell2.text.min")}`;
  } else {
    let str = "";
    const hours = Math.floor(service_times / 60);
    const minutes = service_times % 60;
    str += `${hours}${import_utils.locales.getText("pisell2.text.h")}`;
    if (minutes > 0) {
      str += ` ${minutes}${import_utils.locales.getText("pisell2.text.min")}`;
    }
    return str;
  }
};
var getDiscountTimeByDayMinutes = (days, minutes) => {
  if (days === 0) {
    return getDiscountTime(minutes);
  }
  return `${days} ${import_utils.locales.getText("pisell2.text.day")(days)} ${getDiscountTime(minutes)}`;
};
var _sliceDayIntoFiveMinutes = (config, locale, isDay) => {
  let _locale = locale;
  let dayjsLocale = _locale === "en-US" || _locale === "en" ? "en" : "zh-cn";
  import_dayjs.default.locale(dayjsLocale);
  const startTime = (0, import_dayjs.default)().startOf("day");
  const endTime = (0, import_dayjs.default)().endOf("day");
  const timeSlice = (config == null ? void 0 : config.value) || 5;
  let timeSlices = [];
  let durationSlicesBasedOnTime = [];
  let currentTime = startTime;
  if (isDay) {
    let currentDay = 1;
    while (currentDay <= 30) {
      const timeLabel = currentTime.format("hh:mm A");
      const timeValue = currentTime.format("HH:mm");
      timeSlices.push({ label: timeLabel, value: timeValue });
      durationSlicesBasedOnTime.push({
        label: `${currentDay} ${import_utils.locales.getText("pisell2.text.day")(currentDay)}`,
        value: currentDay
      });
      currentDay++;
    }
    return { timeSlices, durationSlicesBasedOnTime };
  }
  while (currentTime.isBefore(endTime)) {
    const timeLabel = currentTime.format("hh:mm A");
    const timeValue = currentTime.format("HH:mm");
    timeSlices.push({ label: timeLabel, value: timeValue });
    const nextTime = currentTime.add(timeSlice, "minute");
    const durationValue = nextTime.diff(startTime, "minute");
    if (durationValue > 60) {
      const durationLabel = getDiscountTime(durationValue);
      durationSlicesBasedOnTime.push({
        label: durationLabel,
        value: durationValue
      });
    } else {
      const durationLabel = `${durationValue} ${import_utils.locales.getText(
        "pisell2.text.min"
      )}`;
      durationSlicesBasedOnTime.push({
        label: durationLabel,
        value: durationValue
      });
    }
    currentTime = nextTime;
  }
  return { timeSlices, durationSlicesBasedOnTime };
};
var sliceDayIntoFiveMinutes = memoize(_sliceDayIntoFiveMinutes);
var getNowTime = () => {
  return (0, import_dayjs.default)().format("HH:mm");
};
var isNowTime = (time) => {
  return time === "now";
};
var getServeStartTime = (start_time) => {
  if (isNowTime(start_time)) {
    return getNowTime();
  }
  return start_time;
};
var getServiceTime = (item, currentDate) => {
  const startDate = (0, import_dayjs.default)(
    currentDate.format("YYYY-MM-DD") + " " + getServeStartTime(item._extend.start_time)
  );
  const startTime = startDate.format("HH:mm");
  const endTime = startDate.add(flexibleObj.getValue(item._extend.duration), "minute").format("HH:mm");
  const duration = getDiscountTime(flexibleObj.getValue(item._extend.duration));
  return `${startTime} - ${endTime} ( ${duration} )`;
};
var findNextSlice = ({
  timeSlices = [],
  index = 0,
  date = ""
}) => {
  const currentTimeValue = date || (0, import_dayjs.default)().format("HH:mm");
  for (let i = 0; i < timeSlices.length; i++) {
    if (timeSlices[i].value !== "now") {
      if (timeSlices[i].value >= currentTimeValue) {
        return timeSlices[i].value;
      }
    }
  }
  return timeSlices[index].value;
};
var findNextDuration = (current, array, defaultValue) => {
  if (defaultValue) {
    return defaultValue;
  }
  for (let i = 0; i < array.length; i++) {
    if (array[i].value == (current == null ? void 0 : current.value)) {
      return array[i].value;
    }
  }
  return array[0].value;
};
var formatProductListByCategory = (list, filterItem) => {
  let _list = list || [];
  if (filterItem) {
    _list = _list.filter(filterItem);
  }
  let categoryObject = {};
  for (let i = 0; i < _list.length; i++) {
    const productItem = _list[i];
    if ((productItem.category || []).length) {
      for (let j = 0; j < productItem.category.length; j++) {
        let categoryItem = productItem.category[j];
        if (!categoryObject[categoryItem.id]) {
          categoryObject[categoryItem.id] = {
            ...categoryItem,
            products: []
          };
        }
        categoryObject[categoryItem.id] = {
          ...categoryItem,
          products: [...categoryObject[categoryItem.id].products, productItem]
        };
      }
    } else {
      if (!categoryObject["other"]) {
        categoryObject["other"] = {
          id: 0,
          title: import_utils.locales.getText("pisell2.text.other"),
          name: import_utils.locales.getText("pisell2.text.other"),
          cover: "",
          products: []
        };
      }
      categoryObject["other"] = {
        ...categoryObject["other"],
        products: [...categoryObject["other"].products, productItem]
      };
    }
  }
  return Object.values(categoryObject).sort((a, b) => b.sort - a.sort);
};
var getResourceTimeIsUsable = (item, cacheItem) => {
  var _a;
  const isEdit = !!cacheItem.booking_id;
  const isCurrentRelation = item.item_id === ((_a = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _a.relation_id);
  const startDate = (0, import_dayjs.default)(
    cacheItem._extend.start_date.format("YYYY-MM-DD") + " " + getServeStartTime(cacheItem._extend.start_time)
  );
  const isFlexible = flexibleObj.isFlexible(cacheItem._extend.duration);
  let isMaxLimitRange = false;
  let isDateRange = false;
  let time = { ...item };
  if (time.max_participants_limit == 0) {
    isMaxLimitRange = true;
  } else {
    const orderEventCount = isEdit && isCurrentRelation ? time.order_event_count - 1 : time.order_event_count;
    isMaxLimitRange = orderEventCount < time.max_participants_limit;
  }
  const timeStartDate = (0, import_dayjs.default)(time.start_date + " " + time.start_time).subtract(
    1,
    "second"
  );
  const timeEndDate = (0, import_dayjs.default)(time.end_date + " " + time.end_time).add(
    1,
    "second"
  );
  let bol;
  if (isFlexible) {
    bol = startDate.isAfter(timeStartDate) && startDate.isBefore(timeEndDate);
  } else {
    let endDate = startDate.add(
      flexibleObj.getValue(cacheItem._extend.duration),
      "minute"
    );
    bol = startDate.isAfter(timeStartDate) && endDate.isBefore(timeEndDate);
  }
  if (bol) {
    isDateRange = true;
  }
  const isUsable = isDateRange;
  time._extend = {
    isMaxLimitRange,
    isDateRange,
    isUsable
  };
  return time;
};
var formatTimes = (resourceItem, cacheItem) => {
  var _a;
  if (((_a = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _a.sub_type) === "days") {
    const isResourceItem = (resourceItem == null ? void 0 : resourceItem.form_record_id) > 0;
    let isMaxLimitRange = (resourceItem == null ? void 0 : resourceItem.sold_out) === 1;
    let isDateRange = (resourceItem == null ? void 0 : resourceItem.available_status) === 1;
    const isUsable = isDateRange && !isMaxLimitRange;
    const usableTime = {
      isMaxLimitRange,
      isDateRange,
      isUsable: isResourceItem ? isUsable : true
    };
    resourceItem._extend = {
      ...resourceItem._extend,
      usableTime
    };
    return resourceItem;
  }
  let usableTimes = [];
  let _resourceItem = { ...resourceItem };
  _resourceItem.times = _resourceItem.times.map((time) => {
    let _time2 = getResourceTimeIsUsable(time, cacheItem);
    if (_time2 == null ? void 0 : _time2._extend.isUsable) {
      usableTimes.push(_time2);
    }
    return _time2;
  });
  let _time = (usableTimes || []).sort((a, b) => {
    const aEndDate = (0, import_dayjs.default)(a.end_date + " " + a.end_time).valueOf();
    const bEndDate = (0, import_dayjs.default)(b.end_date + " " + b.end_time).valueOf();
    return aEndDate - bEndDate;
  })[0];
  resourceItem._extend = {
    ...resourceItem._extend,
    usableTime: _time
  };
  return resourceItem;
};
var formatResourceProducts = (resourceItem, currentItem) => {
  var _a;
  let usableProduct = false;
  let _resourceItem = { ...resourceItem };
  const type = _resourceItem.partyroom_package.type;
  if (type === "product_all") {
    usableProduct = true;
  } else {
    if (type === "product_collection") {
      usableProduct = !!(0, import_lodash.intersectionBy)(
        ((_a = _resourceItem.partyroom_package) == null ? void 0 : _a.products.map((item) => ({
          ...item,
          id: item.product_collection_id
        }))) || [],
        currentItem.collection || [],
        "id"
      ).length;
    } else {
      usableProduct = _resourceItem.partyroom_package.products.some(
        (item) => {
          if (type === "products") {
            if (item.product_id == currentItem.product_id) {
              return true;
            }
          }
        }
      );
    }
  }
  resourceItem._extend = {
    ...resourceItem._extend,
    // 是否可用
    usableProduct
  };
  return resourceItem;
};
var getShopOpeningHours = () => {
  return localStorage.getItem("shopOpeningHours") || "23:59";
};
var flexibleObj = {
  // 创建, 增加前缀
  create: (num) => {
    return `flexible_${num}`;
  },
  // 格式化, 去除前缀
  getValue: (str) => {
    if (typeof str === "string" && flexibleObj.isFlexible(str)) {
      return Number(str.replace("flexible_", ""));
    }
    return str;
  },
  // 判断当前时长是否为灵活时长
  isFlexible: (str) => {
    if (typeof str !== "string") {
      return false;
    }
    return str.indexOf("flexible_") > -1;
  },
  add: (current, duration) => {
    if (flexibleObj.isFlexible(current)) {
      return flexibleObj.create(
        flexibleObj.getValue(current) + duration
      );
    } else {
      return Number(current) + duration;
    }
  }
};
var getEndDate = (startDate, duration, endDate) => {
  if (duration === "flexible") {
    let openingDate = (0, import_dayjs.default)(
      startDate.format("YYYY-MM-DD") + " " + getShopOpeningHours()
    );
    if ((0, import_dayjs.default)(startDate).isAfter(openingDate)) {
      openingDate = openingDate.add(1, "day");
    }
    if (!endDate) {
      return openingDate;
    }
    endDate = (0, import_dayjs.default)(endDate);
    if (endDate.isAfter(openingDate)) {
      return openingDate;
    }
    return endDate;
  }
  return startDate.add(duration, "minute");
};
var getServiceTimes = (service) => {
  var _a, _b;
  const startDate = (0, import_dayjs.default)(
    (0, import_dayjs.default)(service._extend.start_date).format("YYYY-MM-DD ") + getServeStartTime(service._extend.start_time)
  );
  if ((0, import_utils3.isMultiDayProduct)(service)) {
    return {
      startDate,
      endDate: service._extend.end_date
    };
  }
  const endDate = startDate.add(
    flexibleObj.getValue(service._extend.duration),
    "minute"
  );
  const session = (_b = (_a = service == null ? void 0 : service._extend) == null ? void 0 : _a.other) == null ? void 0 : _b.session;
  if (isSessionProduct(service) && session) {
    return {
      startDate: (0, import_dayjs.default)(session.start_at),
      endDate: (0, import_dayjs.default)(session.end_at)
    };
  }
  return {
    startDate,
    endDate
  };
};
var getErrorList = (resource, cacheItem, isDay) => {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
  if (!(cacheItem == null ? void 0 : cacheItem.id)) {
    return [
      {
        label: import_utils.locales.getText("pisell2.text.no-product-added"),
        type: "products"
      }
    ];
  }
  if (!resource || !resource._extend || !cacheItem) {
    return [];
  }
  let list = [];
  if (!resource.usable) {
    if (!((_a = resource == null ? void 0 : resource._extend) == null ? void 0 : _a.usableProduct)) {
      list.push({
        label: import_utils.locales.getText("pisell1.text.resource-error-message-1")(
          resource.labelText,
          cacheItem == null ? void 0 : cacheItem.title
        ),
        type: "product"
      });
    }
    let startText = "";
    let endText = "";
    if (isDay) {
      const { start_date, end_date } = cacheItem == null ? void 0 : cacheItem._extend;
      startText = start_date == null ? void 0 : start_date.format("YYYY-MM-DD");
      endText = end_date ? end_date == null ? void 0 : end_date.format("YYYY-MM-DD") : "";
    } else {
      const { startDate, endDate } = getServiceTimes(cacheItem);
      startText = startDate.format("hh:mm A");
      endText = endDate.format("hh:mm A");
      if ((0, import_dayjs.default)(endDate).isAfter(startDate, "day")) {
        endText = import_utils.locales.getText("pisell1.text.tomorrow") + endText;
      }
    }
    if (isDay ? !((_c = (_b = resource._extend) == null ? void 0 : _b.usableTime) == null ? void 0 : _c.isDateRange) : !((_d = resource._extend) == null ? void 0 : _d.usableTime)) {
      list.push({
        label: import_utils.locales.getText("pisell1.text.resource-error-message-2")(
          resource.labelText,
          startText,
          endText
        ),
        type: "time"
      });
    } else {
      if (isDay ? (_f = (_e = resource._extend) == null ? void 0 : _e.usableTime) == null ? void 0 : _f.isMaxLimitRange : !((_i = (_h = (_g = resource._extend) == null ? void 0 : _g.usableTime) == null ? void 0 : _h._extend) == null ? void 0 : _i.isMaxLimitRange)) {
        list.push({
          label: import_utils.locales.getText("pisell1.text.resource-error-message-3")(
            resource.labelText,
            startText,
            endText
          ),
          type: "limit"
        });
      }
    }
  }
  return list;
};
var formatResource = (resourceItem, cacheItem, formatLabel) => {
  var _a, _b, _c, _d, _e;
  let _resourceItem = { ...resourceItem };
  _resourceItem = formatTimes(_resourceItem, cacheItem);
  _resourceItem = formatResourceProducts(_resourceItem, cacheItem);
  _resourceItem.labelText = _resourceItem.room_name || _resourceItem.name;
  let usable = _resourceItem._extend.usableTime && ((_a = _resourceItem._extend.usableTime._extend) == null ? void 0 : _a.isMaxLimitRange) && _resourceItem._extend.usableProduct;
  if (((_b = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _b.sub_type) === "days") {
    usable = ((_d = (_c = _resourceItem._extend) == null ? void 0 : _c.usableTime) == null ? void 0 : _d.isUsable) && ((_e = _resourceItem._extend) == null ? void 0 : _e.usableProduct);
  }
  _resourceItem.usable = usable;
  if (formatLabel) {
    _resourceItem.label = formatLabel(_resourceItem);
  }
  return _resourceItem;
};
var getLastServer = (list) => {
  return list == null ? void 0 : list[0];
};
var getCacheParams = () => {
  const sessionData = sessionStorage.getItem("pisell2.booking.serviceParams");
  const data = sessionData ? JSON.parse(sessionData) : null;
  return data == null ? void 0 : data.serviceParams;
};
var deleteCacheParams = () => {
  sessionStorage.removeItem("pisell2.booking.serviceParams");
};
var getDays = (cacheItem, type) => {
  var _a, _b;
  if (type === "days") {
    const { start_date, end_date } = (0, import_utils2.formatDayDate)(cacheItem._extend);
    return end_date.diff(start_date, "day");
  }
  let startDate = (0, import_dayjs.default)((_a = cacheItem._extend) == null ? void 0 : _a.start_date);
  let endDate = (0, import_dayjs.default)((_b = cacheItem._extend) == null ? void 0 : _b.end_date);
  return endDate.diff(startDate, type);
};
var isSessionProduct = (cacheItem) => {
  return ["session_product", "session_ticket"].includes(cacheItem.extension_type);
};
var getIsEject = (item, type) => {
  const isSession = isSessionProduct(item);
  const isSoldByWeight = item.open_sold_weight;
  return type === "detail" || item.bundle_group_count > 0 || item.option_group_count > 0 || item.is_variant > 0 || isSession || isSoldByWeight;
};
var getIsOnlySession = (item) => {
  const isSession = isSessionProduct(item);
  return !(item.bundle_group_count > 0 || item.option_group_count > 0 || item.is_variant > 0) && isSession;
};
var getServerItemExtend = (state, cacheItem, timeObj) => {
  if (!cacheItem.new && cacheItem._extend.endDate) {
    return cacheItem._extend;
  }
  const appointmentTimingPreference = (0, import_utilsByBooking.getAppointmentTimingPreference)(state);
  const isSession = isSessionProduct(cacheItem);
  const isDay = (0, import_utils2.isDayBooking)(state);
  const setDuration = () => {
    var _a;
    if (isDay) {
      return getDays(cacheItem, "days");
    }
    if (isSession) {
      return getDays(cacheItem, "minutes");
    }
    return findNextDuration(
      cacheItem.duration,
      timeObj == null ? void 0 : timeObj.durationSlicesBasedOnTime,
      (_a = cacheItem == null ? void 0 : cacheItem.duration) == null ? void 0 : _a.value
    );
  };
  let lastServer = isDay ? false : getLastServer(state.service.value);
  let _extend = {
    duration: setDuration()
  };
  if (lastServer) {
    _extend.resource = lastServer._extend.resource;
    let lastServerStartDate = lastServer._extend.startDate;
    let lastServerEndDate = lastServer._extend.endDate;
    if (appointmentTimingPreference === "parallel") {
      _extend.start_time = lastServerStartDate.format("HH:mm");
    } else {
      if ((0, import_dayjs.default)(lastServerEndDate).isAfter(lastServerStartDate, "day")) {
        _extend.start_time = timeObj == null ? void 0 : timeObj.timeSlices[(timeObj == null ? void 0 : timeObj.timeSlices.length) - 1].value;
      } else {
        _extend.start_time = lastServerEndDate.format("HH:mm");
      }
    }
  } else {
    let findNextSliceProps = {
      timeSlices: timeObj == null ? void 0 : timeObj.timeSlices,
      index: 0,
      date: ""
    };
    const serviceParams = getCacheParams();
    if (serviceParams) {
      let str = serviceParams.start_date;
      if (str) {
        findNextSliceProps.date = (0, import_dayjs.default)(str).format("HH:mm");
      }
      let resourceId = Number(serviceParams.resource_id);
      if (resourceId || resourceId === 0) {
        _extend.resource = resourceId;
      }
    }
    if (findNextSliceProps.date && findNextSliceProps.date !== "00:00") {
      _extend.start_time = findNextSlice(findNextSliceProps);
    } else {
      if (cacheItem.currentDefaultTime) {
        _extend.start_time = cacheItem.currentDefaultTime;
      } else {
        _extend.start_time = (0, import_dayjs.default)().format("HH:mm");
      }
    }
  }
  _extend = {
    ..._extend,
    ...cacheItem._extend
  };
  if (isDay) {
    _extend.end_date = (0, import_dayjs.default)(_extend.start_date).add(_extend.duration, "day");
    const { start_date, end_date } = (0, import_utils2.formatDayDate)(_extend);
    _extend = { ..._extend, start_date, startDate: start_date, end_date, endDate: end_date };
  }
  return _extend;
};
var getMainPrice = (item, price) => {
  var _a;
  let newPrice = new import_decimal.default(price || item._extend.price || 0);
  let other = (_a = item._extend) == null ? void 0 : _a.other;
  if (other == null ? void 0 : other.product_variant_id) {
    newPrice = new import_decimal.default((other == null ? void 0 : other.price) || 0);
  }
  return newPrice.toNumber();
};
var getProductTotalPrice = (item, options) => {
  var _a, _b, _c, _d, _e;
  let price = new import_decimal.default(item._extend.price || 0);
  let other = (_a = item._extend) == null ? void 0 : _a.other;
  const weighing = (_b = item == null ? void 0 : item._extend) == null ? void 0 : _b.weighing;
  if (((_c = item._extend) == null ? void 0 : _c.priceOverride) || ((_d = item._extend) == null ? void 0 : _d.priceOverride) === 0) {
    price = new import_decimal.default(((_e = item._extend) == null ? void 0 : _e.priceOverride) || 0);
  } else {
    if ((other == null ? void 0 : other.product_variant_id) && !(options == null ? void 0 : options.isUseExtendPrice)) {
      price = new import_decimal.default((other == null ? void 0 : other.price) || 0);
    }
    if (weighing) {
      price = new import_decimal.default((weighing == null ? void 0 : weighing.total_amount) || 0);
    }
    if (other == null ? void 0 : other.bundle) {
      price = other == null ? void 0 : other.bundle.reduce((accumulator, currentValue) => {
        const currentPrice = new import_decimal.default(currentValue.price || 0);
        const currentNum = new import_decimal.default(currentValue.num || 0);
        return accumulator.add(currentPrice.mul(currentNum));
      }, price);
    }
    if (other == null ? void 0 : other.option) {
      price = other == null ? void 0 : other.option.reduce((accumulator, currentValue) => {
        const currentPrice = new import_decimal.default(currentValue.price || 0);
        const currentNum = new import_decimal.default(currentValue.num || 0);
        return accumulator.add(currentPrice.mul(currentNum));
      }, price);
    }
  }
  return price.toNumber();
};
var getDuration = (duration) => {
  if (typeof duration === "number") {
    return duration;
  }
  if (typeof duration === "object") {
    if (duration.type === "minutes") {
      return duration.value;
    }
    if (duration.type === "flexible") {
      return "flexible";
    }
  }
  return duration;
};
var isWalkIn = (customer_id) => {
  if (customer_id === void 0) {
    return true;
  }
  if (typeof customer_id === "string") {
    return ["", "0", "1"].includes(customer_id);
  }
  return [0, 1].includes(customer_id);
};
var getIsEdit = (state) => {
  var _a, _b, _c, _d, _e, _f, _g;
  if ((_a = state.addons) == null ? void 0 : _a.edit) {
    return true;
  }
  if (!state.bookingId) {
    return true;
  }
  if ((_b = state.client) == null ? void 0 : _b.edit) {
    return true;
  }
  if ((_c = state.date) == null ? void 0 : _c.edit) {
    return true;
  }
  if ((_d = state.pet) == null ? void 0 : _d.edit) {
    return true;
  }
  if ((_e = state.service) == null ? void 0 : _e.edit) {
    return true;
  }
  if ((_f = state.notes) == null ? void 0 : _f.edit) {
    return true;
  }
  if ((_g = state.contacts) == null ? void 0 : _g.edit) {
    return true;
  }
  return false;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  deleteCacheParams,
  findNextDuration,
  findNextSlice,
  flexibleObj,
  formatProductListByCategory,
  formatResource,
  formatTimes,
  getCacheParams,
  getDays,
  getDiscountTime,
  getDiscountTimeByDayMinutes,
  getDuration,
  getEndDate,
  getErrorList,
  getIsEdit,
  getIsEject,
  getIsOnlySession,
  getLastServer,
  getMainPrice,
  getNowTime,
  getProductTotalPrice,
  getResourceTimeIsUsable,
  getServeStartTime,
  getServerItemExtend,
  getServiceTime,
  getServiceTimes,
  getShopOpeningHours,
  isNowTime,
  isSessionProduct,
  isWalkIn,
  memoize,
  request,
  sliceDayIntoFiveMinutes
});
