1import{k1 as L,E as M,j$ as D,a7 as I,r as S,j as e,v as B,L as U}from"./index-Cz_StzOF.js";import{u as z}from"./useSuspenseQuery-C53WRaHC.js";import{B as A}from"./button-DLLlTj8W.js";import{T as F,a as P,b as T,c as m,d as Q,e as i}from"./table-BPvFjWXk.js";import{A as R}from"./admin-filter-bar-Dd_-CSon.js";import{A as $}from"./admin-page-header-Bn0eJ8kD.js";import{s as H}from"./sponsor-tiers-x6wpc-TC.js";import{t as q,r as O,d as X}from"./sponsor-write.actions-BTrbS4Qm.js";function E({deletingId:x,emptyMessage:g,onDelete:u,onMove:j,onToggleActive:f,publicBaseUrl:t,reordering:p,sponsors:a,tier:l,title:b,togglingId:v}){const h=a.map(s=>s.id);return e.jsxs("div",{"data-testid":`sponsor-section-${l}`,children:[e.jsx("h2",{className:"mb-3 font-semibold text-lg",children:b}),e.jsx("div",{className:"overflow-hidden rounded-xl border shadow-sm",children:e.jsxs(F,{children:[e.jsx(P,{children:e.jsxs(T,{children:[e.jsx(m,{children:"Logo"}),e.jsx(m,{children:"Name"}),e.jsx(m,{children:"Link"}),e.jsx(m,{className:"w-28",children:"Active"}),e.jsx(m,{className:"w-28",children:"Order"}),e.jsx(m,{className:"w-32 text-right",children:"Actions"})]})}),e.jsxs(Q,{children:[a.length===0&&e.jsx(T,{children:e.jsx(i,{className:"py-8 text-center text-muted-foreground",colSpan:6,children:g})}),a.map((s,d)=>e.jsxs(T,{children:[e.jsx(i,{children:e.jsx("div",{className:"flex items-center justify-center rounded",style:{backgroundColor:"#002442",height:"36px",width:"80px"},children:e.jsx("img",{alt:s.name,src:B(s.logoUrl,t)??"",style:{filter:"brightness(0) invert(1)",height:"24px",objectFit:"contain",width:"auto"}})})}),e.jsx(i,{className:"font-medium",children:s.name}),e.jsx(i,{className:"text-muted-foreground text-sm",children:s.linkUrl??"â"}),e.jsx(i,{onClick:y=>{y.stopPropagation(),f(s.id,s.active)},children:e.jsx("button",{"aria-label":s.active?"Deactivate sponsor":"Activate sponsor",className:"flex h-6 w-10 items-center rounded-full transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:v===s.id,style:{backgroundColor:s.active?"var(--color-primary, #114c97)":"#d1d5db"},type:"button",children:e.jsx("span",{className:"ml-1 h-4 w-4 rounded-full bg-white transition-transform",style:{transform:s.active?"translateX(16px)":"translateX(0)"}})})}),e.jsx(i,{children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(A,{"aria-label":"Move up",disabled:d===0||p,onClick:()=>j(l,h,d,-1),size:"sm",type:"button",variant:"outline",children:"â"}),e.jsx(A,{"aria-label":"Move down",disabled:d===a.length-1||p,onClick:()=>j(l,h,d,1),size:"sm",type:"button",variant:"outline",children:"â"})]})}),e.jsx(i,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(A,{asChild:!0,size:"sm",variant:"outline",children:e.jsx(U,{params:{sponsorId:s.id},to:"/admin/website/sponsors/$sponsorId",children:"Edit"})}),e.jsx(A,{disabled:x===s.id,onClick:()=>u(s.id,s.name),size:"sm",type:"button",variant:"destructive",children:x===s.id?"â¦":"Delete"})]})})]},s.id))]})]})})]})}function K(){const{data:x}=z(L()),{publicBaseUrl:g}=M(),u=D(),j=I(),[f,t]=S.useState(null),[p,a]=S.useState(null),[l,b]=S.useState(null),[v,h]=S.useState(!1),{lead:s,standard:d}=H(x),y=async(n,c)=>{a(n),t(null);try{await q({data:{id:n,active:!c}}),await u.invalidate()}catch(o){t(o instanceof Error?o.message:"Failed to update sponsor")}finally{a(null)}},k=async(n,c,o,w)=>{const N=o+w;if(!(N<0||N>=c.length)){h(!0),t(null);try{const r=[...c];[r[o],r[N]]=[r[N],r[o]],await O({data:{orderedIds:r,tier:n}}),await u.invalidate()}catch(r){t(r instanceof Error?r.message:"Failed to reorder sponsors")}finally{h(!1)}}},C=async(n,c)=>{if(window.confirm(`Delete "${c}"? This cannot be undone.`)){b(n),t(null);try{await X({data:{id:n}}),await j.invalidateQueries({queryKey:["sponsors"]}),await u.invalidate()}catch(w){t(w instanceof Error?w.message:"Failed to delete sponsor")}finally{b(null)}}};return e.jsxs("section",{className:"px-4 py-8",children:[e.jsx($,{actions:e.jsx(R,{to:"/admin/website/sponsors/new",children:"Add sponsor"}),eyebrow:"Admin",title:"Sponsors"}),f&&e.jsx("p",{className:"mb-4 rounded-md border border-destructive/30 bg-destructive/10 p-3 text-destructive text-sm",children:f}),e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(E,{deletingId:l,emptyMessage:"No lead sponsors yet. Edit a sponsor and tick âLead sponsorâ to feature it here.",onDelete:C,onMove:k,onToggleActive:y,publicBaseUrl:g,reordering:v,sponsors:s,tier:"lead",title:"Lead sponsors",togglingId:p}),e.jsx(E,{deletingId:l,emptyMessage:"No sponsors yet. Add one to get started.",onDelete:C,onMove:k,onToggleActive:y,publicBaseUrl:g,reordering:v,sponsors:d,tier:"standard",title:"Sponsors",togglingId:p})]})]})}function se(){return e.jsx(K,{})}export{se 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.