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/plus/salesSdk/utils/ensureHoldersBeforeSubmit.ts
var ensureHoldersBeforeSubmit_exports = {};
__export(ensureHoldersBeforeSubmit_exports, {
  ensureHoldersBeforeSubmit: () => ensureHoldersBeforeSubmit
});
module.exports = __toCommonJS(ensureHoldersBeforeSubmit_exports);
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_createHolderConfirmBridge = require("../holderConfirm/createHolderConfirmBridge");
var import_utils2 = require("../../../components/booking/utils");
var import_utils3 = require("../../../components/booking/info/service2/utils");
var import_holderSubmitValidation = require("./holderSubmitValidation");
async function ensureHoldersBeforeSubmit(input) {
  var _a, _b, _c, _d;
  const { bookingTicket, onMutate, holderConfirmBridge } = input;
  if (!bookingTicket) return true;
  const tempOrder = input.tempOrder ?? ((_a = bookingTicket.getTempOrder) == null ? void 0 : _a.call(bookingTicket)) ?? null;
  const bookingConfig = ((_b = bookingTicket.getBookingConfig) == null ? void 0 : _b.call(bookingTicket)) ?? null;
  const customerId = input.customerId ?? ((_d = (_c = bookingTicket.getOrderCustomerSnapshot) == null ? void 0 : _c.call(bookingTicket)) == null ? void 0 : _d.id) ?? (tempOrder == null ? void 0 : tempOrder.customer_id) ?? null;
  const unassignedHolderLines = (0, import_holderSubmitValidation.collectUnassignedHolderLines)(bookingTicket);
  const shouldPromptHolder = (0, import_holderSubmitValidation.shouldPromptHolderBeforeSubmit)({
    customerId,
    bookingConfig,
    bookingTicket
  });
  const isSubjectRequire = (0, import_utils3.getIsSubjectRequire)({ bookingConfig });
  const isWalkInCustomer = (0, import_utils2.isWalkIn)(customerId ?? void 0);
  const shouldRequireCustomerFirst = isSubjectRequire && isWalkInCustomer && unassignedHolderLines.length > 0;
  if (shouldRequireCustomerFirst) {
    (0, import_materials.PisellToast)({
      content: import_utils.locales.getText("pisell2.text.please-select-the-customer-first")
    });
    return false;
  }
  if (!shouldPromptHolder) {
    return true;
  }
  if (!holderConfirmBridge) {
    console.warn("[SalesSdk] holderConfirmBridge 未配置，跳过 holder 确认");
    return true;
  }
  const snapshotLineKeys = (0, import_holderSubmitValidation.buildHolderConfirmSnapshotKeys)(
    unassignedHolderLines
  );
  try {
    await holderConfirmBridge.show({
      bookingTicket,
      tempOrder,
      bookingConfig,
      customerId,
      snapshotLineKeys,
      onMutate
    });
    return true;
  } catch (error) {
    if ((0, import_createHolderConfirmBridge.isHolderConfirmCancelled)(error)) {
      return false;
    }
    throw error;
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ensureHoldersBeforeSubmit
});
