import{D as Z,g as M,r as i,f as A,j as t,M as T,S as C}from"./main-634.js";import"./bf-25-81.js";import{S as b}from"./bf-54-258.js";import{C as z}from"./bf-4-87.js";import{ac as P,s as L,a7 as _}from"./bf-746-82.js";import{I as $}from"./bf-942-184.js";import{N as B}from"./bf-123-109.js";import{Z as j}from"./bf-907-102.js";import{Z as J}from"./bf-968-198.js";import"./bf-275-83.js";import"./bf-822-108.js";import"./bf-824-186.js";function U({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),[D,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)},E=(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 v=()=>{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:D,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:E,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(J,{formID:h,formFields:I,workDriveConf:e,setWorkDriveConf:c,isLoading:f,setisLoading:u,setSnackbar:p}),t.jsx(B,{nextPageHandler:()=>v(),disabled:e.team===""||e.folder===""})]}),t.jsx($,{step:a,saveConfig:()=>_(y,k,m,e,x)})]})}export{U as default};
