import{D as M,g as C,r,f as w,j as t,S as T,M as b,_ as D}from"./main-634.js";import"./bf-25-81.js";import{S as E}from"./bf-54-258.js";import{C as L}from"./bf-4-87.js";import{ac as F,a7 as $}from"./bf-746-82.js";import{I as z}from"./bf-942-184.js";import{N as B}from"./bf-123-109.js";import j from"./bf-220-115.js";import{r as H,A as J,c as O}from"./bf-92-215.js";import"./bf-275-83.js";import"./bf-822-108.js";import"./bf-438-114.js";function te({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:D("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(E,{step:3,active:s})}),A.length>0&&s===1&&t.jsx(L,{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{te as default};
