var F=Object.defineProperty;var w=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable;var _=(e,i,t)=>i in e?F(e,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[i]=t,o=(e,i)=>{for(var t in i||(i={}))b.call(i,t)&&_(e,t,i[t]);if(w)for(var t of w(i))S.call(i,t)&&_(e,t,i[t]);return e};import{_ as l,d as h,z as f}from"./main.2.8.1.js";import{u as k}from"./Note.BeM7sN-p.js";const v=(e,i,t,n,c)=>{const a=o({},i),{name:s}=e.target;e.target.value!==""?(a[s]=e.target.value,I(a,t,n,c),$(a,t,n,c)):delete a[s],t(o({},a))},M=(e,i,t,n)=>{t(!0);const c={tokenDetails:e.tokenDetails,clientId:e.clientId,clientSecret:e.clientSecret};h(c,"mailup_fetch_all_list").then(a=>{if(a&&a.success){const s=o({},e);a.data&&(s.allList=a.data),n({show:!0,msg:l("Mailup all Lists fetched successfully.","bit-integrations")}),i(o({},s))}else n({show:!0,msg:l("Mailup lists fetching failed. please try again","bit-integrations")});t(!1)}).catch(()=>t(!1))},$=(e,i,t,n)=>{t(!0);const c={tokenDetails:e.tokenDetails,clientId:e.clientId,clientSecret:e.clientSecret};h(c,"mailup_fetch_all_field").then(a=>{a&&a.success?(i(s=>k(s,d=>{d.staticFields=a.data,d.field_map=z(d)})),n({show:!0,msg:l("Mailup all fields fetched successfully","bit-integrations")})):n({show:!0,msg:l("Mailup fields fetching failed. please try again","bit-integrations")}),t(!1)}).catch(()=>t(!1))},I=(e,i,t,n)=>{t(!0);const c={tokenDetails:e.tokenDetails,clientId:e.clientId,clientSecret:e.clientSecret,listId:e.listId};h(c,"mailup_fetch_all_group").then(a=>{if(a&&a.success){const s=o({},e);a.data&&(s.allGroup=a.data),n({show:!0,msg:l("All groups fetched successfully","bit-integrations")}),i(o({},s))}else n({show:!0,msg:l("Groups fetching failed. please try again","bit-integrations")});t(!1)}).catch(()=>t(!1))},P=e=>{const i={},n=window.location.href.replace(`${window.opener.location.href}`,"").split("&");n&&n.forEach(c=>{const a=c.split("=");a[1]&&(i[a[0]]=a[1])}),localStorage.setItem(`__${e}`,JSON.stringify(i)),window.close()},G=(e,i,t,n,c,a,s)=>{if(!i.clientId){n({clientId:i.clientId?"":l("Client ID can't be empty","bit-integrations")});return}if(!i.clientSecret){n({clientSecret:i.clientSecret?"":l("Client Secret can't be empty","bit-integrations")});return}a(!0);const d=`https://services.mailup.com/Authorization/OAuth/LogOn?client_id=${i.clientId}&response_type=code&redirect_uri=${encodeURIComponent(window.location.href)}`,m=window.open(d,e,"width=400,height=609,toolbar=off"),y=setInterval(()=>{if(m.closed){clearInterval(y);let r={},g=!1;const p=localStorage.getItem(`__${e}`);if(p&&(g=!0,r=JSON.parse(p),localStorage.removeItem(`__${e}`),r.token&&(r.code=r.token)),!r.code||r.error||!r||!g){const u=r.error?`Cause: ${r.error}`:"";s({show:!0,msg:`${l("Authorization Failed","bit-integrations")} ${u}. ${l("please try again","bit-integrations")}`}),a(!1)}else{const u=o({},i);A(r,u,t,c,a)}}a(!1)},500)},A=(e,i,t,n,c)=>{const a=o({},e);a.clientId=i.clientId,a.clientSecret=i.clientSecret,h(a,"mailup_authorization").then(s=>{if(s&&s.success){const d=o({},i);d.tokenDetails=s.data,t(d),n(!0),f.success(l("Authorized Successfully","bit-integrations"))}else s&&s.data&&s.data.data||!s.success&&typeof s.data=="string"?f.error(`${l("Authorization failed Cause:","bit-integrations")}${s.data.data||s.data}. ${l("please try again","bit-integrations")}`):f.error(l("Authorization failed. please try again","bit-integrations"));c(!1)})},z=e=>{const i=e==null?void 0:e.staticFields.filter(t=>t.required===!0);return i.length>0?i.map(t=>({formField:"",mailupFormField:t.key})):[{formField:"",mailupFormField:""}]},O=e=>!((e!=null&&e.field_map?e.field_map.filter(t=>!t.formField||!t.mailupFormField||!t.formField==="custom"&&!t.customValue):[]).length>0);export{I as a,$ as b,O as c,G as d,M as f,v as h,P as s};
