var S=Object.defineProperty;var C=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var b=(e,t,a)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,d=(e,t)=>{for(var a in t||(t={}))$.call(t,a)&&b(e,a,t[a]);if(C)for(var a of C(t))k.call(t,a)&&b(e,a,t[a]);return e};import{_ as o,z as g,b as _}from"./main.2.8.10.js";const v=(e,t,a)=>{const r=d({},t),{name:c}=e.target;e.target.value!==""?r[c]=e.target.value:delete r[c],a(d({},r))},z=e=>!((e?e.filter(a=>!a.formField||!a.googleCalendarFormField):[]).length>0),F=(e,t,a)=>{const r={flowID:e!=null?e:null,clientId:t.clientId,clientSecret:t.clientSecret,tokenDetails:t.tokenDetails},c=_(r,"googleCalendar_get_all_lists").then(n=>{if(n&&n.success){const s=d({},t);return n.data.googleCalendarLists&&(s.calendarLists=n.data.googleCalendarLists,s.tokenDetails=n.data.tokenDetails),a(s),o("Google Calendar List refreshed successfully","bit-integrations")}else return o("Google Calendar List refresh failed. please try again","bit-integrations")});g.promise(c,{success:n=>n,error:o("Error Occurred","bit-integrations"),loading:o("Loading Google Calendar List...","bit-integrations")})},L=(e,t,a,r,c,n)=>{if(!e.clientId||!e.clientSecret){c({clientId:e.clientId?"":o("Client Id can't be empty","bit-integrations"),clientSecret:e.clientSecret?"":o("Client Secret can't be empty","bit-integrations")});return}r(!0);const i=`https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/calendar&access_type=offline&prompt=consent&response_type=code&state=${encodeURIComponent(window.location.href)}/redirect&redirect_uri=${encodeURIComponent(`${n.api}/redirect`)}&client_id=${e.clientId}`,u=window.open(i,"googleCalendar","width=400,height=609,toolbar=off"),y=setInterval(()=>{if(u.closed){clearInterval(y);let l={},p=!1;const f=localStorage.getItem("__googleCalendar");if(f&&(p=!0,l=JSON.parse(f),localStorage.removeItem("__googleCalendar")),!l.code||l.error||!l||!p){const h=l.error?`Cause: ${l.error}`:"";g.error(`${o("Authorization Failed","bit-integrations")} ${h}. ${o("please try again","bit-integrations")}`),r(!1)}else{const h=d({},e);h.accountServer=l["accounts-server"],I(l,h,t,a,r,n)}}},500)},I=(e,t,a,r,c,n)=>{const s=d({},e);s.clientId=t.clientId,s.clientSecret=t.clientSecret,s.redirectURI=`${n.api}/redirect`,_(s,"googleCalendar_authorization").then(i=>{if(i&&i.success){const u=d({},t);u.tokenDetails=i.data,a(u),r(!0),g.success(o("Authorized Successfully","bit-integrations"))}else i&&i.data&&i.data.data||!i.success&&typeof i.data=="string"?g.error(`${o("Authorization failed Cause:","bit-integrations")}${i.data.data||i.data}. ${o("please try again","bit-integrations")}`):g.error(o("Authorization failed. please try again","bit-integrations"));c(!1)})};export{L as a,z as c,F as g,v as h};
