1import{r as i,s as v,j as t,L as W}from"./index-CLTM18rh.js";import{u as Y}from"./AdminContext-B2hLlcqc.js";import{CATEGORY_META as g,SUBCATEGORY_META as y}from"./Kreis4Map-BzlzrI8Z.js";import{N as H}from"./NurLesen-BKsmfvXD.js";import{A as Q}from"./Aktivitaet-Blgc-LAk.js";import{A as Z}from"./AuditLogViewer-CgrB1xOp.js";import"./TileLayer-DpZblqbA.js";import"./Popup-7uc8Qs2p.js";import"./hooks-DsPkwVqL.js";import"./authFetch-u5HjDcUX.js";import"./Filterleiste-Dovi1-bW.js";function J(){return t.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 20 20",children:t.jsx("path",{d:"M7 2a2 2 0 110 4 2 2 0 010-4zm6 0a2 2 0 110 4 2 2 0 010-4zM7 8a2 2 0 110 4 2 2 0 010-4zm6 0a2 2 0 110 4 2 2 0 010-4zm-6 6a2 2 0 110 4 2 2 0 010-4zm6 0a2 2 0 110 4 2 2 0 010-4z"})})}function K(x){const c=Array.isArray(x.images)?x.images:[];return(c.find(u=>u.hero)??c.find(u=>!u.historical)??c[0])?.url??null}function ce({onEdit:x,onNew:c}){const{permissions:u}=Y(),z=u.perm_unterwegs,[a,j]=i.useState([]),[F,D]=i.useState(!0),[m,I]=i.useState(""),[l,_]=i.useState(null),[h,b]=i.useState(null),[k,T]=i.useState(!1),[N,q]=i.useState(!1),[d,p]=i.useState(null),[G,f]=i.useState(null),[C,w]=i.useState(null),[S,A]=i.useState(!1);async function B(){A(!0),w(null);try{const{data:{session:e}}=await v.auth.getSession(),n=await fetch("/api/admin/unterwegs-summaries",{method:"POST",headers:{Authorization:`Bearer ${e?.access_token??""}`}}),r=await n.json();w(n.ok?r.message??`${r.updated} Kurztexte erzeugt${r.total?` (von ${r.total})`:""}.`:r.error??"Fehler")}catch(e){w(e instanceof Error?e.message:"Fehler")}finally{A(!1)}}i.useEffect(()=>{v.from("unterwegs_stations").select("id, slug, title, category, subcategory, lat, lng, is_published, sort_order, draft_updated_at, images").order("title",{ascending:!0}).then(({data:e})=>{j(e??[]),D(!1)})},[]);const P=Object.keys(g).filter(e=>a.some(n=>n.category===e)),R=l?[...new Set(a.filter(e=>e.category===l&&e.subcategory).map(e=>e.subcategory))].sort((e,n)=>(y[e]??e).localeCompare(y[n]??n,"de")):[],O=a.filter(e=>(!m.trim()||e.title.toLowerCase().includes(m.toLowerCase()))&&(!l||e.category===l)&&(!h||e.subcategory===h)&&(!k||!e.is_published)&&(!N||e.draft_updated_at!=null)),E=a.filter(e=>e.lat==null).length,$=a.filter(e=>!e.is_published).length,M=a.filter(e=>e.draft_updated_at!=null).length,o=z&&!!l&&!m.trim()&&!k,L=[...O].sort((e,n)=>o&&(e.sort_order??1e9)-(n.sort_order??1e9)||e.title.localeCompare(n.title,"de"));async function U(e){const n=new Map(e.map((r,s)=>[r.id,s]));j(r=>r.map(s=>n.has(s.id)?{...s,sort_order:n.get(s.id)}:s)),await Promise.all(e.map((r,s)=>v.from("unterwegs_stations").update({sort_order:s}).eq("id",r.id)))}function V(e){if(d===null||d===e){p(null),f(null);return}const n=[...L],[r]=n.splice(d,1);n.splice(e,0,r),p(null),f(null),U(n)}return t.jsxs("div",{className:"max-w-4xl",children:[t.jsx(H,{recht:"perm_unterwegs"}),t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("h1",{className:"text-2xl font-bold text-zinc-900 dark:text-white",children:"Kreis 4 unterwegs"}),t.jsxs("div",{className:"flex items-center gap-4",children:[t.jsx(Q,{titel:"Kreis 4 unterwegs",hinweis:"Stationen und thematische Rundgänge mit ihren Ãnderungen sowie die Review-Mails an die Verantwortlichen.",children:t.jsx(Z,{filter:{or:"target_type.eq.unterwegs_station,target_type.eq.unterwegs_rundgang,target_type.eq.mail_unterwegs"},labelFor:e=>({unterwegs_station_created:"Station angelegt",unterwegs_station_updated:"Station geändert",unterwegs_station_deleted:"Station gelöscht",unterwegs_rundgang_created:"Rundgang angelegt",unterwegs_rundgang_updated:"Rundgang geändert",unterwegs_rundgang_deleted:"Rundgang gelöscht",mail_sent:"Review-Mail versendet",mail_failed:"Review-Mail gescheitert"})[e]??e,colorFor:e=>e.endsWith("_deleted")||e==="mail_failed"?"bg-red-500":e.endsWith("_created")?"bg-green-500":e==="mail_sent"?"bg-red-400":"bg-zinc-400",limit:300})}),z&&t.jsx("button",{onClick:c,className:"text-sm font-medium text-white bg-red-600 hover:bg-red-700 px-4 py-2 rounded-lg transition-colors",children:"+ Neue Station"})]})]}),t.jsxs("p",{className:"text-sm text-zinc-500 dark:text-zinc-400 mb-3",children:[a.length," Stationen",E>0?` · ${E} ohne Koordinaten`:""]}),z&&t.jsxs("div",{className:"flex items-center gap-3 mb-5",children:[t.jsx("button",{onClick:B,disabled:S,className:"text-sm font-medium px-3 py-1.5 rounded-lg border border-zinc-200 dark:border-zinc-700 text-zinc-600 dark:text-zinc-300 hover:border-red-300 hover:text-red-600 transition-colors disabled:opacity-50",children:S?"Erzeuge KI-Kurztexteâ¦":"KI-Kurztexte für Rundgang erzeugen"}),C&&t.jsx("span",{className:"text-xs text-zinc-500 dark:text-zinc-400",children:C}),t.jsx(W,{to:"/admin/unterwegs/rundgaenge",className:"text-sm font-medium px-3 py-1.5 rounded-lg border border-zinc-200 dark:border-zinc-700 text-zinc-600 dark:text-zinc-300 hover:border-red-300 hover:text-red-600 transition-colors",children:"Thematische Rundgänge verwalten"})]}),t.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[t.jsxs("button",{onClick:()=>{_(null),b(null)},className:`px-3 py-1 text-xs font-medium rounded-full transition-colors ${l===null?"bg-zinc-900 text-white dark:bg-white dark:text-zinc-900":"bg-zinc-100 dark:bg-zinc-800 text-zinc-600 dark:text-zinc-300 hover:bg-zinc-200"}`,children:["Alle (",a.length,")"]}),$>0&&t.jsxs("button",{onClick:()=>T(e=>!e),className:`px-3 py-1 text-xs font-medium rounded-full transition-colors ${k?"bg-amber-500 text-white":"bg-amber-50 dark:bg-amber-950/30 text-amber-700 dark:text-amber-400 hover:bg-amber-100"}`,children:["Versteckte (",$,")"]}),M>0&&t.jsxs("button",{onClick:()=>q(e=>!e),className:`px-3 py-1 text-xs font-medium rounded-full transition-colors ${N?"bg-sky-600 text-white":"bg-sky-50 dark:bg-sky-950/30 text-sky-700 dark:text-sky-400 hover:bg-sky-100"}`,children:["Zu prüfen (",M,")"]}),P.map(e=>{const n=a.filter(s=>s.category===e).length,r=l===e;return t.jsxs("button",{onClick:()=>{_(r?null:e),b(null)},className:`inline-flex items-center gap-1.5 px-3 py-1 text-xs font-medium rounded-full transition-colors ${r?"text-white":"bg-zinc-100 dark:bg-zinc-800 text-zinc-600 dark:text-zinc-300 hover:bg-zinc-200"}`,style:r?{backgroundColor:g[e].color}:void 0,children:[t.jsx("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:r?"white":g[e].
1color}}),g[e].label," (",n,")"]},e)})]}),l&&R.length>0&&t.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3 pl-1 border-l-2 border-zinc-200 dark:border-zinc-700",children:[t.jsx("button",{onClick:()=>b(null),className:`ml-1.5 px-2.5 py-0.5 text-xs rounded-full transition-colors ${h===null?"bg-zinc-700 text-white dark:bg-zinc-200 dark:text-zinc-900":"bg-zinc-100 dark:bg-zinc-800 text-zinc-500 dark:text-zinc-400 hover:bg-zinc-200"}`,children:"Alle Unterkategorien"}),R.map(e=>{const n=a.filter(s=>s.category===l&&s.subcategory===e).length,r=h===e;return t.jsxs("button",{onClick:()=>b(r?null:e),className:`px-2.5 py-0.5 text-xs rounded-full transition-colors ${r?"bg-red-600 text-white":"bg-zinc-100 dark:bg-zinc-800 text-zinc-500 dark:text-zinc-400 hover:bg-zinc-200"}`,children:[y[e]??e," (",n,")"]},e)})]}),t.jsx("input",{value:m,onChange:e=>I(e.target.value),placeholder:"Station suchenâ¦",className:"w-full mb-2 px-3 py-2 text-sm rounded-lg border border-zinc-200 dark:border-zinc-700 bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white placeholder:text-zinc-400 focus:outline-none focus:ring-2 focus:ring-red-500"}),t.jsxs("p",{className:"text-xs text-zinc-400 mb-4",children:[O.length," angezeigt"]}),F?t.jsx("p",{className:"text-sm text-zinc-400",children:"Ladenâ¦"}):t.jsx("ul",{className:"divide-y divide-zinc-100 dark:divide-zinc-800 rounded-xl border border-zinc-200 dark:border-zinc-800 overflow-hidden",children:L.map((e,n)=>t.jsx("li",{draggable:o,onDragStart:o?()=>p(n):void 0,onDragOver:o?r=>{r.preventDefault(),f(n)}:void 0,onDrop:o?()=>V(n):void 0,onDragEnd:o?()=>{p(null),f(null)}:void 0,className:`transition-colors ${G===n&&d!==null&&d!==n?"bg-red-50 dark:bg-red-950/20":d===n?"opacity-40 bg-zinc-50 dark:bg-zinc-800/50":""}`,children:t.jsxs("button",{onClick:()=>x(e.slug),className:"w-full flex items-center gap-3 px-4 py-3 text-left hover:bg-zinc-50 dark:hover:bg-zinc-800/50 transition-colors",children:[o&&t.jsx("span",{className:"text-zinc-300 dark:text-zinc-600 cursor-grab active:cursor-grabbing shrink-0",children:t.jsx(J,{})}),K(e)?t.jsx("img",{src:K(e),alt:"",loading:"lazy",className:"w-11 h-11 rounded object-cover shrink-0 bg-zinc-100 dark:bg-zinc-800"}):t.jsx("div",{className:"w-11 h-11 rounded shrink-0 bg-zinc-100 dark:bg-zinc-800 flex items-center justify-center text-zinc-300 dark:text-zinc-600 text-lg",children:"·"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-sm font-medium text-zinc-900 dark:text-white truncate",children:e.title}),t.jsx("p",{className:"text-xs text-zinc-400 mt-0.5",children:g[e.category]?.label??e.category??"â ohne Kategorie"})]}),e.lat==null&&t.jsx("span",{className:"text-xs text-amber-600 dark:text-amber-400 bg-amber-50 dark:bg-amber-950/30 px-2 py-0.5 rounded-full shrink-0",children:"kein Pin"}),!e.is_published&&t.jsx("span",{className:"text-xs text-zinc-500 bg-zinc-100 dark:bg-zinc-800 px-2 py-0.5 rounded-full shrink-0",children:"versteckt"}),e.draft_updated_at!=null&&t.jsx("span",{className:"text-xs text-sky-700 dark:text-sky-400 bg-sky-50 dark:bg-sky-950/30 px-2 py-0.5 rounded-full shrink-0",children:"Entwurf"}),t.jsx("svg",{className:"w-4 h-4 text-zinc-300 shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]})},e.id))})]})}export{ce as AdminUnterwegs};
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.