import { getDoubleFaUrlFromSession } from "../foundation/utils/web_app_url_utils";
import { MODE } from "../constant/easysafepay";
export function getChannelBehavior(notRedirectAfterComplete, paymentSessionMetaData) {
  var _paymentSessionMetaDa;
  var allowSubmitPayCallAhead = false;
  var allowClickOutsideClose = false;
  var buildSubmitPayExtParams = undefined;
  // EASYPAY
  if ((paymentSessionMetaData === null || paymentSessionMetaData === void 0 || (_paymentSessionMetaDa = paymentSessionMetaData.paymentSessionConfig) === null || _paymentSessionMetaDa === void 0 ? void 0 : _paymentSessionMetaDa.productScene) === 'EASY_PAY') {
    var _paymentSessionMetaDa2, _paymentSessionMetaDa3, _paymentSessionMetaDa4, _paymentSessionMetaDa5;
    var isFirstTimeToPay = !((_paymentSessionMetaDa2 = paymentSessionMetaData.action) !== null && _paymentSessionMetaDa2 !== void 0 && _paymentSessionMetaDa2.autoDebitWithToken);
    var needAccountConfirmPage = (_paymentSessionMetaDa3 = paymentSessionMetaData.needAccountConfirmPage) !== null && _paymentSessionMetaDa3 !== void 0 ? _paymentSessionMetaDa3 : true;
    var isTossPayment = (paymentSessionMetaData === null || paymentSessionMetaData === void 0 || (_paymentSessionMetaDa4 = paymentSessionMetaData.paymentSessionConfig) === null || _paymentSessionMetaDa4 === void 0 ? void 0 : _paymentSessionMetaDa4.productSceneVersion) === '2.0' && ['BANKTRANSFER_QUICKPAY'].includes(paymentSessionMetaData === null || paymentSessionMetaData === void 0 || (_paymentSessionMetaDa5 = paymentSessionMetaData.paymentMethodInfoView) === null || _paymentSessionMetaDa5 === void 0 ? void 0 : _paymentSessionMetaDa5.paymentMethodType);
    if (isFirstTimeToPay) {
      allowSubmitPayCallAhead = !needAccountConfirmPage;
    } else {
      // 如果是二次一定调用submitPay接口
      allowSubmitPayCallAhead = true;
    }
    if (isTossPayment) {
      allowClickOutsideClose = false;
      buildSubmitPayExtParams = function buildSubmitPayExtParams(params) {
        var callBackUrl = getDoubleFaUrl(params);
        return {
          callBackUrl: callBackUrl,
          notRedirectAfterComplete: notRedirectAfterComplete
        };
      };
    }
  }
  return {
    allowSubmitPayCallAhead: allowSubmitPayCallAhead,
    buildSubmitPayExtParams: buildSubmitPayExtParams,
    createIframeNode: true,
    loadApp: true
  };
}
export function getDoubleFaUrl(params) {
  var instanceId = params.instanceId,
    paymentMethodType = params.paymentMethodType,
    paymentSessionData = params.paymentSessionData,
    paymentSessionObj = params.paymentSessionObj,
    locale = params.locale,
    env = params.env,
    sdkVersion = params.sdkVersion,
    notRedirectAfterComplete = params.notRedirectAfterComplete;
  var isLandscapeOrientation = false; // Web 不含横屏

  var baseDoubleFaUrl = getDoubleFaUrlFromSession(paymentSessionObj, env);
  return "".concat(baseDoubleFaUrl) + '?' + "scene=cashierResultPage" + '&' + "instanceId=".concat(instanceId) + '&' + "paymentSessionData=".concat(encodeURIComponent(paymentSessionData)) + '&' + "isLandscape=".concat(isLandscapeOrientation ? 'true' : '') + '&' + "pmt=".concat(paymentMethodType) + '&' + "locale=".concat(locale) + '&' + "sdkVersion=".concat(sdkVersion) + '&' + "mode=".concat(MODE.SDK) + '&' + "&notRedirectAfterComplete=".concat(notRedirectAfterComplete);
}