var SYS_PRODUCTYPE = 'TEST'

var ua = window.navigator.userAgent.toLowerCase();
// var uaArr = ua.split(';');
// var isWebview = /supportJDSHWK\/1/i.test(ua); //iosapp,webview内核是否为wk
// console.log(isWebview, 'isWebview')

const isWebview = (name) => {
  ua = ua || navigator.userAgent;
  if (name === 'xview') return typeof window.XView !== 'undefined';
  if (name === 'wk') return !!ua.match(/supportjdshwk/i) || window._is_jdsh_wkwebview == 1;
  return false;
}

//关窗方法
const XViewClose = () => {
  console.log(isWebview, 'isWebview111')

  if (!isWebview('xview')) return;
  if (isWebview('wk')) {
    window.webkit.messageHandlers.XView.postMessage({
      "method": "close",
    });
  } else {
    window.XView && window.XView.close();
  }
}
const closeGiftPop = (content) => {
  var vm = this;
  // $(".ui-modal-body").removeClass('animate__' + vm.styleInfo.intoEffectType).addClass('animate__' + vm.styleInfo.outEffectType);
  // 关注信息同步给京东
  if (SYS_PRODUCTYPE != "DEVELOP") {
    if (!vm.hasFollow) {
      // window.location.href = 'xview://search?request={"action":"shopHome_followShop","des":"followShop_status","status":"true"}'
      window.location.href =
        'xview://search?request={"action":"shopHome_followShop","des":"followShop_status","status":"true","sourceType":"ISVRedEnvelope"}'
    }
  }
  setTimeout(function() {
    vm.isShowApp = false
    if (SYS_PRODUCTYPE != "DEVELOP") {
      XViewClose();
    }
  }, 1000)
}

const jumpGetCoupon = (url, callBack) => {
  console.log(url, '跳转方法')

  var params = {
    category: "jump",
    des: "getCoupon",
    sourceValue: "sourceValue_test",
    sourceType: "sourceType_test",
    url: url
  };
  params = JSON.stringify(params)
  var linkUrl = "openjd://virtual?params=" + params;
  window.location.href = linkUrl;
}

export {
  jumpGetCoupon,
  closeGiftPop
}
