import{k as $,r as p,g as j,h as A,c as r,a as e,j as c,b as i,d as f,u as a,F as E,i as F,l as z,t as u,m as _,v as D,B as I,p as U,o,U as q}from"#entry";import{u as G}from"./C_U-NUAd.js";import{P as H}from"./R6Iy1jPP.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}from"./6EY4_GXp.js";import{T as K}from"./FF_cyd6S.js";import{N as O}from"./DAACT36i.js";import{A as R}from"./C8kQt0fa.js";const J={class:"min-h-full py-16 bg-gray-50"},Q={class:"max-w-4xl mx-auto px-4 sm:px-6 lg:px-8"},X={class:"flex justify-between items-center mb-6"},Y={key:0,class:"flex items-center justify-center py-12"},Z={key:1,class:"space-y-6"},ee={class:"flex justify-between items-start mb-4"},te={class:"flex-1"},se={class:"flex items-center space-x-3 mb-2"},le={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"},ae={class:"flex items-center"},ie={class:"flex items-center"},ne={key:0,class:"flex items-center"},de={key:0,class:"flex space-x-2 ml-4"},ce=["onClick"],ue=["onClick"],me={class:"prose prose-lg max-w-none text-gray-700 whitespace-pre-wrap"},pe={key:0,class:"text-center py-12"},fe={key:0,class:"text-gray-400 text-sm mt-2"},be={class:"bg-white rounded-xl shadow-2xl max-w-3xl w-full p-8 max-h-[90vh] overflow-y-auto"},xe={class:"text-2xl font-display font-bold text-gray-900 mb-6"},ve=["disabled"],he=["disabled"],ye={class:"flex items-center space-x-3 p-4 bg-blue-50 rounded-lg border border-blue-200"},ge=["disabled"],we={for:"isPublic",class:"text-sm font-medium text-gray-900 cursor-pointer flex-1"},_e={class:"flex items-center"},ke={key:0,class:"flex items-center p-3 rounded-md bg-red-50 text-red-700 text-sm"},Ne={class:"flex justify-end space-x-4 pt-4"},ze=["disabled"],De=["disabled"],Ee={__name:"news",setup(Se){const k=$(),v=p(!0),n=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=""},T=async()=>{n.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{n.value=!1}},B=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()}),G({title:"Interne News - Harheimer TC"}),(s,t)=>(o(),r("div",J,[e("div",Q,[e("div",X,[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?(o(),r("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"},[i(a(H),{size:20,class:"mr-2"}),t[3]||(t[3]=f(" News erstellen ",-1))])):c("",!0)]),v.value?(o(),r("div",Y,[i(a(S),{size:40,class:"animate-spin text-primary-600"})])):(o(),r("div",Z,[(o(!0),r(E,null,F(h.value,l=>(o(),r("article",{key:l.id,class:"bg-white rounded-xl shadow-lg p-6 border border-gray-100"},[e("div",ee,[e("div",te,[e("div",se,[e("h2",le,u(l.title),1),l.isPublic?(o(),r("span",oe,[i(a(C),{size:14,class:"mr-1"}),t[5]||(t[5]=f(" Öffentlich ",-1))])):c("",!0)]),e("div",re,[e("div",ae,[i(a(q),{size:16,class:"mr-1"}),f(" "+u(l.author),1)]),e("div",ie,[i(a(W),{size:16,class:"mr-1"}),f(" "+u(N(l.created)),1)]),l.updated!==l.created?(o(),r("div",ne,[i(a(P),{size:16,class:"mr-1"}),f(" Aktualisiert: "+u(N(l.updated)),1)])):c("",!0)])]),y.value?(o(),r("div",de,[e("button",{onClick:V=>L(l),class:"p-2 text-blue-600 hover:bg-blue-50 rounded-lg transition-colors",title:"Bearbeiten"},[i(a(P),{size:20})],8,ce),e("button",{onClick:V=>B(l),class:"p-2 text-red-600 hover:bg-red-50 rounded-lg transition-colors",title:"Löschen"},[i(a(K),{size:20})],8,ue)])):c("",!0)]),e("div",me,u(l.content),1)]))),128)),h.value.length===0?(o(),r("div",pe,[i(a(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?(o(),r("p",fe,' Klicken Sie auf "News erstellen", um die erste News zu veröffentlichen. ')):c("",!0)])):c("",!0)])),x.value?(o(),r("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",be,[e("h2",xe,u(b.value?"News bearbeiten":"News erstellen"),1),e("form",{onSubmit:z(T,["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:n.value},null,8,ve),[[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:n.value},null,8,he),[[D,d.value.content]])]),e("div",ye,[_(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:n.value},null,8,ge),[[I,d.value.isPublic]]),e("label",we,[e("div",_e,[i(a(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?(o(),r("div",ke,[i(a(R),{size:20,class:"mr-2"}),f(" "+u(m.value),1)])):c("",!0),e("div",Ne,[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:n.value}," Abbrechen ",8,ze),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:n.value},[n.value?(o(),U(a(S),{key:0,size:20,class:"animate-spin mr-2"})):c("",!0),e("span",null,u(n.value?"Speichert...":"Speichern"),1)],8,De)])],32)])])):c("",!0)])]))}};export{Ee as default};