import{D as Z,g as _,r as c,f as A,j as t,M,S as P,_ as z}from"./main-634.js";import"./bf-25-81.js";import{S as T}from"./bf-54-258.js";import{C as b}from"./bf-4-87.js";import{ac as C,s as L,a7 as $}from"./bf-746-82.js";import{I as J}from"./bf-942-184.js";import{N as O}from"./bf-123-109.js";import{f as q,Z as I,h as B,c as G}from"./bf-936-98.js";import{Z as H}from"./bf-968-194.js";import"./bf-275-83.js";import"./bf-822-108.js";import"./bf-297-103.js";import"./bf-438-114.js";function ie({formFields:j,setIntegration:k,integrations:y,allIntegURL:u}){const g=Z(),{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)},D=(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&&q(p,e,r,h,o)},[e.parentAppId]),c.useEffect(()=>{window.opener&&L("zohoProjects")},[]);const E=s=>{if(s===3){if(!G(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:D,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=>B(s,e,r,p,h,o),projectsConf:e,setProjectsConf:r,isLoading:f,setisLoading:h,setSnackbar:o}),t.jsx(O,{nextPageHandler:()=>E(3),disabled:e.portalId===""||e.event===""})]}),t.jsx(J,{step:i,saveConfig:()=>$(y,k,u,e,g)})]})}export{ie as default};
