import{D,g as v,r,a as T,f as I,j as t,M as b,_ as E,S as F}from"./main-634.js";import"./bf-25-81.js";import{S as P}from"./bf-54-258.js";import{C as z}from"./bf-4-87.js";import{ac as L}from"./bf-746-82.js";import{I as $}from"./bf-942-184.js";import{s as q}from"./bf-186-202.js";import{N as B}from"./bf-123-109.js";import{r as G,s as J,M as w,h as O,c as H,b as R}from"./bf-512-88.js";import{M as K}from"./bf-701-203.js";import"./bf-275-83.js";import"./bf-822-108.js";import"./bf-438-114.js";function oe({formFields:j,setIntegration:k,integrations:y,allIntegURL:f}){const x=D(),{formID:d}=v(),[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=L([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&&G(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(B,{nextPageHandler:()=>_(),disabled:!e.listId||e.field_map.length<1})]}),t.jsx($,{step:i,saveConfig:()=>q(y,k,f,e,x)})]})}export{oe as default};
