1import{r as l,j as e,B as N,b as v,s as c}from"./main-HePXyMBG.js";import{I as w}from"./ImageUpload-BcOh6RdJ.js";import{P as y}from"./plus-Btqz4HeU.js";import{A as _,a as k}from"./arrow-up-LT5Cuo90.js";import{T as C}from"./trash-2-Bcb9cb1e.js";import{S}from"./save-CmT6ypEQ.js";function P(){const[s,h]=l.useState(null),[m,x]=l.useState(!1);async function a(){const{data:r}=await c.from("clients").select("id, name, logo_url, website_url, is_published, sort_order").order("sort_order",{ascending:!0});h(r||[])}l.useEffect(()=>{a()},[]);async function f(){if((s?.length||0)>=20){alert("Maximal 20 Logos möglich.");return}x(!0);const r=(s?.length||0)+1,{error:o}=await c.from("clients").insert({name:`Kunde ${r}`,logo_url:"/logo.png",sort_order:r});if(x(!1),o){alert(o.message);return}a()}async function p(r,o){const{error:t}=await c.from("clients").update(o).eq("id",r);if(t){alert(t.message);return}a()}async function i(r){confirm("Logo wirklich löschen?")&&(await c.from("clients").delete().eq("id",r),a())}async function b(r,o){if(!s)return;const t=s.findIndex(j=>j.id===r),u=t+o;if(t<0||u<0||u>=s.length)return;const d=s[t],g=s[u];await Promise.all([c.from("clients").update({sort_order:g.sort_order}).eq("id",d.id),c.from("clients").update({sort_order:d.sort_order}).eq("id",g.id)]),a()}return e.jsxs("div",{className:"max-w-5xl",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2 flex-wrap gap-3",children:[e.jsx("h1",{className:"text-3xl font-display font-bold",children:"Kundenlogos"}),e.jsxs(N,{onClick:f,variant:"hero",disabled:m||(s?.length||0)>=20,children:[m?e.jsx(v,{className:"animate-spin"}):e.jsx(y,{})," Logo hinzufügen"]})]}),e.jsx("p",{className:"text-muted-foreground mb-8",children:"Bis zu 20 Logos. Werden auf der Startseite in einem laufenden Band angezeigt â grau, beim Hover farbig."}),s===null?e.jsx("div",{className:"text-center py-10",children:e.jsx(v,{className:"h-5 w-5 animate-spin inline"})}):s.length===0?e.jsx("div",{className:"rounded-2xl border border-dashed border-border bg-background p-10 text-center text-muted-foreground",children:"Noch keine Logos angelegt."}):e.jsx("div",{className:"grid sm:grid-cols-2 gap-4",children:s.map((r,o)=>e.jsx(L,{client:r,first:o===0,last:o===s.length-1,onUpdate:t=>p(r.id,t),onDelete:()=>i(r.id),onMoveUp:()=>b(r.id,-1),onMoveDown:()=>b(r.id,1)},r.id))})]})}function L({client:s,first:h,last:m,onUpdate:x,onDelete:a,onMoveUp:f,onMoveDown:p}){const[i,b]=l.useState(s.name),[r,o]=l.useState(s.website_url||""),[t,u]=l.useState(s.logo_url),[d,g]=l.useState(s.is_published),j=i!==s.name||r!==(s.website_url||"")||t!==s.logo_url||d!==s.is_published;return e.jsxs("div",{className:"rounded-2xl border border-border bg-background p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("button",{onClick:f,disabled:h,className:"p-1 rounded text-muted-foreground hover:text-foreground disabled:opacity-30",title:"Nach oben",children:e.jsx(_,{className:"h-4 w-4"})}),e.jsx("button",{onClick:p,disabled:m,className:"p-1 rounded text-muted-foreground hover:text-foreground disabled:opacity-30",title:"Nach unten",children:e.jsx(k,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex-1",children:e.jsx(w,{value:t,onChange:n=>u(n||""),folder:"clients",label:"Logo"})}),e.jsx("button",{onClick:a,className:"p-2 rounded-lg text-muted-foreground hover:text-destructive hover:bg-destructive/10",title:"Löschen",children:e.jsx(C,{className:"h-4 w-4"})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"Name"}),e.jsx("input",{value:i,onChange:n=>b(n.target.value),className:"w-full px-3 py-2 rounded-lg bg-background border border-border focus:outline-none focus:border-primary/50 text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"Website (
1optional)"}),e.jsx("input",{value:r,onChange:n=>o(n.target.value),placeholder:"https://",className:"w-full px-3 py-2 rounded-lg bg-background border border-border focus:outline-none focus:border-primary/50 text-sm"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("label",{className:"inline-flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:d,onChange:n=>g(n.target.checked)}),"Sichtbar"]}),e.jsxs(N,{size:"sm",variant:"hero",disabled:!j||!t||!i.trim(),onClick:()=>x({name:i.trim(),logo_url:t,website_url:r.trim()||null,is_published:d}),children:[e.jsx(S,{className:"h-4 w-4"})," Speichern"]})]})]})}export{P as component};
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.