1import{r as i,j as t,s as b}from"./index-DeJ875KO.js";import{u as K}from"./AdminContext-DezprucX.js";import{I as q}from"./InlineTagEditor-D2e6A9-f.js";import{N as R}from"./NurLesen-D6aOATEr.js";import{R as W,F as O,a as P}from"./Filterleiste-D-uExNFA.js";import{b as $}from"./bestaetige-CpNFuPQa.js";import"./authFetch-B7xfneuy.js";function Y({onEdit:_,onNew:A}){const{permissions:C}=K(),f=C.perm_news,[a,k]=i.useState([]),[x,S]=i.useState([]),[T,z]=i.useState(!0),[j,v]=i.useState(null),[l,D]=i.useState(""),[c,L]=i.useState([]),[m,M]=i.useState("date-desc"),[h,B]=i.useState("active");async function w(){z(!0);const[{data:e},{data:r},{data:s}]=await Promise.all([b.from("news_articles").select("id, title, author, published_at, status, vernehmlassung_id").order("published_at",{ascending:!1}),b.from("tags").select("id, name").eq("for_news",!0).order("sort_order").order("name"),b.from("news_tags").select("article_id, tag_id")]),o=new Map((r??[]).map(n=>[n.id,n])),d=new Map;for(const n of s??[]){const N=o.get(n.tag_id);N&&(d.has(n.article_id)||d.set(n.article_id,[]),d.get(n.article_id).push(N))}k((e??[]).map(n=>({...n,tags:d.get(n.id)??[]}))),S(r??[]),z(!1)}i.useEffect(()=>{w()},[]);async function E(e,r){await $(`«${r}» wirklich löschen?`)&&(v(e),await b.from("news_articles").delete().eq("id",e),await w(),v(null))}function I(e,r){k(s=>s.map(o=>o.id!==e?o:{...o,tags:x.filter(d=>r.includes(d.id))}))}function F(e){L(r=>r.includes(e)?r.filter(s=>s!==e):[...r,e])}const g=i.useMemo(()=>{const e=new Date;return e.setMonth(e.getMonth()-6),e.toISOString().slice(0,10)},[]),u=e=>(e.published_at??"").slice(0,10)<g,y=i.useMemo(()=>({active:a.filter(e=>!u(e)).length,archived:a.filter(e=>u(e)).length}),[a,g]),p=i.useMemo(()=>{let e=a.filter(r=>h==="archived"?u(r):!u(r));if(c.length>0&&(e=e.filter(r=>r.tags.some(s=>c.includes(s.id)))),l.trim()){const r=l.trim().toLowerCase();e=e.filter(s=>s.title.toLowerCase().includes(r)||s.author?.toLowerCase().includes(r))}return[...e].sort((r,s)=>m==="date-asc"?r.published_at.localeCompare(s.published_at):m==="date-desc"?s.published_at.localeCompare(r.published_at):r.title.localeCompare(s.title,"de"))},[a,l,c,m,h,g]);return t.jsxs("div",{children:[t.jsx(R,{recht:"perm_news"}),t.jsxs("div",{className:"flex items-center justify-between mb-6",children:[t.jsx("h1",{className:"text-xl font-bold text-zinc-900 dark:text-white",children:"News"}),f&&t.jsxs("button",{onClick:A,className:"flex items-center gap-2 px-4 py-2 bg-red-600 hover:bg-red-700 text-white text-sm font-medium rounded-lg transition-colors",children:[t.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),"Neuer Artikel"]})]}),t.jsx(W,{aktiv:h,onWechsel:B,reiter:[{key:"active",label:"Aktiv",anzahl:y.active},{key:"archived",label:"Archiv",anzahl:y.archived}]}),t.jsx(O,{suche:l,onSuche:D,platzhalter:"Titel oder Text suchenâ¦",children:t.jsx(P,{wert:m,onWert:e=>M(e),titel:"Sortierung",optionen:[["date-desc","Datum â"],["date-asc","Datum â"],["title","Titel"]]})}),x.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1.5 mb-4",children:x.map(e=>{const r=c.includes(e.id);return t.jsx("button",{onClick:()=>F(e.id),className:`px-2.5 py-1 text-xs font-medium rounded-full border transition-colors ${r?"border-transparent text-white":"border-zinc-200 dark:border-zinc-700 text-zinc-500 dark:text-zinc-400 hover:border-zinc-300 dark:hover:border-zinc-600"}`,style:r?{backgroundColor:e.color??"#6b7280"}:void 0,children:e.name},e.id)})}),T?t.jsx("div",{className:"py-20 text-center text-zinc-400 text-sm",children:"Lädtâ¦"}):p.length===0?t.jsx("div",{className:"py-20 text-center text-zinc-400 text-sm",children:a.length===0?"Noch keine Artikel.":l.trim()||c.length>0?"Keine Treffer.":h==="archived"?"Keine archivierten Artikel (älter als 6 Monate).":"Keine aktuellen Artikel."}):t.jsxs("div",{className:"bg-white dark:bg-zinc-900 rounded-xl border border-zinc-200 dark:border-zinc-800 overflow-hidden",children:[t.jsxs("div",{className:"px-4 py-2 border-b border-zinc-100 dark:border-zinc-800 text-xs text-zinc-400",children:[p.length," ",(p.length===1,"Artikel")]}),t.jsxs("table",{className:"w-full text-sm",children:[t.jsx("thead",{children:t.jsxs("tr",{className:"border-b border-zinc-100 dark:border-zinc-800",children:[t.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-zinc-400 uppercase tracking-wider",children:"Datum"}),t.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-zinc-400 uppercase tracking-wider",children:"Titel"}),t.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-zinc-400 uppercase tracking-wider hidden md:table-cell",children:"Tags"}),t.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-zinc-400 uppercase tracking-wider hidden lg:table-cell",children:"Autor"}),t.jsx("th",{className:"px-4 py-3"})]})}),t.jsx("tbody",{className:"divide-y divide-zinc-100 dark:divide-zinc-800",children:p.map(e=>t.jsxs("tr",{className:"hover:bg-zinc-50 dark:hover:bg-zinc-800/50",children:[t.jsx("td",{className:"px-4 py-3 text-zinc-600 dark:text-zinc-400 whitespace-nowrap",children:e.published_at}),t.jsxs("td",{className:"px-4 py-3 font-medium text-zinc-900 dark:text-white",children:[e.title,e.status==="entwurf"&&t.jsx("span",{className:"ml-2 align-middle text-[11px] font-semibold uppercase tracking-wide px-1.5 py-0.5 rounded bg-zinc-100 dark:bg-zinc-800 text-zinc-500 border border-zinc-200 dark:border-zinc-700",children:"Entwurf"}),e.vernehmlassung_id&&t.jsx("span",{className:"ml-2 align-middle text-[11px] font-semibold uppercase tracking-wide px-1.5 py-0.5 rounded bg-amber-50 dark:bg-amber-950/40 text-amber-700 dark:text-amber-400 border border-amber-200 dark:border-amber-900",children:"Vernehmlassung"})]}),t.jsx("td",{className:"px-4 py-3 hidden md:table-cell",children:t.jsx(q,{itemId:e.id,tagIds:e.tags.map(r=>r.id),allTags:x,junctionTable:"news_tags",itemKey:"article_id",onChange:r=>I(e.id,r),readOnly:!f})}),t.jsx("td",{className:"px-4 py-3 text-zinc-500 dark:text-zinc-400 hidden lg:table-cell",children:e.author}),f&&t.jsx("td",{className:"px-4 py-3",children:t.jsxs("div",{className:"flex items-center justify-end gap-2",children:[t.jsx("button",{onClick:()=>_(e.id),className:"px-3 py-1.5 text-xs font-medium text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:hover:text-white border border-zinc-200 dark:border-zinc-700 hover:border-zinc-300 dark:hover:border-zinc-600 rounded-md transition-colors",children:"Bearbeiten"}),t.jsx("button",{onClick:()=>E(e.id,e.title),disabled:j===e.id,className:"px-3 py-1.5 text-xs font-medium text-red-600 dark:text-red-400 hover:text-red-700 border border-red-200 dark:border-red-900 hover:border-red-300 rounded-md transition-colors disabled:opacity-40",children:j===e.id?"â¦":"Löschen"})]})})]},e.id))})]})]})]})}export{Y as AdminNews}
vendor: 2 bytes, line 1
1;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.