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/Cart/utils/cartResource.ts
var cartResource_exports = {};
__export(cartResource_exports, {
  deleteResourceFromCartItem: () => deleteResourceFromCartItem,
  formatResourceToCartItem: () => formatResourceToCartItem,
  formatResourceToCartItemOrigin: () => formatResourceToCartItemOrigin
});
module.exports = __toCommonJS(cartResource_exports);
var import_dayjs = __toESM(require("dayjs"));
var formatResourceToCartItem = (params) => {
  const { cartItem, resources } = params;
  if (resources && (resources == null ? void 0 : resources.length)) {
    const firstResource = resources[0];
    cartItem.resource_id = firstResource == null ? void 0 : firstResource.id;
    cartItem.relation_form_name = firstResource == null ? void 0 : firstResource.main_field;
    if (firstResource.startTime && firstResource.endTime) {
      cartItem.start_date = (0, import_dayjs.default)(firstResource.startTime).format("YYYY-MM-DD");
      cartItem.start_time = (0, import_dayjs.default)(firstResource.startTime).format("HH:mm");
      cartItem.end_date = (0, import_dayjs.default)(firstResource.endTime).format("YYYY-MM-DD");
      cartItem.end_time = (0, import_dayjs.default)(firstResource.endTime).format("HH:mm");
    }
  } else {
    cartItem.resource_id = void 0;
    cartItem.relation_form_name = void 0;
    cartItem.start_date = void 0;
    cartItem.start_time = void 0;
    cartItem.end_date = void 0;
    cartItem.end_time = void 0;
  }
  const oringin = formatResourceToCartItemOrigin(params);
  cartItem._origin = oringin;
  cartItem._resourceOrigin = resources;
  return cartItem;
};
var formatResourceToCartItemOrigin = (params) => {
  const { cartItem, resources } = params;
  let origin = cartItem._origin;
  if (resources && (resources == null ? void 0 : resources.length)) {
    origin.resources = [];
    const checkResourcesFormat = (resources2, arr) => {
      resources2.forEach((resource) => {
        var _a;
        const childArr = [];
        if ((_a = resource == null ? void 0 : resource.children) == null ? void 0 : _a.length) {
          checkResourcesFormat(resource.children, childArr);
        }
        const obj = {
          relation_type: "form",
          like_status: resource.like_status || "common",
          id: resource.id,
          main_field: resource.main_field,
          resourceType: resource.resourceType,
          form_id: resource.form_id,
          relation_id: resource.id,
          capacity: (resource == null ? void 0 : resource.capacity) || 0,
          metadata: (resource == null ? void 0 : resource.metadata) || {}
          // 后端可以在这里挂一个前端用于计算的数据
        };
        if (childArr.length) {
          obj.children = childArr;
        }
        arr.push(obj);
      });
    };
    checkResourcesFormat(resources, origin.resources);
    const { startTime, endTime } = resources[0];
    if (startTime && endTime) {
      origin.select_date = (0, import_dayjs.default)(startTime).format("YYYY-MM-DD");
      origin.start_date = (0, import_dayjs.default)(startTime).format("YYYY-MM-DD");
      origin.start_time = (0, import_dayjs.default)(startTime).format("HH:mm");
      origin.end_date = (0, import_dayjs.default)(endTime).format("YYYY-MM-DD");
      origin.end_time = (0, import_dayjs.default)(endTime).format("HH:mm");
    }
  } else if ((resources == null ? void 0 : resources.length) === 0) {
    origin.resources = [];
    origin.select_date = null;
    origin.start_date = null;
    origin.start_time = null;
    origin.end_date = null;
    origin.end_time = null;
  }
  return origin;
};
var deleteResourceFromCartItem = (cartItem) => {
  cartItem.resource_id = void 0;
  cartItem.relation_form_name = void 0;
  delete cartItem._resourceOrigin;
  cartItem._origin.resources = null;
  return cartItem;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  deleteResourceFromCartItem,
  formatResourceToCartItem,
  formatResourceToCartItemOrigin
});
