import { isWalkIn } from "../../../components/booking/utils";
import { isNormalProductByDurationSchedule } from "../../../components/booking/info/service2/utils";
/**
 * 加车前是否弹出 Holder 选择（与 ticketBooking addService `handleBooking4Service` 条件一致）。
 */
export function shouldPromptHolderOnAddCart(input) {
  var _bookingConfig$config, _cacheItem$_extend;
  var cacheItem = input.cacheItem,
    bookingConfig = input.bookingConfig,
    customerId = input.customerId,
    skipForPromotion = input.skipForPromotion;
  if (skipForPromotion) return false;
  var basic = bookingConfig === null || bookingConfig === void 0 || (_bookingConfig$config = bookingConfig.config) === null || _bookingConfig$config === void 0 || (_bookingConfig$config = _bookingConfig$config.basic) === null || _bookingConfig$config === void 0 ? void 0 : _bookingConfig$config.appointment_subject;
  if ((basic === null || basic === void 0 ? void 0 : basic.type) !== 'form') return false;
  if ((basic === null || basic === void 0 ? void 0 : basic.show_hold_on_add_cart) === 0) 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(bookingConfig) {
  var _bookingConfig$config2;
  return (bookingConfig === null || bookingConfig === void 0 || (_bookingConfig$config2 = bookingConfig.config) === null || _bookingConfig$config2 === void 0 || (_bookingConfig$config2 = _bookingConfig$config2.basic) === null || _bookingConfig$config2 === void 0 ? void 0 : _bookingConfig$config2.subject_require) === 'require';
}