import { isWalkIn } from "../../../components/booking/utils";
import { isNormalProductByDurationSchedule } from "../../../components/booking/info/service2/utils";
import { isProductHolderRequired, resolveProductHolderConfig } from "./productHolderConfig";
/**
 * 加车前是否弹出 Holder 选择（与 ticketBooking addService `handleBooking4Service` 条件一致）。
 */
export function shouldPromptHolderOnAddCart(input) {
  var _cacheItem$_extend;
  var cacheItem = input.cacheItem,
    productSource = input.productSource,
    customerId = input.customerId,
    skipForPromotion = input.skipForPromotion;
  if (skipForPromotion) return false;
  var holderConfig = resolveProductHolderConfig(productSource !== null && productSource !== void 0 ? productSource : cacheItem);
  if (!holderConfig.enabled) return false;
  if (isWalkIn(customerId !== null && customerId !== void 0 ? customerId : undefined)) return false;
  if (isNormalProductByDurationSchedule(cacheItem)) return false;
  var holderId = cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend = cacheItem._extend) === null || _cacheItem$_extend === void 0 ? void 0 : _cacheItem$_extend.holder_id;
  if (Array.isArray(holderId) && holderId.length > 0) return false;
  if (holderId !== undefined && holderId !== null && holderId !== '' && !Array.isArray(holderId)) {
    return false;
  }
  return true;
}

/** Holder 必选但用户未选时是否应中止加车 */
export function isHolderRequiredOnAddCart(productSource) {
  return isProductHolderRequired(productSource);
}