import{D as T,g as E,r,a as b,f as A,j as t,M as C,_ as I,S as F,W as P,h as z}from"./main-634.js";import{m as B}from"./bf-25-81.js";import{S as O}from"./bf-54-258.js";import{C as $}from"./bf-4-87.js";import{ac as J}from"./bf-746-82.js";import{c as W,s as L}from"./bf-60-199.js";import{I as R}from"./bf-942-184.js";import{r as q,G as k,h as H,c as K}from"./bf-403-116.js";import{G as Q}from"./bf-328-200.js";import"./bf-275-83.js";import"./bf-822-108.js";import"./bf-438-114.js";import"./bf-913-201.js";function ce({formFields:j,setIntegration:N,integrations:y,allIntegURL:p}){const w=T(),{formID:d}=E(),[G,h]=r.useState(!1),[u,l]=r.useState(!1),[s,m]=r.useState(1),{css:_}=b(),[v,a]=r.useState({show:!1}),[e,o]=r.useState({name:"Google Sheet API",type:"Google Sheet",clientId:"",clientSecret:"",spreadsheetId:"",worksheetName:"",field_map:[{formField:"",googleSheetField:""}],header:"ROWS",headerRow:"A1",actions:{}}),S=J([e.type]),x=()=>{setTimeout(()=>{w(`${p}/new/${e.type}`)},1e3),h(!1)},D=(i,f)=>{if(i.integration_type===e.type){const c=JSON.parse(i.integration_details);o(n=>A(n,g=>{g.parentAppId=i.id,g.clientId=c.clientId,g.clientSecret=c.clientSecret,g.tokenDetails=c.tokenDetails})),m(2)}};r.useEffect(()=>{o(i=>A(i,f=>{const c=S.find(n=>n.id===e.parentAppId);if(c){const n=JSON.parse(c.integration_details);f.clientId=n.clientId,f.clientSecret=n.clientSecret,f.tokenDetails=n.tokenDetails}})),e!=null&&e.parentAppId&&q(d,e,o,l,a)},[e.parentAppId]),r.useEffect(()=>{window.opener&&W("googleSheet")},[]);const M=()=>{if(setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),!K(e)){a({show:!0,msg:"Please map fields to continue."});return}e.spreadsheetId!==""&&e.worksheetName!==""&&e.field_map.length>0&&m(3)};return t.jsxs("div",{children:[t.jsx(C,{title:I("Authorize New Google App"),show:G,setModal:()=>h(!1),children:t.jsx(k,{formID:d,sheetConf:e,setSheetConf:o,step:s,setstep:m,setSnackbar:a,isLoading:u,setisLoading:l,allIntegURL:p,authorizedAction:x})}),t.jsx(F,{snack:v,setSnackbar:a}),t.jsx("div",{className:"txt-center w-9 mt-2 cal-width",children:t.jsx(O,{step:3,active:s})}),S.length>0&&s===1&&t.jsx($,{allIntegURL:p,specificTypes:[e.type],onClickAction:D,allowAddNew:!0,addNewAction:()=>h(!0)}),s===1&&S.length===0&&t.jsx(k,{formID:d,sheetConf:e,setSheetConf:o,step:s,setstep:m,setSnackbar:a,isLoading:u,setisLoading:l,allIntegURL:p,authorizedAction:x}),t.jsxs("div",{className:"btcd-stp-page",style:{width:s===2&&900,height:s===2&&"100%"},children:[t.jsx(Q,{formID:d,formFields:j,handleInput:i=>H(i,e,o,d,l,a),sheetConf:e,setSheetConf:o,isLoading:u,setisLoading:l,setSnackbar:a,setShowMdl:h}),t.jsxs(P,{onClick:()=>M(),disabled:!e.spreadsheetId||!e.worksheetName||e.field_map.length<1,className:_(z.ftRight),children:[I("Next"),t.jsx(B,{className:"ml-1 rev-icn"})]})]}),t.jsx(R,{step:s,saveConfig:()=>L(y,N,p,e,w)})]})}export{ce as default};
