import{G as v,g as D,r,a as T,f as I,j as t,M as b,_ as E,S as F}from"./main-343.js";import"./bf-649-79.js";import{S as P}from"./bf-149-261.js";import{C as z}from"./bf-559-89.js";import{ac as G}from"./bf-659-81.js";import{I as L}from"./bf-58-184.js";import{s as $}from"./bf-745-202.js";import{N as q}from"./bf-713-109.js";import{r as B,s as J,M as w,h as O,c as H,b as R}from"./bf-825-90.js";import{M as K}from"./bf-442-203.js";import"./bf-974-82.js";import"./bf-594-113.js";function ne({formFields:j,setIntegration:k,integrations:y,allIntegURL:f}){const x=v(),{formID:d}=D(),[M,l]=r.useState(!1),[g,p]=r.useState(!1),[i,m]=r.useState(1),[N,a]=r.useState({show:!1});T();const[e,n]=r.useState({name:"Mail Chimp Integration",type:"Mail Chimp",clientId:"",clientSecret:"",listId:"",listName:"",tags:"",field_map:[{formField:"",mailChimpField:""}],address_field:[],actions:{}}),S=G([e.type]),A=()=>{setTimeout(()=>{x(`${f}/new/${e.type}`)},1e3),l(!1)},C=(s,h)=>{if(s.integration_type===e.type){const c=JSON.parse(s.integration_details);n(o=>I(o,u=>{u.parentAppId=s.id,u.clientId=c.clientId,u.clientSecret=c.clientSecret,u.tokenDetails=c.tokenDetails})),m(2)}};r.useEffect(()=>{n(s=>I(s,h=>{const c=S.find(o=>o.id===e.parentAppId);if(c){const o=JSON.parse(c.integration_details);h.clientId=o.clientId,h.clientSecret=o.clientSecret,h.tokenDetails=o.tokenDetails}})),e!=null&&e.parentAppId&&B(d,e,n,p,a)},[e.parentAppId]),r.useEffect(()=>{window.opener&&J("mailChimp")},[]);const _=()=>{var s;if(setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),(s=e.actions)!=null&&s.address&&!H(e)){a({show:!0,msg:"Please map address required fields to continue."});return}if(!R(e)){a({show:!0,msg:"Please map fields to continue."});return}e.listId!==""&&m(3)};return t.jsxs("div",{children:[t.jsx(b,{title:E("Authorize New Mailchimp App"),show:M,setModal:()=>l(!1),children:t.jsx(w,{formID:d,sheetConf:e,setSheetConf:n,step:i,setstep:m,isLoading:g,setisLoading:p,setSnackbar:a,authorizedAction:A})}),t.jsx(F,{snack:N,setSnackbar:a}),t.jsx("div",{className:"txt-center w-9 mt-2 cal-width",children:t.jsx(P,{step:3,active:i})}),S.length>0&&i===1&&t.jsx(z,{allIntegURL:f,specificTypes:[e.type],onClickAction:C,allowAddNew:!0,addNewAction:()=>l(!0)}),i===1&&S.length===0&&t.jsx(w,{formID:d,sheetConf:e,setSheetConf:n,step:i,setstep:m,isLoading:g,setisLoading:p,setSnackbar:a,authorizedAction:A}),t.jsxs("div",{className:"btcd-stp-page",style:{width:i===2&&900,height:i===2&&"100%"},children:[t.jsx(K,{formID:d,formFields:j,handleInput:s=>O(s,e,n,d,p,a),sheetConf:e,setSheetConf:n,isLoading:g,setisLoading:p,setSnackbar:a,setShowMdl:l}),t.jsx(q,{nextPageHandler:()=>_(),disabled:!e.listId||e.field_map.length<1})]}),t.jsx(L,{step:i,saveConfig:()=>$(y,k,f,e,x)})]})}export{ne as default};
