import{d as y,Q as _,h as r,o,F as g,p as h,j as c,b as d,n as C,k as f,g as k,W as l}from"./app-Cb9hmj6k.js";import{t as p}from"./index-bRFR14ax.js";const I={class:"space-y-2"},b={class:"flex items-center justify-between group"},x=["onClick"],S=["onClick"],$={key:0,class:"pl-4 border-l ml-2"},V=y({__name:"CategoryTree",props:{items:{},activeId:{}},emits:["select"],setup(B,{emit:m}){const n=m;function u(t){confirm("Удалить категорию?")&&l.delete(`/documentation/categories/${t}`,{preserveScroll:!0,onSuccess:()=>{p.success("Категория удалена"),l.reload({only:["categories"]})},onError:()=>{p.error("Нельзя удалить категорию")}})}return(t,a)=>{const v=_("CategoryTree",!0);return o(),r("div",I,[(o(!0),r(g,null,h(t.items,e=>{var i;return o(),r("div",{key:e.id},[c("div",b,[c("div",{class:C(["cursor-pointer text-sm px-2 py-1 rounded-md transition",{"bg-primary/10 text-primary font-medium":e.id===t.activeId,"hover:text-primary":e.id!==t.activeId}]),onClick:s=>n("select",e.id)},f(e.name),11,x),t.$page.props.auth.user.role==="admin"?(o(),r("button",{key:0,class:"opacity-0 group-hover:opacity-100 text-red-500 text-xs cursor-pointer",onClick:s=>u(e.id)}," ✕ ",8,S)):d("",!0)]),(i=e.children)!=null&&i.length?(o(),r("div",$,[k(v,{items:e.children,activeId:t.activeId,onSelect:a[0]||(a[0]=s=>n("select",s))},null,8,["items","activeId"])])):d("",!0)])}),128))])}}});export{V as _};
