1import{k as E,l as F,r as i,j as e,L,a1 as A,C as B,c as H,d as q,n as P,B as c,e as I,a2 as O,D as R,w as z,x as V,y as U,v as x,I as p,bd as Y,bp as $,s as u,q as n}from"./index-D6S94l3r.js";import{T as G}from"./textarea-zkxjn3Pk.js";import{T as J,a as K,b as y,c as l,d as M,e as d}from"./table-DNwFNVSx.js";import{P as Q}from"./plus-BOxbBXe6.js";import{P as W}from"./pencil-C_L5e1Pl.js";function te(){const{isAdmin:m,loading:f}=E(),g=F(),[v,w]=i.useState([]),[b,N]=i.useState(!0),[T,o]=i.useState(!1),[h,C]=i.useState(null),[a,r]=i.useState({name:"",color:"#888888",description:"",is_active:!0});i.useEffect(()=>{!f&&!m&&g("/")},[f,m,g]);const j=async()=>{N(!0);const{data:s,error:t}=await u.from("shift_types").select("*").order("name");t&&n.error(t.message),w(s??[]),N(!1)};i.useEffect(()=>{m&&j()},[m]);const _=()=>{C(null),r({name:"",color:"#888888",description:"",is_active:!0}),o(!0)},k=s=>{C(s),r({name:s.name,color:s.color,description:s.description??"",is_active:s.is_active}),o(!0)},D=async()=>{if(!a.name.trim()){n.error("Name is required");return}const s={name:a.name.trim(),color:a.color,description:a.description.trim()||null,is_active:a.is_active},{error:t}=h?await u.from("shift_types").update(s).eq("id",h.id):await u.from("shift_types").insert(s);if(t){n.error(t.message);return}n.success(h?"Updated":"Created"),o(!1),j()},S=async s=>{if(!confirm(`Delete shift type "${s.name}"?`))return;const{error:t}=await u.from("shift_types").delete().eq("id",s.id);if(t){n.error(t.message);return}n.success("Deleted"),j()};return f?null:e.jsxs("div",{className:"container py-8 max-w-5xl",children:[e.jsxs(L,{to:"/admin/config",className:"inline-flex items-center text-sm text-muted-foreground hover:text-foreground mb-4",children:[e.jsx(A,{className:"h-4 w-4 rotate-180 mr-1"}),"Back to admin config"]}
1),e.jsxs(B,{children:[e.jsxs(H,{className:"flex flex-row items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(q,{children:"Volunteer Shift Types"}),e.jsx(P,{children:"Categories of shift (e.g. Front of House, Bar, Sound, Lighting). Colours are used in the calendar view."})]}),e.jsxs(c,{onClick:_,children:[e.jsx(Q,{className:"h-4 w-4 mr-2"})," New shift type"]})]}),e.jsx(I,{children:b?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loadingâ¦"}):v.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No shift types yet."}):e.jsxs(J,{children:[e.jsx(K,{children:e.jsxs(y,{children:[e.jsx(l,{children:"Name"}),e.jsx(l,{children:"Colour"}),e.jsx(l,{children:"Description"}),e.jsx(l,{children:"Active"}),e.jsx(l,{className:"w-32"})]})}),e.jsx(M,{children:v.map(s=>e.jsxs(y,{children:[e.jsx(d,{className:"font-medium",children:s.name}),e.jsx(d,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-4 w-4 rounded",style:{backgroundColor:s.color}}),e.jsx("span",{className:"font-mono text-xs",children:s.color})]})}),e.jsx(d,{className:"text-sm text-muted-foreground",children:s.description}),e.jsx(d,{children:s.is_active?"Yes":"No"}),e.jsxs(d,{className:"text-right space-x-1",children:[e.jsx(c,{variant:"ghost",size:"icon",onClick:()=>k(s),children:e.jsx(W,{className:"h-4 w-4"})}),e.jsx(c,{variant:"ghost",size:"icon",onClick:()=>S(s),children:e.jsx(O,{className:"h-4 w-4"})})]})]},s.id))})]})})]}),e.jsx(R,{open:T,onOpenChange:o,children:e.jsxs(z,{children:[e.jsx(V,{children:e.jsx(U,{children:h?"Edit shift type":"New shift type"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"st-name",children:"Name"}),e.jsx(p,{id:"st-name",value:a.name,onChange:s=>r({...a,name:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"st-color",children:"Colour"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(p,{id:"st-color",type:"color",value:a.color,onChange:s=>r({...a,color:s.target.value}),className:"w-20 h-10 p-1"}),e.jsx(p,{value:a.color,onChange:s=>r({...a,color:s.target.value}),className:"font-mono"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"st-desc",children:"Description"}),e.jsx(G,{id:"st-desc",value:a.description,onChange:s=>r({...a,description:s.target.value}),rows:3})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(x,{htmlFor:"st-active",children:"Active"}),e.jsx(Y,{id:"st-active",checked:a.is_active,onCheckedChange:s=>r({...a,is_active:s})})]})]}),e.jsxs($,{children:[e.jsx(c,{variant:"outline",onClick:()=>o(!1),children:"Cancel"}),e.jsx(c,{onClick:D,children:"Save"})]})]})})]})}export{te 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.