import{G as M,g as C,r,f as w,j as t,S as T,M as b,_ as E}from"./main-343.js";import"./bf-649-79.js";import{S as L}from"./bf-149-261.js";import{C as D}from"./bf-559-89.js";import{ac as F,a7 as $}from"./bf-659-81.js";import{I as z}from"./bf-58-184.js";import{N as B}from"./bf-713-109.js";import j from"./bf-714-114.js";import{r as H,A as J,c as O}from"./bf-624-215.js";import"./bf-974-82.js";import"./bf-594-113.js";function ee({formFields:v,setIntegration:y,integrations:I,allIntegURL:m}){const x=M(),{formID:u}=C(),[S,c]=r.useState(!1),[f,d]=r.useState(!1),[s,l]=r.useState(1),[k,i]=r.useState({show:!1}),[e,n]=r.useState({name:"Active Campaign API",type:"ActiveCampaign",api_url:"",api_key:"",field_map:[{formField:"",activeCampaignField:""}],actions:{}}),A=F(["ActiveCampaign"]),N=a=>{if(setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),a===3){if(!O(e)){i({show:!0,msg:"Please map all required fields to continue."});return}if(!(e!=null&&e.listId)){i({show:!0,msg:"Please select list to continue."});return}e.name!==""&&e.field_map.length>0&&l(3)}},P=(a,g)=>{if(a.integration_type==="ActiveCampaign"){const p=JSON.parse(a.integration_details);n(o=>w(o,h=>{h.parentAppId=a.id,h.api_url=p.api_url,h.api_key=p.api_key})),l(2)}},_=()=>{setTimeout(()=>{x(`${m}/new/${e.type}`)},1e3),c(!1)};return r.useEffect(()=>{n(a=>w(a,g=>{const p=A.find(o=>o.id===e.parentAppId);if(p){const o=JSON.parse(p.integration_details);g.api_url=o.api_url,g.api_key=o.api_key}})),e!=null&&e.parentAppId&&H(e,n,d,i)},[e.parentAppId]),t.jsxs("div",{children:[t.jsx(T,{snack:k,setSnackbar:i}),t.jsx(b,{title:E("Connect New Active Campaing API"),show:S,setModal:()=>c(!1),children:t.jsx(j,{formID:u,activeCampaingConf:e,setActiveCampaingConf:n,step:s,setstep:l,isLoading:f,setIsLoading:d,setSnackbar:i,authorizedAction:_})}),t.jsx("div",{className:"txt-center w-9 mt-2 cal-width",children:t.jsx(L,{step:3,active:s})}),A.length>0&&s===1&&t.jsx(D,{allIntegURL:m,specificTypes:[e.type],onClickAction:P,allowAddNew:!0,addNewAction:()=>c(!0)}),s===1&&A.length===0&&t.jsx(j,{formID:u,activeCampaingConf:e,setActiveCampaingConf:n,step:s,setstep:l,isLoading:f,setIsLoading:d,setSnackbar:i,authorizedAction:_}),t.jsxs("div",{className:"btcd-stp-page",style:{width:s===2&&900,minHeight:s===2&&"900px"},children:[t.jsx(J,{formID:u,formFields:v,activeCampaingConf:e,setActiveCampaingConf:n,isLoading:f,setIsLoading:d,setSnackbar:i,setShowMdl:c}),t.jsx(B,{nextPageHandler:()=>N(3),disabled:!(e!=null&&e.listId)||e.field_map.length<1})]}),t.jsx(z,{step:s,saveConfig:()=>$(I,y,m,e,x)})]})}export{ee as default};
