/**
 * 规格弹窗确认后的数量：以弹窗选择为准，不采用 addProductWithFlow 外层的防抖 increment。
 */
export function resolveConfirmDetailQuantity(input) {
  var _input$detailResult$d, _input$detailResult, _input$detailResult2, _input$options;
  var fromDetail = Number((_input$detailResult$d = (_input$detailResult = input.detailResult) === null || _input$detailResult === void 0 || (_input$detailResult = _input$detailResult.detail) === null || _input$detailResult === void 0 || (_input$detailResult = _input$detailResult._extend) === null || _input$detailResult === void 0 ? void 0 : _input$detailResult.quantity) !== null && _input$detailResult$d !== void 0 ? _input$detailResult$d : (_input$detailResult2 = input.detailResult) === null || _input$detailResult2 === void 0 || (_input$detailResult2 = _input$detailResult2.e) === null || _input$detailResult2 === void 0 ? void 0 : _input$detailResult2.quantity);
  if (Number.isFinite(fromDetail) && fromDetail > 0) {
    return Math.floor(fromDetail);
  }
  var fallback = (_input$options = input.options) === null || _input$options === void 0 ? void 0 : _input$options.quantity;
  if (fallback != null && fallback > 0) {
    return Math.floor(fallback);
  }
  return undefined;
}

/**
 * 已拼装 cacheItem 加车时：优先 cacheItem._extend.quantity，避免外层 options.quantity 覆盖弹窗数量。
 */
export function resolveAddQuantityFromCacheItem(cacheItem, explicitQuantity) {
  var _cacheItem$_extend;
  var fromCache = Number(cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend = cacheItem._extend) === null || _cacheItem$_extend === void 0 ? void 0 : _cacheItem$_extend.quantity);
  if (Number.isFinite(fromCache) && fromCache > 0) {
    return Math.floor(fromCache);
  }
  if (explicitQuantity != null && explicitQuantity > 0) {
    return Math.floor(explicitQuantity);
  }
  return undefined;
}