import{G as D,g as _,r as c,f as A,j as t,M,S as P,_ as z}from"./main-343.js";import"./bf-649-79.js";import{S as T}from"./bf-149-261.js";import{C as b}from"./bf-559-89.js";import{ac as C,s as L,a7 as $}from"./bf-659-81.js";import{I as G}from"./bf-58-184.js";import{N as J}from"./bf-713-109.js";import{f as O,Z as I,h as q,c as B}from"./bf-38-100.js";import{Z as H}from"./bf-20-194.js";import"./bf-974-82.js";import"./bf-529-105.js";import"./bf-594-113.js";function ae({formFields:j,setIntegration:k,integrations:y,allIntegURL:u}){const g=D(),{formID:p}=_(),[f,h]=c.useState(!1),[N,x]=c.useState(!1),[i,m]=c.useState(1),[v,o]=c.useState({show:!1}),[e,r]=c.useState({name:"Zoho Projects API",type:"Zoho Projects",clientId:"",clientSecret:"",portalId:"",event:"",field_map:{},actions:{}}),S=C([e.type]),w=()=>{setTimeout(()=>{g(`${u}/new/${e.type}`)},1e3),x(!1)},E=(s,d)=>{if(s.integration_type===e.type){const n=JSON.parse(s.integration_details);r(a=>A(a,l=>{l.parentAppId=s.id,l.clientId=n.clientId,l.clientSecret=n.clientSecret,l.tokenDetails=n.tokenDetails,l.dataCenter=n.dataCenter,l.ownerEmail=n.ownerEmail})),m(2)}};c.useEffect(()=>{r(s=>A(s,d=>{const n=S.find(a=>a.id===e.parentAppId);if(n){const a=JSON.parse(n.integration_details);d.clientId=a.clientId,d.clientSecret=a.clientSecret,d.tokenDetails=a.tokenDetails,d.dataCenter=a.dataCenter,d.ownerEmail=a.ownerEmail}})),e!=null&&e.parentAppId&&O(p,e,r,h,o)},[e.parentAppId]),c.useEffect(()=>{window.opener&&L("zohoProjects")},[]);const Z=s=>{if(s===3){if(!B(e,o)){o({show:!0,msg:z("Please map mandatory fields")});return}m(3)}};return t.jsxs("div",{children:[t.jsx(M,{title:"Authorize New Zoho Projects App",show:N,setModal:()=>x(!1),children:t.jsx(I,{formID:p,projectsConf:e,setProjectsConf:r,step:i,setStep:m,isLoading:f,setisLoading:h,setSnackbar:o,authorizedAction:w})}),t.jsx(P,{snack:v,setSnackbar:o}),t.jsx("div",{className:"txt-center w-9 mt-2 cal-width",children:t.jsx(T,{step:3,active:i})}),S.length>0&&i===1&&t.jsx(b,{allIntegURL:u,specificTypes:[e.type],onClickAction:E,allowAddNew:!0,addNewAction:()=>x(!0)}),i===1&&S.length===0&&t.jsx(I,{formID:p,projectsConf:e,setProjectsConf:r,step:i,setStep:m,isLoading:f,setisLoading:h,setSnackbar:o,authorizedAction:w}),t.jsxs("div",{className:"btcd-stp-page",style:{width:i===2&&900,height:i===2&&"100%"},children:[t.jsx(H,{formID:p,formFields:j,handleInput:s=>q(s,e,r,p,h,o),projectsConf:e,setProjectsConf:r,isLoading:f,setisLoading:h,setSnackbar:o}),t.jsx(J,{nextPageHandler:()=>Z(3),disabled:e.portalId===""||e.event===""})]}),t.jsx(G,{step:i,saveConfig:()=>$(y,k,u,e,g)})]})}export{ae as default};
