import{G as Z,g as M,r as i,f as A,j as t,M as T,S as C}from"./main-343.js";import"./bf-649-79.js";import{S as b}from"./bf-149-261.js";import{C as z}from"./bf-559-89.js";import{ac as P,s as L,a7 as _}from"./bf-659-81.js";import{I as $}from"./bf-58-184.js";import{N as B}from"./bf-713-109.js";import{Z as j}from"./bf-720-104.js";import{Z as G}from"./bf-544-198.js";import"./bf-974-82.js";import"./bf-541-186.js";function Y({formFields:I,setIntegration:k,integrations:y,allIntegURL:m}){const x=Z(),{formID:h}=M(),[f,u]=i.useState(!1),[N,g]=i.useState(!1),[a,l]=i.useState(1),[E,p]=i.useState({show:!1}),[e,c]=i.useState({name:"Zoho WorkDrive API",type:"Zoho WorkDrive",clientId:"",clientSecret:"",team:"",folder:"",folderMap:[],actions:{}}),w=P([e.type]),S=()=>{setTimeout(()=>{x(`${m}/new/${e.type}`)},1e3),g(!1)},v=(d,n)=>{if(d.integration_type===e.type){const o=JSON.parse(d.integration_details);c(s=>A(s,r=>{r.parentAppId=d.id,r.clientId=o.clientId,r.clientSecret=o.clientSecret,r.tokenDetails=o.tokenDetails,r.dataCenter=o.dataCenter,r.ownerEmail=o.ownerEmail})),l(2)}};i.useEffect(()=>{c(d=>A(d,n=>{const o=w.find(s=>s.id===e.parentAppId);if(o){const s=JSON.parse(o.integration_details);n.clientId=s.clientId,n.clientSecret=s.clientSecret,n.tokenDetails=s.tokenDetails,n.dataCenter=s.dataCenter,n.ownerEmail=s.ownerEmail}}))},[e.parentAppId]),i.useEffect(()=>{window.opener&&L("zohoWorkDrive")},[]);const D=()=>{setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),e.team!==""&&e.folder!==""&&l(3)};return t.jsxs("div",{children:[t.jsx(T,{title:"Authorize New Zoho WorkDrive App",show:N,setModal:()=>g(!1),children:t.jsx(j,{formID:h,workDriveConf:e,setWorkDriveConf:c,step:a,setStep:l,isLoading:f,setisLoading:u,setSnackbar:p,authorizedAction:S})}),t.jsx(C,{snack:E,setSnackbar:p}),t.jsx("div",{className:"txt-center w-9 mt-2 cal-width",children:t.jsx(b,{step:3,active:a})}),w.length>0&&a===1&&t.jsx(z,{allIntegURL:m,specificTypes:[e.type],onClickAction:v,allowAddNew:!0,addNewAction:()=>g(!0)}),a===1&&w.length===0&&t.jsx(j,{formID:h,workDriveConf:e,setWorkDriveConf:c,step:a,setStep:l,isLoading:f,setisLoading:u,setSnackbar:p,authorizedAction:S}),t.jsxs("div",{className:"btcd-stp-page",style:{width:a===2&&900,height:a===2&&"100%"},children:[t.jsx(G,{formID:h,formFields:I,workDriveConf:e,setWorkDriveConf:c,isLoading:f,setisLoading:u,setSnackbar:p}),t.jsx(B,{nextPageHandler:()=>D(),disabled:e.team===""||e.folder===""})]}),t.jsx($,{step:a,saveConfig:()=>_(y,k,m,e,x)})]})}export{Y as default};
