1import{u as w,r as i,j as e,q as y,a5 as C,an as A,a1 as k,p as n}from"./index-CfXbMZ_V.js";import{C as z}from"./chevron-left-BFeklwt6.js";function B(){const f=w(),[d,c]=i.useState([]),[b,m]=i.useState(!0),[l,x]=i.useState(""),[u,g]=i.useState(""),[o,v]=i.useState(!1),[h,r]=i.useState(""),p=async()=>{m(!0);try{const t=await n.entities.Service.list("-created_date",200);c(t||[])}catch(t){r((t==null?void 0:t.message)||"Failed to load services")}finally{m(!1)}};i.useEffect(()=>{p()},[]);const j=async t=>{t.preventDefault();const s=l.trim();if(s){v(!0),r("");try{await n.entities.Service.create({name:s,description:u.trim(),active:!0}),x(""),g(""),await p()}catch(a){r((a==null?void 0:a.message)||"Could not add service")}finally{v(!1)}}},N=async t=>{try{await n.entities.Service.update(t.id,{active:!t.active}),c(s=>s.map(a=>a.id===t.id?{...a,active:!a.active}:a))}catch(s){r((s==null?void 0:s.message)||"Could not update service")}},S=async t=>{if(confirm(`Delete "${t.name}"? Accountants assigned to it will lose it from their booking page.`))try{await n.entities.Service.delete(t.id),c(s=>s.filter(a=>a.id!==t.id))}catch(s){r((s==null?void 0:s.message)||"Could not delete service")}};return e.jsxs("div",{className:"space-y-5 pb-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>f("/super"),className:"flex items-center justify-center w-11 h-11 rounded-xl bg-gray-100 hover:bg-gray-200 transition-colors shrink-0","aria-label":"Back",children:e.jsx(z,{size:20,className:"text-gray-700"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold text-gray-900",children:"Booking services"}),e.jsx("p",{className:"text-xs text-gray-500 mt-0.5",children:"Create services, then assign them to accountants on their activity page."})]})]}),h&&e.jsx("div",{className:"p-3 rounded-xl bg-red-50 border border-red-200 text-red-600 text-sm",children:h}),e.jsxs("form",{onSubmit:j,className:"bg-white border border-gray-100 rounded-2xl p-4 space-y-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-gray-900",children:"Add a service"}),e.jsx("input",{value:l,onChange:t=>x(t.target.value),placeholder:"Service name (e.g. Tax Planning)",className:"w-full border border-gray-200 rounded-xl px-3 py-2.5 text-sm outline-none focus:border-violet-400",style:{minHeight:44}}),e.jsx("input",{value:u,onChange:t=>g(t.target.value),placeholder:"Short description (optional)",className:"w-full border border-gray-200 rounded-xl px-3 py-2.5 text-sm outline-none focus:border-violet-400",style:{minHeight:44}}),e.jsxs("button",{type:"submit",disabled:o||!l.trim(),className:"w-full h-11 rounded-xl bg-violet-600 hover:bg-violet-700 text-white font-semibold flex items-center justify-center gap-2 disabled:opacity-50",children:[o?e.jsx(y,{size:16,className:"animate-spin"}):e.jsx(C,{size:16}),o?"Addingâ¦":"Add service"]})]}),e.jsxs("div",{className:"bg-white border border-gray-100 rounded-2xl p-4 space-y-2",children:[e.jsx("h2",{className:"text-sm font-semibold text-gray-900",children:"All services"}),b?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx(y,{className:"w-5 h-5 text-violet-500 animate-spin"})}):d.length===0?e.jsxs("div",{className:"flex flex-col items-center py-8 text-center",children:[e.jsx(A,{size:28,className:"text-gray-300 mb-2"}),e.jsx("p",{className:"text-sm text-gray-400",children:"No services yet. Add your first one above."})]}):e.jsx("div",{className:"space-y-2",children:d.map(t=>e.jsxs("div",{className:"flex items-center gap-3 border border-gray-100 rounded-xl p-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900 truncate",children:t.name}),t.description&&e.jsx("p",{className:"text-xs text-gray-500 truncate",children:t.description})]}),e.jsx("button",{onClick:()=>N(t),className:`text-xs font-semibold px-3 py-1.5 rounded-full ${t.active?"bg-emerald-100 text-emerald-700":"bg-gray-100 text-gray-500"}`,children:t.active?"Active":"Hidden"}),e.jsx("button",{onClick:()=>S(t),className:"flex items-center justify-center w-9 h-9 rounded-lg text-red-500 hover:bg-red-50 transition-colors","aria-label":`Delete ${t.name}`,children:e.jsx(k,{size:16})})]},t.id))})]})]})}export{B 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.