var L=Object.defineProperty;var w=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var v=(i,s,a)=>s in i?L(i,s,{enumerable:!0,configurable:!0,writable:!0,value:a}):i[s]=a,D=(i,s)=>{for(var a in s||(s={}))T.call(s,a)&&v(i,a,s[a]);if(w)for(var a of w(s))z.call(s,a)&&v(i,a,s[a]);return i};import{G as B,g as E,r as p,a as $,f as k,j as t,M as J,_ as N,S as O,U as q,h as G}from"./main-343.js";import{B as P}from"./bf-649-79.js";import{S as H}from"./bf-149-261.js";import{C as Q}from"./bf-559-89.js";import{ac as R,af as V,ag as I,a7 as W}from"./bf-659-81.js";import{I as X}from"./bf-58-184.js";import{D as Y}from"./bf-828-220.js";import"./bf-974-82.js";function re({formFields:i,setIntegration:s,integrations:a,allIntegURL:h}){const y=B(),{formID:d}=E(),[b,g]=p.useState(!1),[x,S]=p.useState(!1),[o,f]=p.useState(1),[_,C]=p.useState({show:!1}),{css:M}=$(),[e,r]=p.useState({name:"Dropbox Integration",type:"Dropbox",apiKey:"",apiSecret:"",accessCode:"",field_map:[{formField:"",dropboxFormField:""}],foldersList:[],actions:{}}),A=R([e.type]),j=()=>{setTimeout(()=>{y(`${h}/new/${e.type}`)},1e3),g(!1)},F=(l,m)=>{if(l.integration_type===e.type){const c=JSON.parse(l.integration_details);r(n=>k(n,u=>{u.parentAppId=l.id,u.apiKey=c.apiKey,u.apiSecret=c.apiSecret,u.tokenDetails=c.tokenDetails})),f(2)}},K=()=>{W(a,s,h,e,y)};return p.useEffect(()=>{r(l=>k(l,m=>{const c=A.find(n=>n.id===e.parentAppId);if(c){const n=JSON.parse(c.integration_details);m.apiKey=n.apiKey,m.apiSecret=n.apiSecret,m.tokenDetails=n.tokenDetails}})),e!=null&&e.parentAppId&&V(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:f,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(H,{step:3,active:o})}),A.length>0&&o===1&&t.jsx(Q,{allIntegURL:h,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:f,isLoading:x,setIsLoading:S,authorizedAction:j}),t.jsxs("div",{className:"btcd-stp-page",style:D({},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:()=>f(3),disabled:e.field_map.length<1,className:M(G.ftRight),children:[N("Next"),t.jsx(P,{className:"ml-1 rev-icn"})]})]}),t.jsx(X,{step:o,saveConfig:()=>K()})]})}export{re as default};
