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