import{D as M,g as T,r as i,f as I,j as t,M as z,_ as b,S as P}from"./main-634.js";import"./bf-25-81.js";import{S as C}from"./bf-54-258.js";import{ac as F,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{d as B,Z as j,h as G}from"./bf-473-91.js";import{Z as H}from"./bf-925-187.js";import{C as q}from"./bf-4-87.js";import"./bf-275-83.js";import"./bf-822-108.js";import"./bf-438-114.js";function oe({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),[D,c]=i.useState({show:!1}),[w,Z]=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)},_=(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&&B(p,e,n,h,c)},[e.parentAppId]),i.useEffect(()=>{window.opener&&L("zohoBigin")},[]);const v=()=>{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:D,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:_,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:Z,formID:p,formFields:y,handleInput:r=>G(r,w,e,n,p,h,c),biginConf:e,setBiginConf:n,isLoading:f,setisLoading:h,setSnackbar:c}),t.jsx(O,{nextPageHandler:()=>v()})]}),t.jsx(J,{step:a,saveConfig:()=>$(N,k,u,e,g)})]})}export{oe as default};
