var k=Object.defineProperty;var p=Object.getOwnPropertySymbols;var m=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var b=(e,t,a)=>t in e?k(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,c=(e,t)=>{for(var a in t||(t={}))m.call(t,a)&&b(e,a,t[a]);if(p)for(var a of p(t))U.call(t,a)&&b(e,a,t[a]);return e};import{_ as o,b as g}from"./main.2.8.10.js";const I=(e,t,a)=>{const r=c({},t);r[e.target.name]=e.target.value,a(c({},r))},S=(e,t,a,r)=>{a(!0);const d={clientId:e.clientId,clientSecret:e.clientSecret,baseUrl:e.baseUrl,tokenDetails:e.tokenDetails};g(d,"mautic_get_fields").then(i=>{var l,n;if(i&&i.success){const s=c({},e);i.data&&(s.default||(s.default={}),(l=s.default)!=null&&l.fields||(s.default.fields={}),s.default.fields=i.data,s.field_map=D(i.data)),(n=i.data)!=null&&n.tokenDetails&&(s.tokenDetails=i.data.tokenDetails),r({show:!0,msg:o("Fields refreshed","bit-integrations")}),t(c({},s))}else r({show:!0,msg:o("Fields refresh failed. please try again","bit-integrations")});a(!1)}).catch(()=>a(!1))},A=(e,t,a,r)=>{a(!0);const d={clientId:e.clientId,clientSecret:e.clientSecret,baseUrl:e.baseUrl,tokenDetails:e.tokenDetails};g(d,"mautic_get_tags").then(i=>{var l,n;if(i&&i.success){const s=c({},e);i.data&&(s.default||(s.default={}),(l=s.default)!=null&&l.tags||(s.default.tags={}),s.default.tags=i.data),(n=i.data)!=null&&n.tokenDetails&&(s.tokenDetails=i.data.tokenDetails),r({show:!0,msg:o("Tags refreshed","bit-integrations")}),t(c({},s))}else r({show:!0,msg:o("Tags refresh failed. please try again","bit-integrations")});a(!1)}).catch(()=>a(!1))},R=(e,t,a,r)=>{a(!0);const d={clientId:e.clientId,clientSecret:e.clientSecret,baseUrl:e.baseUrl,tokenDetails:e.tokenDetails};g(d,"mautic_get_users").then(i=>{var l,n;if(i&&i.success){const s=c({},e);i.data&&(s.default||(s.default={}),(l=s.default)!=null&&l.users||(s.default.users={}),s.default.users=i.data.allUsers),(n=i.data)!=null&&n.tokenDetails&&(s.tokenDetails=i.data.tokenDetails),r({show:!0,msg:o("Contact Owner refreshed","bit-integrations")}),t(c({},s))}else r({show:!0,msg:o("Contact Owner refresh failed. please try again","bit-integrations")});a(!1)}).catch(()=>a(!1))},q=e=>{const t={},r=window.location.href.replace(`${window.opener.location.href}`,"").split("&");r&&r.forEach(d=>{const i=d.split("=");i[1]&&(t[i[0]]=i[1])}),localStorage.setItem(`__${e}`,JSON.stringify(t)),window.close()},v=(e,t,a,r,d,i,l)=>{if(!t.clientId||!t.clientSecret||!t.baseUrl){r({clientId:t.clientId?"":o("Client Id can't be empty","bit-integrations"),clientSecret:t.clientSecret?"":o("Secret key can't be empty","bit-integrations"),baseUrl:t.baseUrl?"":o("Base Url can't be empty","bit-integrations")});return}i(!0);const n=`${t.baseUrl}/oauth/v2/authorize?client_id=${t.clientId}&redirect_uri=${encodeURIComponent(window.location.href)}&response_type=code`,s=window.open(n,e,"width=400,height=609,toolbar=off"),_=setInterval(()=>{if(s.closed){clearInterval(_);let f={},u=!1;const w=localStorage.getItem(`__${e}`);if(w&&(u=!0,f=JSON.parse(w),localStorage.removeItem(`__${e}`),f.code.search("#"))){const[h]=f.code.split("#");f.code=h}if(!f.code||f.error||!f||!u){const h=f.error?`Cause: ${f.error}`:"";l({show:!0,msg:`${o("Authorization failed","bit-integrations")} ${h}. ${o("please try again","bit-integrations")}`}),i(!1)}else{const h=c({},t);h.accountServer=f["accounts-server"],y(f,h,a,d,i,l)}}},500)},y=(e,t,a,r,d,i)=>{const l=c({},e);l.clientId=t.clientId,l.clientSecret=t.clientSecret,l.baseUrl=t.baseUrl,l.redirectURI=window.location.href,g(l,"mautic_generate_token").then(n=>n).then(n=>{if(n&&n.success){const s=c({},t);s.tokenDetails=n.data,a(s),r(!0),i({show:!0,msg:o("Authorized Successfully","bit-integrations")})}else n&&n.data&&n.data.data||!n.success&&typeof n.data=="string"?i({show:!0,msg:`${o("Authorization failed Cause:","bit-integrations")}${n.data.data||n.data}. ${o("please try again","bit-integrations")}`}):i({show:!0,msg:o("Authorization failed. please try again","bit-integrations")});d(!1)})},z=e=>!((e.field_map?e.field_map.filter(a=>!a.formField&&!a.mauticField):[]).length>0),D=e=>{const t=e.filter(a=>a.required===!0);return t.length>0?t.map(a=>({formField:"",mauticField:a.fieldAlias})):[{formField:"",mauticField:""}]};export{R as a,S as b,z as c,v as d,A as g,I as h,q as s};
