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