var __awaiter=this&&this.__awaiter||function(t,e,r,n){function i(t){return t instanceof r?t:new r((function(e){e(t)}))}return new(r||(r=Promise))((function(r,o){function s(t){try{l(n.next(t))}catch(t){o(t)}}function a(t){try{l(n["throw"](t))}catch(t){o(t)}}function l(t){t.done?r(t.value):i(t.value).then(s,a)}l((n=n.apply(t,e||[])).next())}))};var __generator=this&&this.__generator||function(t,e){var r={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},n,i,o,s;return s={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(s[Symbol.iterator]=function(){return this}),s;function a(t){return function(e){return l([t,e])}}function l(s){if(n)throw new TypeError("Generator is already executing.");while(r)try{if(n=1,i&&(o=s[0]&2?i["return"]:s[0]?i["throw"]||((o=i["return"])&&o.call(i),0):i.next)&&!(o=o.call(i,s[1])).done)return o;if(i=0,o)s=[s[0]&2,o.value];switch(s[0]){case 0:case 1:o=s;break;case 4:r.label++;return{value:s[1],done:false};case 5:r.label++;i=s[1];s=[0];continue;case 7:s=r.ops.pop();r.trys.pop();continue;default:if(!(o=r.trys,o=o.length>0&&o[o.length-1])&&(s[0]===6||s[0]===2)){r=0;continue}if(s[0]===3&&(!o||s[1]>o[0]&&s[1]<o[3])){r.label=s[1];break}if(s[0]===6&&r.label<o[1]){r.label=o[1];o=s;break}if(o&&r.label<o[2]){r.label=o[2];r.ops.push(s);break}if(o[2])r.ops.pop();r.trys.pop();continue}s=e.call(t,r)}catch(t){s=[6,t];i=0}finally{n=o=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};var __spreadArray=this&&this.__spreadArray||function(t,e){for(var r=0,n=e.length,i=t.length;r<n;r++,i++)t[i]=e[r];return t};import{E as Error}from"./unknown-97022c22.js";import"./Item-f4cbd6f4.js";import{a as Authorization}from"./index-2d6441ea.js";import"./ok-c9833bf3.js";import"./Token-ba2c5d5c.js";import"./index-c2c33860.js";import"./index-8e333ab5.js";var Handler=function(){function t(){}t.register=function(e,r,n){this.client=n;this.callbacks.push(e);e(this.states,this.logs,this.merchants,this.settlements,this.conversion);if(!t.timer){this.download(r);t.timer=setInterval(t.download,6e5)}};t.download=function(e){return __awaiter(this,void 0,void 0,(function(){var r,n,i,o,s,a,l,c,u,f,d,h;return __generator(this,(function(p){switch(p.label){case 0:if(!!this.downloading)return[3,5];p.label=1;case 1:p.trys.push([1,4,,5]);this.downloading=true;return[4,(r=t.client)===null||r===void 0?void 0:r.merchant.list()];case 2:a=p.sent();return[4,Promise.all([a&&!Error.is(a)?Promise.all(a.map((function(e){var r;return(r=t.client)===null||r===void 0?void 0:r.authorization.list(true,e.id)}))).then((function(t){return t.reduce((function(t,e){return e!=undefined&&Array.isArray(e)&&t&&!Error.is(t)?__spreadArray(__spreadArray([],t),e):t}),[])})):(n=t.client)===null||n===void 0?void 0:n.authorization.list(true),e!="test"?(i=t.client)===null||i===void 0?void 0:i.settlement.list():[],(o=t.client)===null||o===void 0?void 0:o.settlement.connection.get("currency/conversion")])];case 3:l=p.sent(),c=l[0],u=l[1],f=l[2];d=e=="developer"?(s=t.client)===null||s===void 0?void 0:s.log.list():Promise.resolve([]);if(!Error.is(c)&&c&&!c.some(Authorization.is))t.states=c;t.logs=d;if(!Error.is(a)&&typeof a!="string")t.merchants=a;if(!Error.is(u)&&typeof u!="string")t.settlements=u;if(!Error.is(f)&&typeof f!="string")t.conversion=f;t.callbacks.forEach((function(e){return e(t.states,t.logs,t.merchants,t.settlements,t.conversion)}));this.downloading=false;return[3,5];case 4:h=p.sent();this.downloading=false;return[3,5];case 5:return[2]}}))}))};return t}();Handler.downloading=false;Handler.callbacks=[];export{Handler as H};