import{D as Z,g as v,r,f as S,j as t,M,S as T}from"./main-634.js";import"./bf-25-81.js";import{S as _}from"./bf-54-258.js";import{ac as z,s as C,a7 as P}from"./bf-746-82.js";import{I as F}from"./bf-942-184.js";import{N as L}from"./bf-123-109.js";import{r as $,Z as A,h as B}from"./bf-593-100.js";import{Z as J}from"./bf-264-196.js";import{C as O}from"./bf-4-87.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:I,setIntegration:j,integrations:y,allIntegURL:f}){const k=Z(),{formID:p}=v(),[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 D=()=>{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(O,{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(J,{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:()=>D(),disabled:e.workbook===""||e.worksheet===""||e.field_map.length<1})]}),t.jsx(F,{step:o,saveConfig:()=>P(y,j,f,e,k)})]})}export{oe as default};
