"use strict";var __assign=this&&this.__assign||function(){return __assign=Object.assign||function(n){for(var e,i=1,t=arguments.length;i<t;i++){e=arguments[i];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n},__assign.apply(this,arguments)};Object.defineProperty(exports,"__esModule",{value:!0});var h5Mobile_1=require("./h5Mobile"),findFitMsgId=function(n){return window.dingtalk.callbackStack[n]?findFitMsgId(n+1):n},h5PcBridgeReadyPromise,h5PcBridgeInit=function(){return h5PcBridgeReadyPromise||(h5PcBridgeReadyPromise=new Promise(function(n,e){try{window.dingtalk.callbackStack={},window.dingtalk.event.register(function(n,e){if(e){var i=""+e.msgId;"openapi.event.emit"===n&&(console.log("dingtalk receive event:",e,"identifer is",i),window.dingtalk.callbackStack[i]&&(window.dingtalk.callbackStack[i](e),delete window.dingtalk.callbackStack[i]))}}),setTimeout(n,0)}catch(n){e(n)}})),h5PcBridgeReadyPromise},h5PcBridge=function(n,e){return h5PcBridgeInit().then(function(){return new Promise(function(i,t){var r=__assign({_apiName:n},e),o=function(n){var e=n;return void 0!==e.body?h5Mobile_1.handleBridgeResponse(e.body,i,t):h5Mobile_1.handleBridgeResponse(e,i,t)},a=findFitMsgId(Date.now());window.dingtalk.platform.invokeAPI(a,n,r),window.dingtalk.callbackStack[a]=o}).then(function(n){return"function"==typeof e.onSuccess&&e.onSuccess.call(null,n),n},function(n){throw"function"==typeof e.onFail&&e.onFail.call(null,n),n})})},getH5PcBridge=function(){return h5PcBridgeInit().then(function(){return h5PcBridge})};exports.default=getH5PcBridge;