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/plus/pisellReservation/utils/reservationTicketBookingHostParams.ts
var reservationTicketBookingHostParams_exports = {};
__export(reservationTicketBookingHostParams_exports, {
  buildReservationTicketBookingCreateModeConfigBase: () => buildReservationTicketBookingCreateModeConfigBase,
  buildReservationTicketBookingCreateModeConfigForRow: () => buildReservationTicketBookingCreateModeConfigForRow,
  buildResourcePayloadFromReservationRow: () => buildResourcePayloadFromReservationRow,
  buildServiceItemFromReservationRuleProduct: () => buildServiceItemFromReservationRuleProduct
});
module.exports = __toCommonJS(reservationTicketBookingHostParams_exports);
var import_dayjs = __toESM(require("dayjs"));
function buildReservationTicketBookingCreateModeConfigBase(input) {
  const { reservationBiz, associated_menu_list_ids } = input;
  const menuIds = (associated_menu_list_ids == null ? void 0 : associated_menu_list_ids.filter(
    (id) => typeof id === "number" && Number.isFinite(id) && id > 0
  )) ?? [];
  return {
    bookingConfigParams: {
      item_type: "appointment_booking",
      sub_type: "food",
      source_type: "pos"
    },
    productDisplayConfig: "sku-list-a5",
    businessCode: reservationBiz,
    ...menuIds.length > 0 ? { associated_menu_list_ids: menuIds } : {},
    ...reservationBiz === "dine_in" ? { order_type: "table-order" } : {}
  };
}
function buildResourcePayloadFromReservationRow(row) {
  const relationIdNum = Number(row.id);
  const relationId = Number.isFinite(relationIdNum) ? relationIdNum : 0;
  const formIdNum = Number(row.form_id);
  const formId = Number.isFinite(formIdNum) ? formIdNum : 0;
  const cap = Number(row.capacityLabel ?? 0);
  const capacity = Number.isFinite(cap) ? cap : 0;
  return {
    [String(formId)]: [
      {
        id: 0,
        shop_id: 0,
        schedule_event_id: 0,
        category: "basic",
        form_id: formId,
        parent_relation_id: 0,
        relation_type: "form",
        relation_id: relationId,
        capacity,
        like_status: "common",
        metadata: null,
        created_at: null,
        updated_at: null,
        deleted_at: null
      }
    ]
  };
}
function buildInitialExtendCapacityFromRuleProduct(product) {
  const capacitys = product == null ? void 0 : product.capacity;
  if ((capacitys == null ? void 0 : capacitys.type) !== "custom" || !Array.isArray(capacitys.custom)) {
    return [];
  }
  return capacitys.custom.map((d) => ({
    id: d.id,
    value: d.min || 1,
    name: d.name
  }));
}
function buildServiceItemFromReservationRuleProduct(product, resource) {
  var _a;
  const duration = Number((_a = product == null ? void 0 : product.duration) == null ? void 0 : _a.value) || 0;
  const price = Number(product == null ? void 0 : product.price) || 0;
  const start = (0, import_dayjs.default)();
  const end = duration > 0 ? start.add(duration, "minute") : start;
  const title = (product == null ? void 0 : product.title) ?? (product == null ? void 0 : product.name) ?? "";
  const cover = (product == null ? void 0 : product.cover) ?? (product == null ? void 0 : product.main_image) ?? "";
  return {
    ...product,
    _id: `pre_${(product == null ? void 0 : product.id) ?? "unknown"}_${Date.now()}`,
    id: product == null ? void 0 : product.id,
    product_id: product == null ? void 0 : product.id,
    title,
    quantity: 1,
    price,
    cover,
    duration,
    _extend: {
      capacity: buildInitialExtendCapacityFromRuleProduct(product),
      duration,
      price,
      total: price,
      origin_total: price,
      quantity: 1,
      product_name: title,
      startDate: start,
      start_date: start,
      endDate: end,
      end_date: end,
      resource,
      start_time: start.format("HH:mm")
    }
  };
}
function buildReservationTicketBookingCreateModeConfigForRow(input) {
  const { reservationBiz, associated_menu_list_ids, reservationRuleProduct, row } = input;
  const biz = reservationBiz != null && String(reservationBiz).trim() !== "" ? String(reservationBiz).trim() : "";
  if (!biz) return null;
  const createModeConfig = buildReservationTicketBookingCreateModeConfigBase({
    reservationBiz: biz,
    associated_menu_list_ids
  });
  if (biz !== "dine_in") {
    return createModeConfig;
  }
  if (!reservationRuleProduct || !row) {
    return null;
  }
  const resourcePayload = buildResourcePayloadFromReservationRow(row);
  const serviceItem = buildServiceItemFromReservationRuleProduct(
    reservationRuleProduct,
    resourcePayload
  );
  createModeConfig.initialModalState = {
    service: { value: [serviceItem], edit: true },
    appointment_status: "started"
  };
  return createModeConfig;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildReservationTicketBookingCreateModeConfigBase,
  buildReservationTicketBookingCreateModeConfigForRow,
  buildResourcePayloadFromReservationRow,
  buildServiceItemFromReservationRuleProduct
});
