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