1import{j as e}from"./ui.DSlRn_VK.js";import{r as a,g as t}from"./vendor.-hzTlH9Y.js";import{supabase as s}from"./client.BXbBMsBT.js";import{c as r,i as n,j as i,f as l,B as o,e as c,k as d,l as m,m as h}from"./index.CWMBhjqx.js";import{I as x,L as u}from"./label.MI1FCLHZ.js";import{L as p,T as y}from"./textarea.Bprd7_8H.js";import{A as g,a as f,b as v,c as j}from"./accordion.ww_NbDHt.js";const b=r("Image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]]),k=r("Link",[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]]),N=r("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]),w=r("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]),C=r("Upload",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"17 8 12 3 7 8",key:"t8dd8p"}],["line",{x1:"12",x2:"12",y1:"3",y2:"15",key:"widbto"}]]),z=i("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function S({className:a,variant:t,...s}){return e.jsx("div",{className:n(z({variant:t}),a),...s})}const L=({onUploaded:t,keyHint:r})=>{const n=a.useRef(null),[i,c]=a.useState(!1),{toast:d}=l();return e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:n,type:"file",accept:"image/*",className:"hidden",onChange:e=>{var a;const i=null==(a=e.target.files)?void 0:a[0];i&&(async e=>{var a;if(e.type.startsWith("image/"))if(e.size>8388608)d({title:"Datei zu groÃ",description:"Maximal 8 MB.",variant:"destructive"});else{c(!0);try{const n=(null==(a=e.name.split(".").pop())?void 0:a.toLowerCase())||"jpg",i=`${r.replace(/[^a-z0-9_-]/gi,"_")}/${Date.now()}.${n}`,{error:l}=await s.storage.from("cms-images").upload(i,e,{cacheControl:"3600",upsert:!1,contentType:e.type});if(l)throw l;const{data:o}=s.storage.from("cms-images").getPublicUrl(i);t(o.publicUrl),d({title:"Bild hochgeladen",description:"URL wurde eingetragen."})}catch(i){const e=i instanceof Error?i.message:"Upload fehlgeschlagen";d({title:"Fehler",description:e,variant:"destructive"})}finally{c(!1),n.current&&(n.current.value="")}}else d({title:"Fehler",description:"Bitte eine Bilddatei wählen.",variant:"destructive"})})(i)}}),e.jsx(o,{type:"button",variant:"outline",size:"sm",onClick:()=>{var e;return null==(e=n.current)?void 0:e.click()},disabled:i,children:i?e.jsxs(e.Fragment,{children:[e.jsx(p,{className:"h-4 w-4 animate-spin"}),"Lade hochâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(C,{className:"h-4 w-4"}),"Bild hochladen"]})})]})},M=({entry:t,onSaved:r})=>{var n;const{rows:i}=c(),{toast:d}=l(),m=i[t.key],p=(null==m?void 0:m.value)??("text"===t.type?(null==(n=h[t.key])?void 0:n.de)??t.fallback:t.fallback),[g,f]=a.useState(p),[v,j]=a.useState(!1),N=g!==p;return e.jsxs("div",{className:"border border-border rounded-lg p-4 bg-card space-y-3",children:[e.jsx("div",{className:"flex items-start justify-between gap-3",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(u,{htmlFor:`field-${t.key}`,className:"font-medium",children:t.label}),e.jsxs(S,{variant:"outline",className:"gap-1 text-xs",children:[(C=t.type,"image"===C?e.jsx(b,{className:"h-3.5 w-3.5"}):"link"===C?e.jsx(k,{className:"h-3.5 w-3.5"}):e.jsx(w,{className:"h-3.5 w-3.5"})),t.type]}),m?e.jsx(S,{variant:"default",className:"text-xs",children:"CMS"}):e.jsx(S,{variant:"secondary",className:"text-xs",children:"Standard"})]}),e.jsx("p",{className:"font-mono text-[11px] text-muted-foreground mt-1 break-all",children:t.key})]})}),"text"===t.type&&e.jsx(y,{id:`field-${t.key}`,value:g,onChange:e=>f(e.target.value),rows:Math.min(8,Math.max(2,g.split("\n").length))}),"image"===t.type&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx(x,{id:`field-${t.key}`,type:"url",placeholder:"https://â¦/bild.webp oder Bild hochladen â",value:g,onChange:e=>f(e.target.value)}),e.jsx(L,{keyHint:t.key,onUploaded:e=>f(e)})]}),g&&e.jsxs("div",{className:"border border-border rounded-md p-2 bg-muted/30 inline-block",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Vorschau:"}),e.jsx("img",{src:g,alt:`Vorschau: ${t.label}`,className:"max-h-32 max-w-full rounded object-contain",onError:e=>{e.currentTarget.style.display="none"}})]})]}),"link"===t.type&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{id:`field-${t.key}`,type:"url",placeholder:"https://â¦",value:g,onChange:e=>f(e.target.value)}),g&&e.jsxs("a",{href:g,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary hover:underline inline-flex items-center gap-1",children:[e.jsx(k,{className:"h-3 w-3"}),"Link testen"]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[m&&e.jsx(o,{variant:"outline",size:"sm",onClick:async()=>{var e;j(!0);try{const{error:a}=await s.from("site_content").delete().eq("key",t.key);if(a)throw a;const n="text"===t.type?(null==(e=h[t.key])?void 0:e.de)??t.fallback:t.fallback;f(n),await r(),d({title:"Auf Standard zurückgesetzt",description:t.label})}catch(a){const e=a instanceof Error?a.message:"Unbekannter Fehler";d({title:"Fehler",description:e,variant:"destructive"})}finally{j(!1)}},disabled:v,children:"Zurücksetzen"}),e.jsx(o,{size:"sm",onClick:async()=>{j(!0);try{const{error:e}=await s.from("site_content").upsert({key:t.key,value:g,type:t.type,category:t.category},{onConflict:"key"});if(e)throw e;await r(),d({title:"Gespeichert",description:t.label})}catch(e){const a=e instanceof Error?e.message:"Unbekannter Fehler";d({title:"Fehler",description:a,variant:"destructive"})}finally{j(!1)}},disabled:v||!N,children:v?"Speichereâ¦":"Speichern"})]})]});var C},$=()=>{const r=t(),{rows:n,refresh:i}
1=c(),[l,h]=a.useState(""),u=a.useMemo(()=>{var e;const a=l.trim().toLowerCase(),t=new Map;for(const s of d)t.set(s,[]);for(const s of m){if(a){if(!`${s.key} ${s.label} ${s.category}`.toLowerCase().includes(a))continue}null==(e=t.get(s.category))||e.push(s)}return Array.from(t.entries()).filter(([,e])=>e.length>0)},[l]),p=Object.keys(n).length;return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"border-b border-border bg-card sticky top-0 z-10",children:e.jsxs("div",{className:"container mx-auto px-4 py-4 flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"font-serif text-xl font-semibold",children:"CMS Admin"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[m.length," Inhalte · ",p," angepasst"]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx(o,{variant:"outline",size:"sm",onClick:()=>r("/"),children:"Zur Website"}),e.jsxs(o,{variant:"outline",size:"sm",onClick:async()=>{await s.auth.signOut(),r("/admin/login",{replace:!0})},children:[e.jsx(N,{className:"h-4 w-4"}),"Logout"]})]})]})}),e.jsxs("main",{className:"container mx-auto px-4 py-8 max-w-4xl",children:[e.jsx("div",{className:"mb-6",children:e.jsx(x,{placeholder:"Suche nach Bezeichnung, Key oder Kategorieâ¦",value:l,onChange:e=>h(e.target.value)})}),0===u.length?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"Keine Inhalte gefunden."}):e.jsx(g,{type:"multiple",defaultValue:u.map(([e])=>e),className:"space-y-3",children:u.map(([a,t])=>e.jsxs(f,{value:a,className:"border border-border rounded-lg bg-card px-4",children:[e.jsx(v,{className:"hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"font-serif text-lg",children:a}),e.jsx(S,{variant:"secondary",children:t.length})]})}),e.jsx(j,{className:"pt-2 pb-4",children:e.jsx("div",{className:"space-y-3",children:t.map(a=>e.jsx(M,{entry:a,onSaved:i},a.key))})})]},a))})]})]})};export{$ as default};
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.