var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/booking/editBookingModal/utils.ts
var utils_exports = {};
__export(utils_exports, {
  checkSubResourcesCapacity: () => checkSubResourcesCapacity,
  formatValues: () => formatValues
});
module.exports = __toCommonJS(utils_exports);
var import_utilsByBooking = require("../../info2/utilsByBooking");
var formatRelationDetails = (list) => {
  return (list || []).map((item) => {
    return {
      num: item.product_quantity,
      price: item.payment_price || 0,
      product_id: item.product_id,
      is_charge_tax: item.is_charge_tax,
      order_detail_id: item.order_detail_id
    };
  });
};
var checkSubResourcesCapacity = (resource) => {
  if (resource.children && resource.children.length) {
    let countCapacity = resource.capacity;
    resource.children.forEach((child) => {
      if (child.capacity <= countCapacity) {
        countCapacity -= child.capacity;
      } else {
        child.capacity = countCapacity;
        countCapacity = 0;
      }
    });
  }
};
var checkResourcesFormat = (resources, service, isChild) => {
  return resources.map((resource) => {
    var _a;
    if (!isChild) {
      resource.capacity = (0, import_utilsByBooking.getSumCapacity)({ cacheItem: service });
    }
    checkSubResourcesCapacity(resource);
    return {
      children: ((_a = resource.children) == null ? void 0 : _a.length) ? checkResourcesFormat(resource.children, service, true) : void 0,
      form_id: resource.form_id,
      relation_type: resource.relation_type || "form",
      relation_id: resource.relation_id || 0,
      capacity: resource.capacity,
      like_status: resource.like_status || "common",
      metadata: resource.metadata || {}
    };
  });
};
var formatResource = (service) => {
  if (!service._extend.resource) {
    return void 0;
  }
  try {
    return Object.values(service._extend.resource).reduce((pre, cur) => {
      const newList = checkResourcesFormat(cur, service);
      pre = pre.concat(newList);
      return pre;
    }, []);
  } catch (err) {
    return void 0;
  }
};
var formatProducts = (item) => {
  return {
    "num": Number(item.detail.quantity),
    "price": Number(item.detail.source_product_price),
    "source_product_price": Number(item.detail.source_product_price),
    "product_id": item.detail.id,
    "discount_amount": item.detail.discount_amount,
    "product_discount_reason": item.detail.product_discount_reason || "",
    "is_charge_tax": item.detail.is_charge_tax,
    "note": item.detail.note,
    "discountway": item.detail.discountway || "num",
    "discount_per": item.detail.discount_per,
    "discount_type": item.detail.discount_type,
    "order_detail_id": item.detail.order_detail_id,
    "product_bundle": item.detail.product_bundle,
    "bundle_edit": 0,
    "product_option_item": [],
    "product_variant_id": item.detail.product_variant_id || 0,
    "discount_list": item.detail.discount_list,
    metadata: item.detail.metadata
  };
};
var formatBookings = (data, values) => {
  let bookings = [];
  bookings = data.map((item) => {
    return {
      "product": formatProducts(item),
      "relation_products": formatRelationDetails(item.relation_details),
      "id": item.id,
      "relation_id": item.relation_id,
      "like_status": item.like_status,
      "relation_type": item.relation_type,
      "is_all": item.is_all,
      "schedule_id": item.schedule_id || 0,
      "end_time": item.end_time,
      "sub_type": item.sub_type,
      "select_date": item.start_date,
      "start_time": item.start_time,
      "end_date": item.end_date,
      "start_date": item.start_date,
      "duration": item.duration,
      "number": item.number,
      "resources": formatResource(item),
      "metadata": item.metadata,
      "holder": item.holder
    };
  });
  return bookings;
};
var formatValues = (data, values) => {
  let result = {
    type: "appointment_booking",
    platform: data.platform,
    sales_channel: data.platform,
    bookings: [],
    customer_id: data.customer_id,
    holder: data.holder,
    relation_products: data.relation_products,
    metadata: data.metadata,
    shop_note: data.shop_note,
    shop_discount: data.shop_discount,
    shop_discount_reason: data.shop_discount_reason,
    contacts: data.contacts,
    customer_name: data.customer_name,
    email: data.customer_name,
    phone: data.customer_name,
    country_calling_code: data.customer_name
  };
  result.bookings = formatBookings(data, values);
  return result;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  checkSubResourcesCapacity,
  formatValues
});
