var b=Object.defineProperty;var u=Object.getOwnPropertySymbols;var f=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable;var x=(e,t,s)=>t in e?b(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,o=(e,t)=>{for(var s in t||(t={}))f.call(t,s)&&x(e,s,t[s]);if(u)for(var s of u(t))y.call(t,s)&&x(e,s,t[s]);return e};import{c as j,d as p,_ as n,j as a,T as F,dl as N,z as v}from"./main-40.js";const S=(e,t,s,i,d,c,l,r)=>{const m=o({},t),{name:h}=e.target;e.target.value!==""?m[h]=e.target.value:delete m[h],s(o({},m))},_=(e=null,t,s)=>{var c;const i={formID:e,id:(c=t.id)!=null?c:null,apiKey:t.apiKey,apiSecret:t.apiSecret,tokenDetails:t.tokenDetails},d=j(i,"bitforms_dropbox_get_all_folders").then(l=>{if(l&&l.success){const r=o({},t);return l.data.dropboxFoldersList&&(r.foldersList=l.data.dropboxFoldersList,r.tokenDetails=l.data.tokenDetails),s(r),"Dropbox Folders List refreshed successfully"}else return"Dropbox Folders List refresh failed. please try again"});p.promise(d,{success:l=>l,error:n("Error Occurred"),loading:n("Loading Dropbox Folders List...")})},z=(e,t,s,i)=>{if(!e.accessCode||!e.apiKey||!e.apiSecret){p.error(n("Dropbox ApiKey, ApiSecret & Access Code can't be empty"));return}i(!0);const d={apiKey:e.apiKey,apiSecret:e.apiSecret,accessCode:e.accessCode};j(d,"bitforms_dropbox_authorization").then(c=>{if(c&&c.success){const l=o({},e);l.tokenDetails=c.data,t(l),s(!0),p.success(n("Authorized Successfully"))}else c&&c.data&&c.data.data||!c.success&&typeof c.data=="string"?p.error(`${n("Authorization failed Cause: ")}${c.data.data||c.data}. ${n("please try again")}`):p.error(n("Authorization failed. please try again"));i(!1)})};function k({dropboxConf:e,setDropboxConf:t}){var i;const s=(d,c)=>{const l=o({},e);c==="deleteFile"&&(d.target.checked?l.actions.delete_from_wp=!0:delete l.actions.delete_from_wp),t(o({},l))};return a.jsx("div",{className:"pos-rel d-flx w-8",children:a.jsx(F,{checked:((i=e.actions)==null?void 0:i.delete_from_wp)||!1,onChange:d=>s(d,"deleteFile"),className:"mt-4 mr-2",value:"delete_from_wp",title:n("Delete File From Wordpress"),subTitle:n("Delete file from Wordpress after upload in Dropbox")})})}const g=(e,t,s)=>{const i=o({},t);i.field_map.splice(e,0,{}),s(o({},i))},D=(e,t,s)=>{const i=o({},t);i.field_map.length>1&&i.field_map.splice(e,1),s(o({},i))};function A({i:e,formFields:t,field:s,dropboxConf:i,setDropboxConf:d}){const c=(l,r)=>{const m=o({},i);m.field_map[r][l.target.name]=l.target.value,d(o({},m))};return a.jsx("div",{className:"flx mt-2 mr-1",children:a.jsxs("div",{className:"pos-rel flx",children:[a.jsxs("div",{className:"flx integ-fld-wrp",children:[a.jsxs("select",{className:"btcd-paper-inp mr-2",name:"formField",value:s.formField||"",onChange:l=>c(l,e),children:[a.jsx("option",{value:"",children:n("Select Field")}),t==null?void 0:t.filter(l=>l.type==="file-up").map(l=>a.jsx("option",{value:l.key,children:l.name},`ff-rm-${l.key}`))]}),a.jsxs("select",{className:"btcd-paper-inp",name:"dropboxFormField",value:s.dropboxFormField,onChange:l=>c(l,e),children:[a.jsx("option",{value:"",children:n("Select Folder")}),N(i.foldersList,"lower_path","ASC").map(({name:l,lower_path:r})=>a.jsx("option",{value:r,children:r==null?void 0:r.substring(1).split("/").map(m=>m.replace("/",">")).join(" > ")},r))]})]}),a.jsx("button",{onClick:()=>g(e,i,d),className:"icn-btn sh-sm ml-2 mr-1",type:"button",children:"+"}),a.jsx("button",{onClick:()=>D(e,i,d),className:"icn-btn sh-sm ml-1",type:"button","aria-label":"btn",children:a.jsx(v,{})})]})})}function K({formID:e,formFields:t,dropboxConf:s,setDropboxConf:i,isLoading:d,setIsLoading:c}){return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"mt-5",children:[a.jsx("b",{className:"wdt-100",children:n("Field Map")}),a.jsx("button",{onClick:()=>_(e,s,i),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":`'${n("Fetch All Dropbox Folders")}'`},type:"button",children:"↻"})]}),a.jsx("div",{className:"btcd-hr mt-1"}),a.jsxs("div",{className:"flx flx-around mt-2 mb-1",children:[a.jsx("div",{className:"txt-dp",children:a.jsx("b",{children:n("File Input")})}),a.jsx("div",{className:"txt-dp",children:a.jsx("b",{children:n("Dropbox Folder")})})]}),s==null?void 0:s.field_map.map((l,r)=>a.jsx(A,{i:r,field:l,formFields:t,dropboxConf:s,setDropboxConf:i},`rp-m-${r+9}`)),a.jsx("div",{className:"txt-center  mt-2",style:{marginRight:85},children:a.jsx("button",{onClick:()=>g(s.field_map.length,s,i),className:"icn-btn sh-sm",type:"button",children:"+"})}),a.jsx("br",{}),a.jsx("br",{}),a.jsx("div",{className:"mt-4",children:a.jsx("b",{className:"wdt-100",children:n("Actions")})}),a.jsx("div",{className:"btcd-hr mt-1"}),a.jsx(k,{dropboxConf:s,setDropboxConf:i})]})}export{K as D,z as a,_ as g,S as h};
