import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import"./Gallery.scss";import{useEffect,useState}from"react";import getProvider from"../../utils/getProvider";const PROVIDER=getProvider();export default function Gallery({currentFile:e,setCurrentFile:l,close:a,fileTypes:n}){const[t,r]=useState([]),[i,s]=useState(e),[o,c]=useState(e);function _(e){c(e),s(e)}useEffect((()=>{PROVIDER&&PROVIDER.gallery.getFiles(r,n)}),[]);const[d,g]=useState(!1),f=n;return _jsx("div",{className:"gallery",onClick:a,children:_jsxs("div",{className:"gallery__container",onClick:e=>e.stopPropagation(),onDragOver:function(e){e.preventDefault(),e.stopPropagation()},onDrop:function(e){e.preventDefault(),e.stopPropagation();const l=[...e.dataTransfer?.files??[]];g(!1),l.length&&(f&&l.some((e=>!f.some((l=>e.name.toLowerCase().endsWith(l.toLowerCase())))))?console.log(`Only following file formats are acceptable: ${f.join(", ")}`):async function(e){if(PROVIDER){const l=await PROVIDER.gallery.uploadFiles(e);r((e=>[...l,...e]))}}(l))},onDragEnter:function(e){e.preventDefault(),e.stopPropagation(),"draggingOverlay"!==e.target.id&&g(!0)},onDragLeave:function(e){e.preventDefault(),e.stopPropagation(),"draggingOverlay"===e.target.id&&g(!1)},children:[d&&_jsx("div",{id:"draggingOverlay",className:"gallery__container__drag-overlay",children:_jsx("div",{children:"Drop here"})}),_jsx("i",{className:"gallery__container__close-btn fa-solid fa-sharp fa-times",onClick:a}),_jsx("div",{className:"gallery__container__file-container "+(t.length>0?"gallery__container__file-container--has-files":""),children:t.length>0?PROVIDER?PROVIDER.gallery.renderFiles(t,o,_):null:_jsx("div",{className:"gallery__container__file-container__empty",children:"Drop files to upload"})}),o&&_jsxs("div",{className:"gallery__container__selected-file-panel",children:[_jsxs("div",{children:[function(e){if(o)return PROVIDER?PROVIDER.gallery.renderSelectedFile(o,c,e):null}(!0),o!=i&&_jsx("button",{className:"gallery__container__selected-file-panel__save-btn",onClick:function(){o&&(s(o),r((e=>e.map((e=>e.id===o.id?o:e)))),PROVIDER&&PROVIDER.gallery.updateFile(o.id,o))},children:"SAVE"})]}),_jsx("button",{className:"gallery__container__selected-file-panel__select-btn",onClick:()=>{l(o),c(""),s(null),a()},children:"SELECT"})]})]})})}