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/adjustTime/adapter.ts
var adapter_exports = {};
__export(adapter_exports, {
  getResourceEndTime: () => getResourceEndTime,
  mapAdjustTimeBooking: () => mapAdjustTimeBooking,
  mapAdjustTimeProducts: () => mapAdjustTimeProducts
});
module.exports = __toCommonJS(adapter_exports);
var import_dayjs = __toESM(require("dayjs"));
var import_utils = require("../info/service/addTimeModal/utils");
var getResourceEndTime = (state, cacheItem) => {
  var _a, _b, _c;
  try {
    const list = ((_a = state.service) == null ? void 0 : _a.resourcesOrigin) || [];
    const relationId = (_b = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _b.relation_id;
    if (!relationId || !list.length) {
      return void 0;
    }
    const currentResource = list.find((item) => item.form_record_id == relationId);
    if (!((_c = currentResource == null ? void 0 : currentResource.times) == null ? void 0 : _c.length)) {
      return void 0;
    }
    const timeItem = currentResource.times.find(
      (time) => time.item_id === relationId
    );
    if (!(timeItem == null ? void 0 : timeItem.end_date) || !(timeItem == null ? void 0 : timeItem.end_time)) {
      return void 0;
    }
    return (0, import_dayjs.default)(`${timeItem.end_date} ${timeItem.end_time}`).add(1, "second").toDate();
  } catch {
    return void 0;
  }
};
var mapAdjustTimeBooking = (cacheItem) => {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
  return {
    id: ((_a = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _a.relation_id) || (cacheItem == null ? void 0 : cacheItem.booking_id),
    title: ((_b = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _b.product_name) || (cacheItem == null ? void 0 : cacheItem.product_name) || "-",
    cover: (cacheItem == null ? void 0 : cacheItem.cover) || ((_c = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _c.cover),
    start: ((_d = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _d.startDate) || ((_e = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _e.start_date),
    end: ((_f = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _f.endDate) || ((_g = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _g.end_date),
    paidAmount: Number(((_h = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _h.paid_amount) || 0),
    quantity: Number(((_i = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _i.quantity) || 1)
  };
};
var mapAdjustTimeProducts = (state, cacheItem) => (state.addTimeProducts || []).filter((item) => (0, import_utils.isUsableProduct)(item.add_time, cacheItem)).map((item) => {
  var _a, _b, _c, _d, _e, _f;
  return {
    id: item.id,
    title: item.title || item.name || "-",
    price: Number(item.price || 0),
    minMinutes: Number(((_a = item.add_time) == null ? void 0 : _a.min_add_time) || 0),
    maxMinutes: Number(((_b = item.add_time) == null ? void 0 : _b.max_add_time) || ((_c = item.add_time) == null ? void 0 : _c.min_add_time) || 0),
    unitMinutes: Number(((_d = item.add_time) == null ? void 0 : _d.unit_duration) || ((_e = item.add_time) == null ? void 0 : _e.min_add_time) || 0),
    unlimited: ((_f = item.add_time) == null ? void 0 : _f.additional_time_options) === "unlimited"
  };
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getResourceEndTime,
  mapAdjustTimeBooking,
  mapAdjustTimeProducts
});
