import{C as e,E as t,L as n,M as r,c as i,ct as a,d as o,i as s,t as c,w as l}from"./_plugin-vue_export-helper-Conii5fq.js";import{a as u}from"./runtime-dom.esm-bundler-CI28bPhn.js";import{r as d}from"./router-DXnXJqfT.js";var f={name:`UploadFilesComponent`,setup(){let t=n(null),r=n(``),i=n([]);return e(async()=>{try{i.value=(await d.get(`/files`)).data}catch(e){console.error(`Fehler beim Abrufen der Dateien:`,e)}}),{fileToUpload:t,fileTitle:r,uploadedFiles:i,handleFileUpload:e=>{t.value=e.target.files[0]},uploadFiles:async()=>{if(!t.value||!r.value){alert(`Bitte wählen Sie eine Datei aus und geben Sie einen Titel ein.`);return}let e=new FormData;e.append(`file`,t.value),e.append(`title`,r.value);try{let n=(await d.post(`/files`,e,{headers:{"Content-Type":`multipart/form-data`}})).data;i.value.push({id:n.id,title:n.title,originalName:n.originalName,createdAt:n.createdAt,hash:n.hash}),t.value=null,r.value=``}catch(e){console.error(`Fehler beim Hochladen der Datei:`,e)}},downloadFile:async e=>{let t=e.originalName.substring(e.originalName.lastIndexOf(`.`)),n=await d.get(`/files/download/${e.hash}`,{responseType:`blob`}),r=new Blob([n.data],{type:n.data.type}),i=document.createElement(`a`);i.href=window.URL.createObjectURL(r),i.download=`${e.title}${t}`,i.click(),window.URL.revokeObjectURL(i.href)},formatDate:e=>new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`long`,day:`numeric`})}}},p={class:`upload-files`},m={class:`file-list`},h={class:`file-info`},g=[`onClick`],_=[`onClick`],v={class:`file-date`};function y(e,n,c,d,f,y){return l(),o(`div`,p,[n[5]||=i(`h2`,null,`Dateien hochladen`,-1),i(`div`,null,[n[3]||=i(`label`,{for:`file-upload`},`Datei auswählen:`,-1),i(`input`,{id:`file-upload`,type:`file`,onChange:n[0]||=(...e)=>d.handleFileUpload&&d.handleFileUpload(...e)},null,32)]),i(`div`,null,[n[4]||=i(`label`,{for:`file-title`},`Titel eingeben:`,-1),r(i(`input`,{id:`file-title`,type:`text`,"onUpdate:modelValue":n[1]||=e=>d.fileTitle=e},null,512),[[u,d.fileTitle]])]),i(`button`,{onClick:n[2]||=(...e)=>d.uploadFiles&&d.uploadFiles(...e)},`Hochladen`),i(`ul`,m,[(l(!0),o(s,null,t(d.uploadedFiles,e=>(l(),o(`li`,{key:e.id},[i(`div`,h,[i(`span`,{class:`file-title`,onClick:t=>d.downloadFile(e)},a(e.title),9,g),i(`span`,{class:`file-name`,onClick:t=>d.downloadFile(e)},a(e.originalName),9,_),i(`span`,v,a(d.formatDate(e.createdAt)),1)])]))),128))])])}var b=c(f,[[`render`,y],[`__scopeId`,`data-v-8ac38dc3`]]);export{b as default};
//# sourceMappingURL=UploadFileManagement-CQLSg8yj.js.map