import{E as e,M as t,c as n,ct as r,d as i,i as a,t as o,u as s,w as c}from"./_plugin-vue_export-helper-Conii5fq.js";import{a as l,c as u,i as d}from"./runtime-dom.esm-bundler-CI28bPhn.js";import{i as f}from"./router-CbChscq0.js";import{r as p,t as m}from"./strings-ldR5sTJW.js";var h={name:`ImageUpload`,data(){return{title:``,description:``,image:null,selectedPage:``,pages:[],images:[]}},methods:{formatDate:m,formatTimeFromDate:p,onFileChange(e){this.image=e.target.files[0]},async uploadImage(){let e=new FormData;e.append(`title`,this.title),e.append(`description`,this.description),e.append(`image`,this.image),e.append(`page`,this.selectedPage);try{await f.post(`/image/`,e),this.fetchImages(),this.resetForm()}catch(e){console.error(`Fehler beim Hochladen des Bildes:`,e)}},async fetchImages(){try{this.images=(await f.get(`/image`)).data}catch(e){console.error(`Fehler beim Abrufen der Bilder:`,e)}},async fetchPages(){try{let e=await f.get(`/menu-data`),t=function(e,n=``){return e.flatMap(e=>{let r=[];return e.submenu&&e.submenu.length&&(r=t(e.submenu,n+e.name+` -> `)),[{value:e.link,caption:n+e.name},...r]})};this.pages=t(e.data)}catch(e){console.error(`Fehler beim Abrufen der Seiten:`,e)}},async updateImage(e){try{await f.put(`/image/${e.id}`,{title:e.title,description:e.description}),this.fetchImages()}catch(e){console.error(`Fehler beim Aktualisieren des Bildes:`,e)}},resetForm(){this.title=``,this.description=``,this.image=null,this.selectedPage=``,document.getElementById(`image`).value=null}},mounted(){this.fetchImages(),this.fetchPages()}},g=[`value`],_={key:0},v=[`src`,`alt`],y=[`onUpdate:modelValue`,`onChange`],b=[`onUpdate:modelValue`,`onChange`];function x(o,f,p,m,h,x){return c(),i(`div`,null,[f[12]||=n(`h1`,null,`Bild hochladen`,-1),n(`form`,{onSubmit:f[4]||=u((...e)=>x.uploadImage&&x.uploadImage(...e),[`prevent`])},[n(`div`,null,[f[5]||=n(`label`,{for:`title`},`Titel`,-1),t(n(`input`,{type:`text`,id:`title`,"onUpdate:modelValue":f[0]||=e=>h.title=e},null,512),[[l,h.title]])]),n(`div`,null,[f[6]||=n(`label`,{for:`description`},`Beschreibung`,-1),t(n(`textarea`,{id:`description`,"onUpdate:modelValue":f[1]||=e=>h.description=e},null,512),[[l,h.description]])]),n(`div`,null,[f[7]||=n(`label`,{for:`image`},`Bild`,-1),n(`input`,{type:`file`,id:`image`,onChange:f[2]||=(...e)=>x.onFileChange&&x.onFileChange(...e)},null,32)]),n(`div`,null,[f[9]||=n(`label`,{for:`page`},`Seite`,-1),t(n(`select`,{id:`page`,"onUpdate:modelValue":f[3]||=e=>h.selectedPage=e},[f[8]||=n(`option`,{value:``},`Keine Seite`,-1),(c(!0),i(a,null,e(h.pages,e=>(c(),i(`option`,{key:e.value,value:e.value},r(e.caption),9,g))),128))],512),[[d,h.selectedPage]])]),f[10]||=n(`button`,{type:`submit`},`Hochladen`,-1)],32),h.images.length?(c(),i(`div`,_,[f[11]||=n(`h2`,null,`Hochgeladene Bilder`,-1),(c(!0),i(a,null,e(h.images,e=>(c(),i(`div`,{key:e.id,class:`uploaded-image`},[n(`img`,{src:`/images/uploads/${e.filename}`,alt:e.title,width:`100`},null,8,v),t(n(`input`,{type:`text`,"onUpdate:modelValue":t=>e.title=t,onChange:t=>x.updateImage(e)},null,40,y),[[l,e.title]]),t(n(`textarea`,{"onUpdate:modelValue":t=>e.description=t,onChange:t=>x.updateImage(e)},null,40,b),[[l,e.description]]),n(`p`,null,r(x.formatDate(e.uploadDate))+` `+r(x.formatTimeFromDate(e.uploadDate)),1)]))),128))])):s(``,!0)])}var S=o(h,[[`render`,x],[`__scopeId`,`data-v-37883b2e`]]);export{S as default};
//# sourceMappingURL=ImageUpload-5bEam1wQ.js.map