import{C as t,E as o}from"./p-888f7794.js";import{I as i,a as r}from"./p-be8a42cb.js";import{a as s}from"./p-d6eb762b.js";import"./p-a96ec623.js";import"./p-112455b1.js";import"./p-1ae2b158.js";var n=function(t,o,i,r){return new(i||(i=Promise))((function(s,n){function e(t){try{c(r.next(t))}catch(t){n(t)}}function u(t){try{c(r.throw(t))}catch(t){n(t)}}function c(t){var o;t.done?s(t.value):(o=t.value,o instanceof i?o:new i((function(t){t(o)}))).then(e,u)}c((r=r.apply(t,o||[])).next())}))};class e{constructor(t){this.connection=t,this.connection.onUnauthorized=()=>n(this,void 0,void 0,(function*(){return null!=this.onUnauthorized&&(yield this.onUnauthorized(this))}))}login(i,r){return n(this,void 0,void 0,(function*(){const n="string"==typeof i?{user:i,password:r}:i,e=yield this.connection.get("me",{authorization:t.toBasic(n)});return o.is(e)||(s.key=Array.isArray(e.merchant)?e.merchant[0].key.private:e.merchant.key.private,this.user=e),e}))}logout(){s.url=void 0,s.key=void 0,this.user=void 0}get user(){const t=s.storage;if(t){const o=t.getItem("Intergiro user");this.userValue=o?JSON.parse(o):void 0}return this.userValue}set user(t){const o=s.storage;o&&(t?o.setItem("Intergiro user",JSON.stringify(t)):o.removeItem("Intergiro user")),this.userValue=t}get customerKeys(){var t;const o=s.storage,n=[];for(let r=0;r<(null!==(t=null==o?void 0:o.length)&&void 0!==t?t:0);r++){const t=null==o?void 0:o.key(r);i.is(t,16)&&n.push(null==o?void 0:o.getItem(t))}return n.filter(r.is)}addCustomerKey(t,o){const i=s.storage;i&&i.setItem(o,t)}static open(t,o){const i=s.open(t,o);return i&&new e(i)}}export{e as Me}