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