/**
 * 走入态白名单 + 取消态护栏，沿用 ticketBooking 现有 disabledEdit 语义。
 * 仅引用 `header.payment_status`（partially_paid → unpaid 等价归一）和
 * `rootBooking.appointment_status === 'cancelled'`，并叠加 `metadata.is_other_entrance_edited`
 * 渠道锁。所有字段读取来自 parseSalesResponse 输出，不发明等价关系。
 */
var PAYMENT_STATUS_EDITABLE_WHITELIST = new Set(['unfulfilled', 'paid', 'unpaid', 'payment_processing']);
export function deriveDisabledEdit(rootBooking, header) {
  var _rootBooking$appointm, _header$payment_statu, _header$metadata;
  var appointmentStatus = String((_rootBooking$appointm = rootBooking === null || rootBooking === void 0 ? void 0 : rootBooking.appointment_status) !== null && _rootBooking$appointm !== void 0 ? _rootBooking$appointm : '');
  var rawPaymentStatus = String((_header$payment_statu = header === null || header === void 0 ? void 0 : header.payment_status) !== null && _header$payment_statu !== void 0 ? _header$payment_statu : '');
  var paymentStatus = rawPaymentStatus === 'partially_paid' ? 'unpaid' : rawPaymentStatus;
  var channelDisabledEdit = Boolean(header === null || header === void 0 || (_header$metadata = header.metadata) === null || _header$metadata === void 0 ? void 0 : _header$metadata.is_other_entrance_edited);
  var cancelled = appointmentStatus === 'cancelled';
  var inWhitelist = paymentStatus === '' || PAYMENT_STATUS_EDITABLE_WHITELIST.has(paymentStatus);
  var disabledEdit = cancelled || !inWhitelist || channelDisabledEdit;
  return {
    disabledEdit: disabledEdit,
    channelDisabledEdit: channelDisabledEdit,
    appointmentStatus: appointmentStatus,
    paymentStatus: rawPaymentStatus
  };
}

/** Footer / Payments 用的最小金额字段集合 */

var ZERO_AMOUNT = '0.00';
export function deriveSummary(summary) {
  var get = function get(key) {
    var v = summary === null || summary === void 0 ? void 0 : summary[key];
    if (v == null) return ZERO_AMOUNT;
    return String(v);
  };
  return {
    productAmount: get('product_amount'),
    productOriginalAmount: get('product_original_amount'),
    productExpectAmount: get('product_expect_amount'),
    productTaxFee: get('product_tax_fee'),
    taxFee: get('tax_fee'),
    surchargeFee: get('surcharge_fee'),
    discountAmount: get('discount_amount'),
    depositAmount: get('deposit_amount'),
    expectAmount: get('expect_amount'),
    totalAmount: get('total_amount'),
    amountGap: get('amount_gap'),
    roundingAmount: get('rounding_amount')
  };
}

/**
 * 是否散客（walk-in customer），沿用 booking/utils.isWalkIn 语义：
 * 未指定客户、id === '' / '0' / '1' / 0 / 1 都视作散客。
 */
export function isWalkInCustomer(customer) {
  if (!customer) return true;
  var id = customer.id;
  if (id === undefined || id === null) return true;
  if (typeof id === 'string') {
    return ['', '0', '1'].includes(id);
  }
  return [0, 1].includes(id);
}