var k=Object.defineProperty,p=Object.defineProperties;var g=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var y=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable;var f=(e,r,t)=>r in e?k(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,u=(e,r)=>{for(var t in r||(r={}))y.call(r,t)&&f(e,t,r[t]);if(F)for(var t of F(r))v.call(r,t)&&f(e,t,r[t]);return e},l=(e,r)=>p(e,g(r));import{z as c,_ as o,b as _}from"./main.2.8.10.js";import{u as d}from"./Note.DalStCGz.js";const G=(e,r,t,i,n)=>{const{name:s,value:a}=e.target,h=d(r,m=>{m[s]=a});t(h),s==="action"&&a!==""&&q(h,t,i,n)},b=e=>{const r=e==null?void 0:e.mailerLiteFields.filter(t=>t.required===!0);return r.length>0?r.map(t=>({formField:"",mailerLiteFormField:t.key})):[{formField:"",mailerLiteFormField:""}]},I=e=>!((e!=null&&e.field_map?e.field_map.filter(t=>!t.formField||!t.mailerLiteFormField||!t.formField==="custom"&&!t.customValue):[]).length>0),K=(e,r,t,i)=>{if(!e.auth_token){c.error(o("API Key can't be empty","bit-integrations"));return}i(l(u({},t),{auth:!0}));const n={auth_token:e.auth_token,version:e.version};_(n,"mailerlite_authorization").then(s=>{if(i(l(u({},t),{auth:!1})),s&&s.success){r(!0),c.success(o("Authorized Successfully","bit-integrations"));return}c.error(o("Authorized failed","bit-integrations"))})},q=(e,r,t,i)=>{if(!e.auth_token){c.error(o("API Key can't be empty","bit-integrations"));return}if(i(l(u({},t),{field:!0})),(e==null?void 0:e.action)!=="add_subscriber"){i(l(u({},t),{field:!1})),r(s=>d(s,a=>{a.mailerLiteFields=[{key:"email",label:"Email",required:!0}],a.field_map=b(a)})),c.success(o("Fields refresh successfully","bit-integrations"));return}const n={auth_token:e.auth_token,version:e.version};_(n,"mailerlite_refresh_fields").then(s=>{if(i(l(u({},t),{field:!1})),s&&s.success){r(a=>d(a,h=>{h.mailerLiteFields=s.data,h.field_map=b(h)})),c.success(o("Fields refresh successfully","bit-integrations"));return}c.error(o("Fields refresh failed","bit-integrations"))})},w=(e,r,t,i)=>{i(l(u({},i),{group:!0}));const n={auth_token:e.auth_token,version:e.version};_(n,"mailerlite_fetch_all_groups").then(s=>{if(s&&s.success){const a=u({},e);s.data&&(a.groups=s.data),r(a),i(l(u({},i),{group:!1})),c.success(o("Group fetch successfully","bit-integrations"));return}i(l(u({},i),{group:!1})),c.error(o("Group fetch failed","bit-integrations"))})};export{K as a,I as c,w as g,G as h,q as m};
