var L=Object.defineProperty;var w=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var D=(i,s,a)=>s in i?L(i,s,{enumerable:!0,configurable:!0,writable:!0,value:a}):i[s]=a,v=(i,s)=>{for(var a in s||(s={}))T.call(s,a)&&D(i,a,s[a]);if(w)for(var a of w(s))z.call(s,a)&&D(i,a,s[a]);return i};import{D as E,g as $,r as p,a as B,f as k,j as t,M as J,_ as N,S as O,W as q,h as P}from"./main-634.js";import{m as W}from"./bf-25-81.js";import{S as G}from"./bf-54-258.js";import{C as H}from"./bf-4-87.js";import{ac as Q,ag as R,ah as I,a7 as V}from"./bf-746-82.js";import{I as X}from"./bf-942-184.js";import{D as Y}from"./bf-254-220.js";import"./bf-275-83.js";import"./bf-822-108.js";function ce({formFields:i,setIntegration:s,integrations:a,allIntegURL:u}){const y=E(),{formID:d}=$(),[b,g]=p.useState(!1),[x,S]=p.useState(!1),[o,m]=p.useState(1),[_,C]=p.useState({show:!1}),{css:M}=B(),[e,r]=p.useState({name:"Dropbox Integration",type:"Dropbox",apiKey:"",apiSecret:"",accessCode:"",field_map:[{formField:"",dropboxFormField:""}],foldersList:[],actions:{}}),A=Q([e.type]),j=()=>{setTimeout(()=>{y(`${u}/new/${e.type}`)},1e3),g(!1)},F=(l,f)=>{if(l.integration_type===e.type){const c=JSON.parse(l.integration_details);r(n=>k(n,h=>{h.parentAppId=l.id,h.apiKey=c.apiKey,h.apiSecret=c.apiSecret,h.tokenDetails=c.tokenDetails})),m(2)}},K=()=>{V(a,s,u,e,y)};return p.useEffect(()=>{r(l=>k(l,f=>{const c=A.find(n=>n.id===e.parentAppId);if(c){const n=JSON.parse(c.integration_details);f.apiKey=n.apiKey,f.apiSecret=n.apiSecret,f.tokenDetails=n.tokenDetails}})),e!=null&&e.parentAppId&&R(d,e,r)},[e.parentAppId]),document.querySelector(".btcd-s-wrp").scrollTop=0,t.jsxs("div",{children:[t.jsx(J,{title:N("Authorize New Dropbox App"),show:b,setModal:()=>g(!1),children:t.jsx(I,{formID:d,dropboxConf:e,setDropboxConf:r,step:o,setStep:m,isLoading:x,setIsLoading:S,authorizedAction:j})}),t.jsx(O,{snack:_,setSnackbar:C}),t.jsx("div",{className:"txt-center w-9 mt-2 cal-width",children:t.jsx(G,{step:3,active:o})}),A.length>0&&o===1&&t.jsx(H,{allIntegURL:u,specificTypes:[e.type],onClickAction:F,allowAddNew:!0,addNewAction:()=>g(!0)}),o===1&&A.length===0&&t.jsx(I,{formID:d,dropboxConf:e,setDropboxConf:r,step:o,setStep:m,isLoading:x,setIsLoading:S,authorizedAction:j}),t.jsxs("div",{className:"btcd-stp-page",style:v({},o===2&&{width:900,height:"150%",overintegrations:"visible"}),children:[t.jsx(Y,{formID:d,formFields:i,dropboxConf:e,setDropboxConf:r,isLoading:x,setIsLoading:S}),t.jsxs(q,{variant:"success",onClick:()=>m(3),disabled:e.field_map.length<1,className:M(P.ftRight),children:[N("Next"),t.jsx(W,{className:"ml-1 rev-icn"})]})]}),t.jsx(X,{step:o,saveConfig:()=>K()})]})}export{ce as default};
