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/modules/BookingContext/utils/timeSlices.ts
var timeSlices_exports = {};
__export(timeSlices_exports, {
  findNextDuration: () => findNextDuration,
  findNextSlice: () => findNextSlice,
  getDurationValue: () => import_flexible.getDurationValue,
  getEndDate: () => getEndDate,
  sliceDayIntoFiveMinutes: () => sliceDayIntoFiveMinutes
});
module.exports = __toCommonJS(timeSlices_exports);
var import_dayjs = __toESM(require("dayjs"));
var import_flexible = require("./flexible");
function sliceDayIntoFiveMinutes(config, isDay) {
  const startTime = (0, import_dayjs.default)().startOf("day");
  const endTime = (0, import_dayjs.default)().endOf("day");
  const timeSlice = config && config.value || 5;
  const timeSlices = [];
  const durationSlicesBasedOnTime = [];
  let currentTime = startTime;
  if (isDay) {
    let currentDay = 1;
    while (currentDay <= 30) {
      timeSlices.push({
        label: currentTime.format("hh:mm A"),
        value: currentTime.format("HH:mm")
      });
      durationSlicesBasedOnTime.push({
        label: String(currentDay),
        value: currentDay
      });
      currentDay += 1;
    }
    return { timeSlices, durationSlicesBasedOnTime };
  }
  while (currentTime.isBefore(endTime)) {
    timeSlices.push({
      label: currentTime.format("hh:mm A"),
      value: currentTime.format("HH:mm")
    });
    const nextTime = currentTime.add(timeSlice, "minute");
    const durationValue = nextTime.diff(startTime, "minute");
    durationSlicesBasedOnTime.push({
      label: String(durationValue),
      value: durationValue
    });
    currentTime = nextTime;
  }
  return { timeSlices, durationSlicesBasedOnTime };
}
function findNextDuration(current, array, defaultValue) {
  if (defaultValue !== void 0 && defaultValue !== null)
    return defaultValue;
  if (!array || array.length === 0)
    return void 0;
  for (let i = 0; i < array.length; i += 1) {
    if (array[i].value === (current == null ? void 0 : current.value))
      return array[i].value;
  }
  return array[0].value;
}
function findNextSlice(params) {
  var _a;
  const { timeSlices, index = 0, date = "" } = params;
  const currentTimeValue = date || (0, import_dayjs.default)().format("HH:mm");
  for (let i = 0; i < timeSlices.length; i += 1) {
    if (timeSlices[i].value !== "now" && timeSlices[i].value >= currentTimeValue) {
      return timeSlices[i].value;
    }
  }
  return (_a = timeSlices[index]) == null ? void 0 : _a.value;
}
function getEndDate(startDate, duration, endDate, shopOpeningHours) {
  if (duration === "flexible") {
    let openingDate = (0, import_dayjs.default)(
      `${startDate.format("YYYY-MM-DD")} ${shopOpeningHours || "23:59"}`
    );
    if ((0, import_dayjs.default)(startDate).isAfter(openingDate)) {
      openingDate = openingDate.add(1, "day");
    }
    if (!endDate)
      return openingDate;
    const endDateObj = (0, import_dayjs.default)(endDate);
    if (endDateObj.isAfter(openingDate))
      return openingDate;
    return endDateObj;
  }
  return startDate.add(Number(duration), "minute");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  findNextDuration,
  findNextSlice,
  getDurationValue,
  getEndDate,
  sliceDayIntoFiveMinutes
});
