import{r as o,o as w,a as d,b as r,d as e,f as k,F as b,j as M,t as c,y as j,q as m,v as f,x as A,k as u}from"./app-kAt5lVqd.js";const D={class:"p-8"},V={class:"flex justify-between items-center mb-6"},$={class:"grid grid-cols-1 md:grid-cols-3 gap-6"},E={class:"text-xl font-bold mb-2"},B={class:"text-gray-600 text-sm mb-4"},F={class:"flex justify-between items-center"},N=["onClick"],U=["onClick"],z={key:0,class:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50"},I={class:"bg-white rounded-lg w-full max-w-lg p-6"},L={class:"text-2xl font-bold mb-4"},S={class:"space-y-4"},q={class:"flex items-center"},H={__name:"Categories",setup(T){const g=o([]),v=o(!1),n=o(!1),l=o({name:"",description:"",is_active:!0}),i=o(null),p=async()=>{const{data:s}=await u.get("/admin/categories");g.value=s.data||s},_=s=>{l.value={...s},i.value=s.id,n.value=!0},y=async()=>{try{const s={...l.value,slug:l.value.name.toLowerCase().replace(/\s+/g,"-")};i.value?await u.put(`/admin/categories/${i.value}`,s):await u.post("/admin/categories",s),x(),p()}catch{alert("Failed to save category")}},h=async s=>{confirm("Delete this category?")&&(await u.delete(`/admin/categories/${s}`),p())},x=()=>{v.value=!1,n.value=!1,l.value={name:"",description:"",is_active:!0},i.value=null};return w(p),(s,a)=>(r(),d(b,null,[e("div",D,[e("div",V,[a[4]||(a[4]=e("h1",{class:"text-3xl font-bold"},"Category Management",-1)),e("button",{onClick:a[0]||(a[0]=t=>v.value=!0),class:"bg-green-500 text-white px-6 py-3 rounded-lg hover:bg-green-600"},"➕ Add Category")]),e("div",$,[(r(!0),d(b,null,M(g.value,t=>(r(),d("div",{key:t.id,class:"bg-white rounded-lg shadow p-6"},[e("h3",E,c(t.name),1),e("p",B,c(t.description),1),e("div",F,[e("span",{class:j([t.is_active?"bg-green-100 text-green-800":"bg-red-100 text-red-800","px-2 py-1 rounded text-sm"])},c(t.is_active?"Active":"Inactive"),3),e("div",null,[e("button",{onClick:C=>_(t),class:"text-blue-600 hover:text-blue-800 mr-3"},"Edit",8,N),e("button",{onClick:C=>h(t.id),class:"text-red-600 hover:text-red-800"},"Delete",8,U)])])]))),128))])]),v.value||n.value?(r(),d("div",z,[e("div",I,[e("h3",L,c(n.value?"Edit":"Add")+" Category",1),e("div",S,[m(e("input",{"onUpdate:modelValue":a[1]||(a[1]=t=>l.value.name=t),placeholder:"Category Name",class:"w-full px-4 py-2 border rounded"},null,512),[[f,l.value.name]]),m(e("textarea",{"onUpdate:modelValue":a[2]||(a[2]=t=>l.value.description=t),placeholder:"Description",class:"w-full px-4 py-2 border rounded"},null,512),[[f,l.value.description]]),e("label",q,[m(e("input",{"onUpdate:modelValue":a[3]||(a[3]=t=>l.value.is_active=t),type:"checkbox",class:"mr-2"},null,512),[[A,l.value.is_active]]),a[5]||(a[5]=e("span",null,"Active",-1))])]),e("div",{class:"flex justify-end space-x-3 mt-6"},[e("button",{onClick:x,class:"px-6 py-2 border rounded"},"Cancel"),e("button",{onClick:y,class:"px-6 py-2 bg-blue-500 text-white rounded"},"Save")])])])):k("",!0)],64))}};export{H as default};
