var m=Object.defineProperty;var b=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var _=(e,t,i)=>t in e?m(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,d=(e,t)=>{for(var i in t||(t={}))F.call(t,i)&&_(e,i,t[i]);if(b)for(var i of b(t))I.call(t,i)&&_(e,i,t[i]);return e};import{_ as r,z as u,d as y}from"./main.2.8.1.js";const z=(e,t,i)=>{const a=d({},t),{name:c}=e.target;e.target.value!==""?a[c]=e.target.value:delete a[c],i(d({},a))},k=e=>!((e!=null&&e.field_map?e.field_map.filter(i=>!i.formField||!i.pCloudFormField):[]).length>0),C=(e,t,i)=>{const a={tokenDetails:e.tokenDetails},c=y(a,"pCloud_get_all_folders").then(n=>{if(n&&n.success){const o=d({},e);return n.data&&(o.foldersList=n.data),t(o),i==="fetch"?r("Folders fetched successfully","bit-integrations"):r("Folders refreshed successfully","bit-integrations")}else return r("Folders refresh failed. please try again","bit-integrations")});u.promise(c,{success:n=>n,error:r("Error Occurred","bit-integrations"),loading:r("Loading PCloud Folders List...","bit-integrations")})},v=(e,t,i,a,c,n)=>{if(!e.clientId||!e.clientSecret){c({clientId:e.clientId?"":r("Client Id can't be empty","bit-integrations"),clientSecret:e.clientSecret?"":r("Client Secret can't be empty","bit-integrations")});return}a(!0);const o=`https://my.pcloud.com/oauth2/authorize?client_id=${e.clientId}&response_type=code&redirect_uri=${n.api}/redirect&state=${encodeURIComponent(window.location.href)}/redirect`,s=window.open(o,"pCloud","width=400,height=609,toolbar=off"),g=setInterval(()=>{if(s.closed){clearInterval(g);let l={},f=!1;const p=localStorage.getItem("__pCloud");if(p&&(f=!0,l=JSON.parse(p),localStorage.removeItem("__pCloud")),!l.code||l.error||!l||!f){const h=l.error?`Cause: ${l.error}`:"";u.error(`${r("Authorization Failed","bit-integrations")} ${h}. ${r("please try again","bit-integrations")}`),a(!1)}else{const h=d({},e);h.accountServer=l["accounts-server"],S(l,h,t,i,a,n)}}},500)},S=(e,t,i,a,c,n)=>{const o=d({},e);o.clientId=t.clientId,o.clientSecret=t.clientSecret,o.redirectURI=`${n.api}/redirect`,y(o,"pCloud_authorization").then(s=>{if(s&&s.success){const g=d({},t);g.tokenDetails=s.data,i(g),a(!0),u.success(r("Authorized Successfully","bit-integrations"))}else s&&s.data||!s.success&&typeof s.data=="string"?u.error(`${r("Authorization failed Cause:","bit-integrations")}${s.data}. ${r("please try again","bit-integrations")}`):u.error(r("Authorization failed. please try again","bit-integrations"));c(!1)})};export{v as a,k as c,C as g,z as h};
