var w=Object.defineProperty;var v=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable;var j=(a,s,e)=>s in a?w(a,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[s]=e,S=(a,s)=>{for(var e in s||(s={}))F.call(s,e)&&j(a,e,s[e]);if(v)for(var e of v(s))P.call(s,e)&&j(a,e,s[e]);return a};import{j as r,_ as d,z as i}from"./main.2.9.0.js";import{u as z,b as o}from"./react-router.DMwpH23k.js";import"./CopyIcn.CEA_lFLo.js";import{S as E}from"./SnackMsg.DYSD96P4.js";import{S as T}from"./Steps.BYe8zHkm.js";import{I as A,g as B}from"./Integrations.DL8wqGct.js";import D from"./MailerLiteAuthorization.wY_j_5om.js";import{h as q,c as M}from"./MailerLiteCommonFunc.4jonRfr9.js";import{M as G}from"./MailerLiteIntegLayout.CLM9hmXD.js";import"./react-vendor.P7K3d6op.js";import"./Note.NSUdvR3c.js";import"./Table.BfF8RYFZ.js";import"./index.DpWdl9V1.js";import"./TutorialLink.CFG7bS5c.js";import"./ProUtilHelpers.CHf_DzPf.js";import"./TagifyInput.KPPRQJ1B.js";import"./lodash.DCvQBX3r.js";function at({formFields:a,setFlow:s,flow:e,allIntegURL:_}){const b=z(),[k,f]=o.useState(!1),[l,g]=o.useState({list:!1,field:!1,auth:!1,group:!1}),[n,h]=o.useState(1),[y,m]=o.useState({show:!1}),[t,c]=o.useState({name:"MailerLite",type:"MailerLite",auth_token:"",field_map:[{formField:"",mailerLiteFormField:"email"}],mailer_lite_type:"",mailerLiteFields:[],groups:[],group_ids:[],actions:{},action:""}),I=()=>{if((t==null?void 0:t.action)==="unassign_subscriber_from_group"&&!(t!=null&&t.selected_group_id)){i.error(d("Please select a group","bit-integrations"));return}f(!0),B(e,s,_,t,b,"","",f).then(u=>{var x;u.success?(i.success((x=u.data)==null?void 0:x.msg),b(_)):i.error(u.data||u)})},N=p=>{if(setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),!M(t)){i.error(d("Please map mandatory fields","bit-integrations"));return}if((t==null?void 0:t.action)==="unassign_subscriber_from_group"&&!(t!=null&&t.selected_group_id)){i.error(d("Please select a group","bit-integrations"));return}t.field_map.length>0&&h(p)};return r.jsxs("div",{children:[r.jsx(E,{snack:y,setSnackbar:m}),r.jsx("div",{className:"txt-center mt-2",children:r.jsx(T,{step:3,active:n})}),r.jsx(D,{mailerLiteConf:t,setMailerLiteConf:c,step:n,setstep:h,loading:l,setLoading:g,setSnackbar:m}),r.jsxs("div",{className:"btcd-stp-page",style:S({},n===2&&{width:900,height:"auto",overflow:"visible"}),children:[r.jsx(G,{formFields:a,handleInput:p=>q(p,t,c,l,g),mailerLiteConf:t,setMailerLiteConf:c,loading:l,setLoading:g,setSnackbar:m}),(t==null?void 0:t.action)&&r.jsxs("button",{onClick:()=>N(3),disabled:!M(t)||(t==null?void 0:t.action)==="unassign_subscriber_from_group"&&!(t!=null&&t.selected_group_id),className:"btn f-right btcd-btn-lg purple sh-sm flx",type:"button",children:[d("Next","bit-integrations"),"  ",r.jsx("div",{className:"btcd-icn icn-arrow_back rev-icn d-in-b"})]})]}),r.jsx(A,{step:n,saveConfig:()=>I(),isLoading:k,dataConf:t,setDataConf:c,formFields:a})]})}export{at as default};
