1import{r as _,j as e}from"./vendor-react-peuzwvkd.js";import{B as l,W as C,aZ as M,a_ as Q,a$ as K,b0 as V,b9 as S,ba as D,p as h,bb as T,b2 as R,s as o,a9 as c}from"./index-tG1jKRbj.js";import{b as W,u as Z,c as y}from"./vendor-query-LZhhN4oj.js";import{I as N}from"./input-40VFulDI.js";import{L as n}from"./label-Cc5RjYmI.js";import{S as A}from"./switch-DcZ0L1UO.js";import{C as B,f as J,d as $}from"./calendar-BgfxG3-e.js";import{S as G,a as U,b as X,c as Y,d as k}from"./select-BX1F3UPh.js";import{A as ee,h as se,a as te,b as ae,c as re,d as ne,e as le,f as ie,g as oe}from"./alert-dialog-Bf9thPwG.js";import{T as ce,a as de,b as I,c as d,d as xe,e as x}from"./table-B0xTx1GG.js";import{I as me}from"./IconPlus-Cn_5MSRN.js";import{I as he}from"./IconPencil-BGAJhSwk.js";import{I as ue}from"./IconTrash-jEXsWaN_.js";import{I as F}from"./IconCalendar-D_AW-2DW.js";import"./vendor-router-BvT7G7vo.js";import"./vendor-recharts-DFJL7mCf.js";import"./vendor-supabase-C6T5JIOu.js";import"./index-Dbqi0AU3.js";import"./IconChevronLeft-XmPocaut.js";import"./index-BdQq_4o_.js";const b={text:"",bg_color:"#f9aa00",text_color:"#3d5261",start_date:new Date().toISOString().split("T")[0],end_date:new Date(Date.now()+30*864e5).toISOString().split("T")[0],display_on:"alle",active:!0};function Ee(){const u=W(),[q,j]=_.useState(!1),[i,g]=_.useState(null),[t,r]=_.useState(b),{data:p=[],isLoading:E}=Z({queryKey:["info-banners"],queryFn:async()=>{const{data:s,error:a}=await o.from("info_banners").select("*").order("created_at",{ascending:!1});if(a)throw a;return s}}),f=y({mutationFn:async()=>{const s={text:t.text,bg_color:t.bg_color,text_color:t.text_color,start_date:t.start_date,end_date:t.end_date,display_on:t.display_on,active:t.active};if(i){const{error:a}=await o.from("info_banners").update(s).eq("id",i.id);if(a)throw a}else{const{error:a}=await o.from("info_banners").insert(s);if(a)throw a}},onSuccess:()=>{u.invalidateQueries({queryKey:["info-banners"]}),c.success(i?"Banner aktualisiert":"Banner erstellt"),v()},onError:()=>c.error("Fehler beim Speichern")}),z=y({mutationFn:async s=>{const{error:a}=await o.from("info_banners").delete().eq("id",s);if(a)throw a},onSuccess:()=>{u.invalidateQueries({queryKey:["info-banners"]}),c.success("Banner gelöscht")},onError:()=>c.error("Fehler beim Löschen")}),O=y({mutationFn:async({id:s,active:a})=>{const{error:w}=await o.from("info_banners").update({active:a}).eq("id",s);if(w)throw w},onSuccess:()=>{u.invalidateQueries({queryKey:["info-banners"]})},onError:()=>c.error("Fehler beim Aktualisieren")}),P=()=>{g(null),r(b),j(!0)},L=s=>{g(s),r({text:s.text,bg_color:s.bg_color,text_color:s.text_color,start_date:s.start_date,end_date:s.end_date,display_on:s.display_on,active:s.active}),j(!0)},v=()=>{j(!1),g(null),r(b)},m=s=>{try{return J(new Date(s+"T00:00:00"),"dd.MM.yyyy",{locale:$})}catch{return s}},H=s=>{if(!s.active)return!1;const a=new Date().toISOString().split("T")[0];return a>=s.start_date&&a<=s.end_date};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Info-Banner"}),e.jsxs(l,{onClick:P,className:"bg-[#00A0DC] hover:bg-[#008bbf] text-white",children:[e.jsx(me,{className:"mr-2 h-4 w-4"})," Neues Banner"]})]}),p.filter(H).map(s=>e.jsxs("div",{className:"rounded-md overflow-hidden",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Vorschau:"}),e.jsx("div",{className:"px-4 py-2.5 text-center text-sm font-semibold",style:{backgroundColor:s.bg_color,color:s.text_color},children:s.text})]},s.id)),E?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(C,{size:48})}):p.length===0?e.jsx("div",{className:"rounded-lg border border-dashed p-8 text-center text-muted-foreground",children:"Noch keine Banner angelegt."}):e.jsx("div",{className:"rounded-md border bg-card",children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(I,{children:[e.jsx(d,{children:"Text"}),e.jsx(d,{children:"Zeitraum"}),e.jsx(d,{children:"Anzeige"}),e.jsx(d,{children:"Aktiv"}),e.jsx(d,{className:"w-24"})]})}),e.jsx(xe,{children:p.map(s=>e.jsxs(I,{children:[e.jsx(x,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:s.bg_color}}),e.jsx("span",{className:"font-medium truncate max-w-[300px]",children:s.text})]})}),e.jsxs(x,{className:"text-muted-foreground text-xs whitespace-nowrap",children:[m(s.start_date)," â ",m(s.end_date)]}),e.jsx(x,{className:"text-muted-foreground text-xs",children:s.display_on==="startseite"?"Nur Startseite":"Alle Seiten"}),e.jsx(x,{children:e.jsx(A,{checked:s.active,onCheckedChange:a=>O.mutate({id:s.id,active:a})})}),e.jsx(x,{children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(l,{variant:"ghost",size:"icon",onClick:()=>L(s),children:e.jsx(he,{className:"h-4 w-4"})}),e.jsxs(ee,{children:[e.jsx(se,{asChild:!0,children:e.jsx(l,{variant:"ghost",size:"icon",children:e.jsx(ue,{className:"h-4 w-4 text-destructive"})})}),e.jsxs(te,{children:[e.jsxs(ae,{children:[e.jsx(re,{children:"Banner l
1öschen?"}),e.jsx(ne,{children:"Das Banner wird unwiderruflich gelöscht."})]}),e.jsxs(le,{children:[e.jsx(ie,{children:"Abbrechen"}),e.jsx(oe,{onClick:()=>z.mutate(s.id),children:"Löschen"})]})]})]})]})})]},s.id))})]})}),e.jsx(M,{open:q,onOpenChange:s=>!s&&v(),children:e.jsxs(Q,{className:"max-w-lg",children:[e.jsx(K,{children:e.jsx(V,{children:i?"Banner bearbeiten":"Neues Banner"})}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(n,{children:"Banner-Text *"}),e.jsx(N,{value:t.text,onChange:s=>r({...t,text:s.target.value}),placeholder:"z.B. ð Aktion: Jetzt 50⬠Bonus sichern!"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(n,{children:"Hintergrundfarbe"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"color",value:t.bg_color,onChange:s=>r({...t,bg_color:s.target.value}),className:"w-10 h-10 rounded cursor-pointer border border-input"}),e.jsx(N,{value:t.bg_color,onChange:s=>r({...t,bg_color:s.target.value}),className:"flex-1 text-sm"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(n,{children:"Textfarbe"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"color",value:t.text_color,onChange:s=>r({...t,text_color:s.target.value}),className:"w-10 h-10 rounded cursor-pointer border border-input"}),e.jsx(N,{value:t.text_color,onChange:s=>r({...t,text_color:s.target.value}),className:"flex-1 text-sm"})]})]})]}),t.text&&e.jsxs("div",{children:[e.jsx(n,{className:"text-xs text-muted-foreground",children:"Vorschau:"}),e.jsx("div",{className:"mt-1 px-4 py-2.5 text-center text-sm font-semibold rounded",style:{backgroundColor:t.bg_color,color:t.text_color},children:t.text})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(n,{children:"Startdatum"}),e.jsxs(S,{children:[e.jsx(D,{asChild:!0,children:e.jsxs(l,{variant:"outline",className:h("w-full justify-start text-left font-normal"),children:[e.jsx(F,{className:"mr-2 h-4 w-4"}),m(t.start_date)]})}),e.jsx(T,{className:"w-auto p-0",align:"start",children:e.jsx(B,{mode:"single",selected:new Date(t.start_date+"T00:00:00"),onSelect:s=>s&&r({...t,start_date:s.toISOString().split("T")[0]}),initialFocus:!0,className:h("p-3 pointer-events-auto")})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(n,{children:"Enddatum"}),e.jsxs(S,{children:[e.jsx(D,{asChild:!0,children:e.jsxs(l,{variant:"outline",className:h("w-full justify-start text-left font-normal"),children:[e.jsx(F,{className:"mr-2 h-4 w-4"}),m(t.end_date)]})}),e.jsx(T,{className:"w-auto p-0",align:"start",children:e.jsx(B,{mode:"single",selected:new Date(t.end_date+"T00:00:00"),onSelect:s=>s&&r({...t,end_date:s.toISOString().split("T")[0]}),initialFocus:!0,className:h("p-3 pointer-events-auto")})})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(n,{children:"Anzeige auf"}),e.jsxs(G,{value:t.display_on,onValueChange:s=>r({...t,display_on:s}),children:[e.jsx(U,{children:e.jsx(X,{})}),e.jsxs(Y,{children:[e.jsx(k,{value:"alle",children:"Alle Seiten"}),e.jsx(k,{value:"startseite",children:"Nur Startseite"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(A,{checked:t.active,onCheckedChange:s=>r({...t,active:s})}),e.jsx(n,{children:"Banner aktiv"})]})]}),e.jsxs(R,{children:[e.jsx(l,{variant:"outline",onClick:v,children:"Abbrechen"}),e.jsxs(l,{onClick:()=>f.mutate(),disabled:!t.text.trim()||f.isPending,children:[f.isPending&&e.jsx(C,{size:16,className:"mr-2"}),i?"Speichern":"Erstellen"]})]})]})})]})}export{Ee 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.