import{D as v,g as M,r as c,f as A,j as t,M as b,_ as I,S as T}from"./main-634.js";import"./bf-25-81.js";import{S as z}from"./bf-54-258.js";import{C as P}from"./bf-4-87.js";import{ac as F,s as L,a7 as C}from"./bf-746-82.js";import{I as $}from"./bf-942-184.js";import{N as B}from"./bf-123-109.js";import{r as J,Z as j,h as O,c as G}from"./bf-508-92.js";import{Z as H}from"./bf-948-188.js";import"./bf-275-83.js";import"./bf-822-108.js";import"./bf-438-114.js";function ae({formFields:y,setIntegration:k,integrations:N,allIntegURL:f}){const x=v(),{formID:p}=M(),[u,h]=c.useState(!1),[E,g]=c.useState(!1),[a,m]=c.useState(1),[_,o]=c.useState({show:!1}),[e,n]=c.useState({name:"Zoho Campaigns API",type:"Zoho Campaigns",clientId:"",clientSecret:"",list:"",field_map:[{formField:"",zohoFormField:""}]}),w=F([e.type]),S=()=>{setTimeout(()=>{x(`${f}/new/${e.type}`)},1e3),g(!1)},D=(r,l)=>{if(r.integration_type===e.type){const i=JSON.parse(r.integration_details);n(s=>A(s,d=>{d.parentAppId=r.id,d.clientId=i.clientId,d.clientSecret=i.clientSecret,d.tokenDetails=i.tokenDetails,d.dataCenter=i.dataCenter,d.ownerEmail=i.ownerEmail})),m(2)}};c.useEffect(()=>{n(r=>A(r,l=>{const i=w.find(s=>s.id===e.parentAppId);if(i){const s=JSON.parse(i.integration_details);l.clientId=s.clientId,l.clientSecret=s.clientSecret,l.tokenDetails=s.tokenDetails,l.dataCenter=s.dataCenter,l.ownerEmail=s.ownerEmail}})),e!=null&&e.parentAppId&&J(p,e,n,h,o)},[e.parentAppId]),c.useEffect(()=>{window.opener&&L("zohoCampaigns")},[]);const Z=()=>{if(setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),!G(e)){o({show:!0,msg:I("Please map mandatory fields")});return}e.list!==""&&e.table!==""&&e.field_map.length>0&&m(3)};return t.jsxs("div",{children:[t.jsx(b,{title:I("Authorize New Zoho Campaigns App"),show:E,setModal:()=>g(!1),children:t.jsx(j,{formID:p,campaignsConf:e,setCampaignsConf:n,step:a,setstep:m,isLoading:u,setisLoading:h,setSnackbar:o,authorizedAction:S})}),t.jsx(T,{snack:_,setSnackbar:o}),t.jsx("div",{className:"txt-center w-9 mt-2 cal-width",children:t.jsx(z,{step:3,active:a})}),w.length>0&&a===1&&t.jsx(P,{allIntegURL:f,specificTypes:[e.type],onClickAction:D,allowAddNew:!0,addNewAction:()=>g(!0)}),a===1&&w.length===0&&t.jsx(j,{formID:p,campaignsConf:e,setCampaignsConf:n,step:a,setstep:m,isLoading:u,setisLoading:h,setSnackbar:o,authorizedAction:S}),t.jsxs("div",{className:"btcd-stp-page",style:{width:a===2&&900,height:a===2&&"100%"},children:[t.jsx(H,{formID:p,formFields:y,handleInput:r=>O(r,p,e,n,h,o),campaignsConf:e,setCampaignsConf:n,isLoading:u,setisLoading:h,setSnackbar:o}),t.jsx(B,{nextPageHandler:()=>Z(),disabled:e.list===""||e.table===""||e.field_map.length<1})]}),t.jsx($,{step:a,saveConfig:()=>C(N,k,f,e,x)})]})}export{ae as default};
