import{G as M,g as z,r as c,f as A,j as s,M as P,S as v,_ as F}from"./main-343.js";import"./bf-649-79.js";import{S as L}from"./bf-149-261.js";import{ac as T,s as C,a7 as $}from"./bf-659-81.js";import{I as b}from"./bf-58-184.js";import{N as G}from"./bf-713-109.js";import{r as I,Z as j,h as J,c as O}from"./bf-483-99.js";import{Z as B}from"./bf-709-193.js";import{C as q}from"./bf-559-89.js";import"./bf-974-82.js";import"./bf-594-113.js";function se({formFields:y,setIntegration:k,integrations:N,allIntegURL:m}){const S=M(),{formID:l}=z(),[u,d]=c.useState(!1),[_,g]=c.useState(!1),[i,f]=c.useState(1),[E,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(`${m}/new/${e.type}`)},1e3),g(!1)},Z=(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})),f(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 D=t=>{if(t===3){if(!O(e)){o({show:!0,msg:F("Please map mandatory fields")});return}e.list!==""&&e.field_map.length>0&&f(t)}else f(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:f,isLoading:u,setisLoading:d,setSnackbar:o,authorizedAction:w})}),s.jsx(v,{snack:E,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:m,specificTypes:[e.type],onClickAction:Z,allowAddNew:!0,addNewAction:()=>g(!0)}),i===1&&x.length===0&&s.jsx(j,{formID:l,marketingHubConf:e,setMarketingHubConf:n,step:i,setStep:f,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(B,{formID:l,formFields:y,handleInput:t=>J(t,l,e,n,d,o),marketingHubConf:e,setMarketingHubConf:n,isLoading:u,setisLoading:d,setSnackbar:o}),s.jsx(G,{nextPageHandler:()=>D(3),disabled:e.list===""||e.table===""||e.field_map.length<1})]}),s.jsx(b,{step:i,saveConfig:()=>$(N,k,m,e,S)})]})}export{se as default};
