import{e as V,j as $,r as p,f as j,g as A,c as o,a as e,h as c,b as n,d as f,u as r,F as E,i as F,k as z,t as u,l as _,v as D,B as U,m as q,o as a,U as G}from"#entry";import{u as H}from"./C_U-NUAd.js";import{L as S}from"./CUq_0rkE.js";import{G as C}from"./KxVBmS-6.js";import{C as W}from"./YJHbYJtA.js";import{S as P,T as K}from"./CGpRzXRB.js";import{N as O}from"./DAACT36i.js";import{A as R}from"./C8kQt0fa.js";/** * @license lucide-vue-next v0.344.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const J=V("PlusIcon",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]),Q={class:"min-h-full py-16 bg-gray-50"},X={class:"max-w-4xl mx-auto px-4 sm:px-6 lg:px-8"},Y={class:"flex justify-between items-center mb-6"},Z={key:0,class:"flex items-center justify-center py-12"},ee={key:1,class:"space-y-6"},te={class:"flex justify-between items-start mb-4"},se={class:"flex-1"},le={class:"flex items-center space-x-3 mb-2"},ae={class:"text-2xl font-display font-bold text-gray-900"},oe={key:0,class:"px-3 py-1 bg-blue-100 text-blue-800 text-xs font-semibold rounded-full flex items-center"},re={class:"flex items-center text-sm text-gray-500 space-x-4"},ne={class:"flex items-center"},ie={class:"flex items-center"},de={key:0,class:"flex items-center"},ce={key:0,class:"flex space-x-2 ml-4"},ue=["onClick"],me=["onClick"],pe={class:"prose prose-lg max-w-none text-gray-700 whitespace-pre-wrap"},fe={key:0,class:"text-center py-12"},be={key:0,class:"text-gray-400 text-sm mt-2"},xe={class:"bg-white rounded-xl shadow-2xl max-w-3xl w-full p-8 max-h-[90vh] overflow-y-auto"},ve={class:"text-2xl font-display font-bold text-gray-900 mb-6"},he=["disabled"],ye=["disabled"],ge={class:"flex items-center space-x-3 p-4 bg-blue-50 rounded-lg border border-blue-200"},we=["disabled"],_e={for:"isPublic",class:"text-sm font-medium text-gray-900 cursor-pointer flex-1"},ke={class:"flex items-center"},Ne={key:0,class:"flex items-center p-3 rounded-md bg-red-50 text-red-700 text-sm"},ze={class:"flex justify-end space-x-4 pt-4"},De=["disabled"],Se=["disabled"],je={__name:"news",setup(Ce){const k=$(),v=p(!0),i=p(!1),h=p([]),x=p(!1),b=p(null),m=p(""),d=p({title:"",content:"",isPublic:!1}),y=j(()=>k.role==="admin"||k.role==="vorstand"),g=async()=>{v.value=!0;try{const s=await $fetch("/api/news");h.value=s.news}catch(s){console.error("Fehler beim Laden der News:",s)}finally{v.value=!1}},M=()=>{b.value=null,d.value={title:"",content:"",isPublic:!1},x.value=!0,m.value=""},L=s=>{b.value=s,d.value={title:s.title,content:s.content,isPublic:s.isPublic||!1},x.value=!0,m.value=""},w=()=>{x.value=!1,b.value=null,m.value=""},I=async()=>{i.value=!0,m.value="";try{await $fetch("/api/news",{method:"POST",body:{id:b.value?.id,...d.value}}),w(),await g()}catch(s){m.value=s.data?.message||"Fehler beim Speichern der News."}finally{i.value=!1}},T=async s=>{if(console.log("Delete item:",s),console.log("Delete item.id:",s.id),!!confirm(`Möchten Sie die News "${s.title}" wirklich löschen?`)){if(!s.id){alert("Fehler: News-ID fehlt!");return}try{console.log("Deleting with ID:",s.id),await $fetch(`/api/news?id=${encodeURIComponent(s.id)}`,{method:"DELETE"}),await g()}catch(t){console.error("Delete error:",t),alert("Fehler beim Löschen der News: "+(t.data?.message||t.message))}}},N=s=>s?new Date(s).toLocaleDateString("de-DE",{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit"}):"";return A(()=>{g()}),H({title:"Interne News - Harheimer TC"}),(s,t)=>(a(),o("div",Q,[e("div",X,[e("div",Y,[t[4]||(t[4]=e("div",null,[e("h1",{class:"text-4xl sm:text-5xl font-display font-bold text-gray-900 mb-2"}," Interne News "),e("div",{class:"w-24 h-1 bg-primary-600 mb-4"})],-1)),y.value?(a(),o("button",{key:0,onClick:M,class:"flex items-center px-4 py-2 bg-primary-600 hover:bg-primary-700 text-white font-semibold rounded-lg transition-colors"},[n(r(J),{size:20,class:"mr-2"}),t[3]||(t[3]=f(" News erstellen ",-1))])):c("",!0)]),v.value?(a(),o("div",Z,[n(r(S),{size:40,class:"animate-spin text-primary-600"})])):(a(),o("div",ee,[(a(!0),o(E,null,F(h.value,l=>(a(),o("article",{key:l.id,class:"bg-white rounded-xl shadow-lg p-6 border border-gray-100"},[e("div",te,[e("div",se,[e("div",le,[e("h2",ae,u(l.title),1),l.isPublic?(a(),o("span",oe,[n(r(C),{size:14,class:"mr-1"}),t[5]||(t[5]=f(" Öffentlich ",-1))])):c("",!0)]),e("div",re,[e("div",ne,[n(r(G),{size:16,class:"mr-1"}),f(" "+u(l.author),1)]),e("div",ie,[n(r(W),{size:16,class:"mr-1"}),f(" "+u(N(l.created)),1)]),l.updated!==l.created?(a(),o("div",de,[n(r(P),{size:16,class:"mr-1"}),f(" Aktualisiert: "+u(N(l.updated)),1)])):c("",!0)])]),y.value?(a(),o("div",ce,[e("button",{onClick:B=>L(l),class:"p-2 text-blue-600 hover:bg-blue-50 rounded-lg transition-colors",title:"Bearbeiten"},[n(r(P),{size:20})],8,ue),e("button",{onClick:B=>T(l),class:"p-2 text-red-600 hover:bg-red-50 rounded-lg transition-colors",title:"Löschen"},[n(r(K),{size:20})],8,me)])):c("",!0)]),e("div",pe,u(l.content),1)]))),128)),h.value.length===0?(a(),o("div",fe,[n(r(O),{size:48,class:"mx-auto text-gray-400 mb-4"}),t[6]||(t[6]=e("p",{class:"text-gray-500 text-lg"},"Noch keine internen News vorhanden.",-1)),y.value?(a(),o("p",be,' Klicken Sie auf "News erstellen", um die erste News zu veröffentlichen. ')):c("",!0)])):c("",!0)])),x.value?(a(),o("div",{key:2,class:"fixed inset-0 z-50 bg-black/50 flex items-center justify-center p-4",onClick:z(w,["self"])},[e("div",xe,[e("h2",ve,u(b.value?"News bearbeiten":"News erstellen"),1),e("form",{onSubmit:z(I,["prevent"]),class:"space-y-4"},[e("div",null,[t[7]||(t[7]=e("label",{class:"block text-sm font-medium text-gray-700 mb-2"},"Titel *",-1)),_(e("input",{"onUpdate:modelValue":t[0]||(t[0]=l=>d.value.title=l),type:"text",required:"",class:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500",disabled:i.value},null,8,he),[[D,d.value.title]])]),e("div",null,[t[8]||(t[8]=e("label",{class:"block text-sm font-medium text-gray-700 mb-2"},"Inhalt *",-1)),_(e("textarea",{"onUpdate:modelValue":t[1]||(t[1]=l=>d.value.content=l),rows:"12",required:"",class:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500",disabled:i.value},null,8,ye),[[D,d.value.content]])]),e("div",ge,[_(e("input",{id:"isPublic","onUpdate:modelValue":t[2]||(t[2]=l=>d.value.isPublic=l),type:"checkbox",class:"w-5 h-5 text-primary-600 border-gray-300 rounded focus:ring-primary-500",disabled:i.value},null,8,we),[[U,d.value.isPublic]]),e("label",_e,[e("div",ke,[n(r(C),{size:18,class:"mr-2 text-blue-600"}),t[9]||(t[9]=e("span",null,"Öffentliche News (auf Startseite anzeigen)",-1))]),t[10]||(t[10]=e("p",{class:"text-xs text-gray-600 mt-1 ml-6"}," Wenn aktiviert, wird diese News auch für nicht angemeldete Besucher auf der Startseite sichtbar. ",-1))])]),m.value?(a(),o("div",Ne,[n(r(R),{size:20,class:"mr-2"}),f(" "+u(m.value),1)])):c("",!0),e("div",ze,[e("button",{type:"button",onClick:w,class:"px-6 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 transition-colors",disabled:i.value}," Abbrechen ",8,De),e("button",{type:"submit",class:"px-6 py-2 bg-primary-600 hover:bg-primary-700 text-white font-semibold rounded-lg transition-colors flex items-center",disabled:i.value},[i.value?(a(),q(r(S),{key:0,size:20,class:"animate-spin mr-2"})):c("",!0),e("span",null,u(i.value?"Speichert...":"Speichern"),1)],8,Se)])],32)])])):c("",!0)])]))}};export{je as default};