import{D as Z,g as v,r,f as A,j as t,M as b,_ as M,S as T}from"./main-634.js";import{S as z}from"./bf-54-258.js";import{C as P}from"./bf-4-87.js";import{ac as C,s as F,a7 as L}from"./bf-746-82.js";import{I as $}from"./bf-942-184.js";import{N as B}from"./bf-123-109.js";import{r as J,Z as I,h as O}from"./bf-107-90.js";import{Z as G}from"./bf-250-185.js";import"./bf-25-81.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 oe({formFields:j,setIntegration:k,integrations:y,allIntegURL:f}){const x=Z(),{formID:d}=v(),[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&&J(d,e,i,h,c)},[e.parentAppId]),r.useEffect(()=>{window.opener&&F("zohoAnalytics")},[]);const D=()=>{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(G,{formID:d,formFields:j,handleInput:n=>O(n,e,i,d,h,c),analyticsConf:e,setAnalyticsConf:i,isLoading:u,setisLoading:h,setSnackbar:c}),t.jsx(B,{nextPageHandler:()=>D(),disabled:e.workspace===""||e.table===""||e.field_map.length<1})]}),t.jsx($,{step:a,saveConfig:()=>L(y,k,f,e,x)})]})}export{oe as default};
