import{G as D,g as M,r as c,f as A,j as t,M as b,_ as I,S as T}from"./main-343.js";import"./bf-649-79.js";import{S as z}from"./bf-149-261.js";import{C as P}from"./bf-559-89.js";import{ac as F,s as L,a7 as C}from"./bf-659-81.js";import{I as $}from"./bf-58-184.js";import{N as B}from"./bf-713-109.js";import{r as G,Z as j,h as J,c as O}from"./bf-772-94.js";import{Z as H}from"./bf-395-188.js";import"./bf-974-82.js";import"./bf-594-113.js";function se({formFields:y,setIntegration:k,integrations:N,allIntegURL:f}){const x=D(),{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)},Z=(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&&G(p,e,n,h,o)},[e.parentAppId]),c.useEffect(()=>{window.opener&&L("zohoCampaigns")},[]);const v=()=>{if(setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),!O(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:Z,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=>J(r,p,e,n,h,o),campaignsConf:e,setCampaignsConf:n,isLoading:u,setisLoading:h,setSnackbar:o}),t.jsx(B,{nextPageHandler:()=>v(),disabled:e.list===""||e.table===""||e.field_map.length<1})]}),t.jsx($,{step:a,saveConfig:()=>C(N,k,f,e,x)})]})}export{se as default};
