import{D as v,g as b,r as i,f as I,j as t,M as T,_ as M,S as z}from"./main-634.js";import"./bf-25-81.js";import{S as P}from"./bf-54-258.js";import{C as F}from"./bf-4-87.js";import{ac as C,s as L,a7 as $}from"./bf-746-82.js";import{I as B}from"./bf-942-184.js";import{N as J}from"./bf-123-109.js";import{g as O,Z as y,h as G,c as H}from"./bf-52-94.js";import{Z as q}from"./bf-723-190.js";import"./bf-275-83.js";import"./bf-822-108.js";import"./bf-297-103.js";import"./bf-824-186.js";import"./bf-438-114.js";function re({formFields:j,setIntegration:k,integrations:N,allIntegURL:m}){const x=v(),{formID:p}=b(),[f,h]=i.useState(!1),[E,g]=i.useState(!1),[a,u]=i.useState(1),[_,n]=i.useState({show:!1}),[S,D]=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)},R=(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&&O(p,e,r,h,n)},[e.parentAppId]),i.useEffect(()=>{window.opener&&L("zohoCRM")},[]);const Z=()=>{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:R,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:D,formID:p,formFields:j,handleInput:l=>G(l,S,e,r,p,h,n),crmConf:e,setCrmConf:r,isLoading:f,setisLoading:h,setSnackbar:n}),t.jsx(J,{nextPageHandler:()=>Z(),disabled:e.module===""||e.layout===""||e.field_map.length<1})]}),t.jsx(B,{step:a,saveConfig:()=>$(N,k,m,e,x)})]})}export{re as default};
