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