import{G as M,g as T,r as i,f as I,j as t,M as z,_ as b,S as P}from"./main-343.js";import"./bf-649-79.js";import{S as C}from"./bf-149-261.js";import{ac as F,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{d as O,Z as j,h as B}from"./bf-985-93.js";import{Z as H}from"./bf-763-187.js";import{C as q}from"./bf-559-89.js";import"./bf-974-82.js";import"./bf-594-113.js";function ae({formFields:y,setIntegration:k,integrations:N,allIntegURL:u}){const g=M(),{formID:p}=T(),[f,h]=i.useState(!1),[E,x]=i.useState(!1),[a,m]=i.useState(1),[Z,c]=i.useState({show:!1}),[w,_]=i.useState(0),[e,n]=i.useState({name:"Zoho Bigin API",type:"Zoho Bigin",clientId:"",clientSecret:"",module:"",field_map:[{formField:"",zohoFormField:""}],relatedlists:[],actions:{}}),S=F([e.type]),A=()=>{setTimeout(()=>{g(`${u}/new/${e.type}`)},1e3),x(!1)},v=(r,d)=>{if(r.integration_type===e.type){const o=JSON.parse(r.integration_details);n(s=>I(s,l=>{l.parentAppId=r.id,l.clientId=o.clientId,l.clientSecret=o.clientSecret,l.tokenDetails=o.tokenDetails,l.dataCenter=o.dataCenter,l.ownerEmail=o.ownerEmail})),m(2)}};i.useEffect(()=>{n(r=>I(r,d=>{const o=S.find(s=>s.id===e.parentAppId);if(o){const s=JSON.parse(o.integration_details);d.clientId=s.clientId,d.clientSecret=s.clientSecret,d.tokenDetails=s.tokenDetails,d.dataCenter=s.dataCenter,d.ownerEmail=s.ownerEmail}})),e!=null&&e.parentAppId&&O(p,e,n,h,c)},[e.parentAppId]),i.useEffect(()=>{window.opener&&L("zohoBigin")},[]);const D=()=>{setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),e.module!==""&&e.field_map.length>0&&m(3)};return t.jsxs("div",{children:[t.jsx(z,{title:b("Authorize New Zoho Bigin App"),show:E,setModal:()=>x(!1),children:t.jsx(j,{formID:p,biginConf:e,setBiginConf:n,step:a,setstep:m,isLoading:f,setisLoading:h,setSnackbar:c,authorizedAction:A})}),t.jsx(P,{snack:Z,setSnackbar:c}),t.jsx("div",{className:"txt-center w-9 mt-2 cal-width",children:t.jsx(C,{step:3,active:a})}),S.length>0&&a===1&&t.jsx(q,{allIntegURL:u,specificTypes:[e.type],onClickAction:v,allowAddNew:!0,addNewAction:()=>x(!0)}),a===1&&S.length===0&&t.jsx(j,{formID:p,biginConf:e,setBiginConf:n,step:a,setstep:m,isLoading:f,setisLoading:h,setSnackbar:c,authorizedAction:A}),t.jsxs("div",{className:"btcd-stp-page",style:{width:a===2&&900,height:a===2&&"100%"},children:[t.jsx(H,{tab:w,settab:_,formID:p,formFields:y,handleInput:r=>B(r,w,e,n,p,h,c),biginConf:e,setBiginConf:n,isLoading:f,setisLoading:h,setSnackbar:c}),t.jsx(J,{nextPageHandler:()=>D()})]}),t.jsx(G,{step:a,saveConfig:()=>$(N,k,u,e,g)})]})}export{ae as default};
