var b=Object.defineProperty;var w=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var _=(e,i,t)=>i in e?b(e,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[i]=t,o=(e,i)=>{for(var t in i||(i={}))F.call(i,t)&&_(e,t,i[t]);if(w)for(var t of w(i))k.call(i,t)&&_(e,t,i[t]);return e};import{_ as l,b as h,c as f,B as S}from"./bi.394.85.js";const R=(e,i,t,c,n)=>{const s=o({},i),{name:a}=e.target;e.target.value!==""?(s[a]=e.target.value,I(s,t,c,n),$(s,t,c,n)):delete s[a],t(o({},s))},v=(e,i,t,c)=>{t(!0);const n={tokenDetails:e.tokenDetails,clientId:e.clientId,clientSecret:e.clientSecret};h(n,"mailup_fetch_all_list").then(s=>{if(s&&s.success){const a=o({},e);s.data&&(a.allList=s.data),c({show:!0,msg:l("Mailup all lists fetched successfully","bit-integrations")}),i(o({},a))}else c({show:!0,msg:l("Mailup lists fetching failed. please try again","bit-integrations")});t(!1)}).catch(()=>t(!1))},$=(e,i,t,c)=>{t(!0);const n={tokenDetails:e.tokenDetails,clientId:e.clientId,clientSecret:e.clientSecret};h(n,"mailup_fetch_all_field").then(s=>{s&&s.success?(i(a=>S(a,d=>{d.staticFields=s.data,d.field_map=D(d)})),c({show:!0,msg:l("Mailup all fields fetched successfully","bit-integrations")})):c({show:!0,msg:l("Mailup fields fetching failed. please try again","bit-integrations")}),t(!1)}).catch(()=>t(!1))},I=(e,i,t,c)=>{t(!0);const n={tokenDetails:e.tokenDetails,clientId:e.clientId,clientSecret:e.clientSecret,listId:e.listId};h(n,"mailup_fetch_all_group").then(s=>{if(s&&s.success){const a=o({},e);s.data&&(a.allGroup=s.data),c({show:!0,msg:l("All groups fetched successfully","bit-integrations")}),i(o({},a))}else c({show:!0,msg:l("Groups fetching failed. please try again","bit-integrations")});t(!1)}).catch(()=>t(!1))},M=e=>{const i={},c=window.location.href.replace(`${window.opener.location.href}`,"").split("&");c&&c.forEach(n=>{const s=n.split("=");s[1]&&(i[s[0]]=s[1])}),localStorage.setItem(`__${e}`,JSON.stringify(i)),window.close()},P=(e,i,t,c,n,s,a)=>{if(!i.clientId){c({clientId:i.clientId?"":l("Client ID can't be empty","bit-integrations")});return}if(!i.clientSecret){c({clientSecret:i.clientSecret?"":l("Client secret can't be empty","bit-integrations")});return}s(!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}`:"";a({show:!0,msg:`${l("Authorization failed","bit-integrations")} ${u}. ${l("please try again","bit-integrations")}`}),s(!1)}else{const u=o({},i);A(r,u,t,n,s)}}s(!1)},500)},A=(e,i,t,c,n)=>{const s=o({},e);s.clientId=i.clientId,s.clientSecret=i.clientSecret,h(s,"mailup_authorization").then(a=>{if(a&&a.success){const d=o({},i);d.tokenDetails=a.data,t(d),c(!0),f.success(l("Authorized Successfully","bit-integrations"))}else a&&a.data&&a.data.data||!a.success&&typeof a.data=="string"?f.error(`${l("Authorization failed Cause:","bit-integrations")}${a.data.data||a.data}. ${l("please try again","bit-integrations")}`):f.error(l("Authorization failed. please try again","bit-integrations"));n(!1)})},D=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:""}]},G=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,G as c,P as d,v as f,R as h,M as s};
