import{G as D,g as M,r as n,f as A,j as e,M as b,S as C}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 T,s as L,a7 as _}from"./bf-659-81.js";import{I as $}from"./bf-58-184.js";import{N as G}from"./bf-713-109.js";import{Z as j}from"./bf-864-98.js";import{Z as J}from"./bf-952-192.js";import"./bf-974-82.js";function X({formFields:I,setIntegration:y,integrations:k,allIntegURL:p}){const f=D(),{formID:x}=M(),[S,g]=n.useState(!1),[N,h]=n.useState(!1),[a,l]=n.useState(1),[E,m]=n.useState({show:!1}),[t,d]=n.useState({name:"Zoho Mail API",type:"Zoho Mail",clientId:"",clientSecret:"",actions:{},to:"",cc:"",bcc:"",subject:"",body:""}),u=T([t.type]),w=()=>{setTimeout(()=>{f(`${p}/new/${t.type}`)},1e3),h(!1)},Z=(i,c)=>{if(i.integration_type===t.type){const o=JSON.parse(i.integration_details);d(s=>A(s,r=>{r.parentAppId=i.id,r.clientId=o.clientId,r.clientSecret=o.clientSecret,r.tokenDetails=o.tokenDetails,r.dataCenter=o.dataCenter,r.ownerEmail=o.ownerEmail})),l(2)}};n.useEffect(()=>{d(i=>A(i,c=>{const o=u.find(s=>s.id===t.parentAppId);if(o){const s=JSON.parse(o.integration_details);c.clientId=s.clientId,c.clientSecret=s.clientSecret,c.tokenDetails=s.tokenDetails,c.dataCenter=s.dataCenter,c.ownerEmail=s.ownerEmail}}))},[t.parentAppId]),n.useEffect(()=>{window.opener&&L("zohoMail")},[]);const v=i=>{l(i)};return e.jsxs("div",{children:[e.jsx(b,{title:"Authorize New Zoho Mail App",show:N,setModal:()=>h(!1),children:e.jsx(j,{formID:x,mailConf:t,setMailConf:d,step:a,setStep:l,isLoading:S,setisLoading:g,setSnackbar:m,authorizedAction:w})}),e.jsx(C,{snack:E,setSnackbar:m}),e.jsx("div",{className:"txt-center w-9 mt-2 cal-width",children:e.jsx(z,{step:3,active:a})}),u.length>0&&a===1&&e.jsx(P,{allIntegURL:p,specificTypes:[t.type],onClickAction:Z,allowAddNew:!0,addNewAction:()=>h(!0)}),a===1&&u.length===0&&e.jsx(j,{formID:x,mailConf:t,setMailConf:d,step:a,setStep:l,isLoading:S,setisLoading:g,setSnackbar:m,authorizedAction:w}),e.jsxs("div",{className:"btcd-stp-page",style:{width:a===2&&900,height:a===2&&"100%"},children:[e.jsx(J,{formFields:I,mailConf:t,setMailConf:d}),e.jsx(G,{nextPageHandler:()=>v(3)})]}),e.jsx($,{step:a,saveConfig:()=>_(k,y,p,t,f)})]})}export{X as default};
