import{G as T,g as E,r,a as b,f as A,j as t,M as B,_ as I,S as C,U as F,h as P}from"./main-343.js";import{B as z}from"./bf-649-79.js";import{S as O}from"./bf-149-261.js";import{C as $}from"./bf-559-89.js";import{ac as J}from"./bf-659-81.js";import{c as L,s as R}from"./bf-204-199.js";import{I as W}from"./bf-58-184.js";import k from"./bf-579-115.js";import{r as q,a as H,d as K}from"./bf-997-171.js";import{G as Q}from"./bf-977-200.js";import"./bf-974-82.js";import"./bf-594-113.js";import"./bf-466-201.js";function ce({formFields:j,setIntegration:N,integrations:y,allIntegURL:d}){const w=T(),{formID:p}=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(`${d}/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(p,e,o,l,a)},[e.parentAppId]),r.useEffect(()=>{window.opener&&L("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(B,{title:I("Authorize New Google App"),show:G,setModal:()=>h(!1),children:t.jsx(k,{formID:p,sheetConf:e,setSheetConf:o,step:s,setstep:m,setSnackbar:a,isLoading:u,setisLoading:l,allIntegURL:d,authorizedAction:x})}),t.jsx(C,{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:d,specificTypes:[e.type],onClickAction:D,allowAddNew:!0,addNewAction:()=>h(!0)}),s===1&&S.length===0&&t.jsx(k,{formID:p,sheetConf:e,setSheetConf:o,step:s,setstep:m,setSnackbar:a,isLoading:u,setisLoading:l,allIntegURL:d,authorizedAction:x}),t.jsxs("div",{className:"btcd-stp-page",style:{width:s===2&&900,height:s===2&&"100%"},children:[t.jsx(Q,{formID:p,formFields:j,handleInput:i=>H(i,e,o,p,l,a),sheetConf:e,setSheetConf:o,isLoading:u,setisLoading:l,setSnackbar:a,setShowMdl:h}),t.jsxs(F,{onClick:()=>M(),disabled:!e.spreadsheetId||!e.worksheetName||e.field_map.length<1,className:_(P.ftRight),children:[I("Next"),t.jsx(z,{className:"ml-1 rev-icn"})]})]}),t.jsx(W,{step:s,saveConfig:()=>R(y,N,d,e,w)})]})}export{ce as default};
