import{v as _,x as w,l as s,p as o,z as r,E as k,q as i,B as g,U as h,r as c}from"./x-CuOWXDIc.js";import{_ as V}from"./DataTable-Cq4CcFtv.js";import{_ as $}from"./Modal-DFk22f1Y.js";import{_ as C}from"./TextField-BlXlwWsx.js";import{_ as T}from"./SlugField-BpBJsMXI.js";import{u as B}from"./useApi-C0u-srqq.js";import{a as U,u as j}from"./DateField.vue_vue_type_style_index_0_lang-BFhdkW_K.js";import{u as P}from"./useCmsUrl-BMH6Mdh_.js";import{P as S}from"./ruler-IYY3v2Di.js";import{B as N}from"./zap-Dlr53vCB.js";import{P as q,T as A}from"./trash-2-z3Bhtg-8.js";const E={class:"p-6"},M={class:"flex items-center justify-between mb-6"},z={class:"font-mono text-sm text-neutral-500"},D={class:"flex items-center gap-1"},F=["href"],I=["onClick"],G={class:"py-12 text-center"},H={class:"flex items-center justify-end gap-2"},se={__name:"Index",props:{blockTypes:{type:Array,default:()=>[]}},setup(d){const{post:f,del:p}=B(),u=j(),{confirm:b}=U(),{cmsUrl:v}=P(),a=c(!1),l=c({name:"",slug:""}),x=[{field:"name",header:"Название",sortable:!0},{field:"slug",header:"Slug",sortable:!1},{field:"blocks_count",header:"Блоков",sortable:!1,width:"100px"}];async function m(){try{const n=await f("/api/cms/block-types",l.value);a.value=!1,u.success("Тип создан"),window.location.reload()}catch{u.error("Ошибка создания")}}async function y(n){if(await b({title:"Удалить тип блоков?",message:`Тип "${n.name}" будет удалён.`,variant:"danger",confirmText:"Удалить"}))try{await p(`/api/cms/block-types/${n.id}`),u.success("Удалён"),window.location.reload()}catch{u.error("Ошибка")}}return(n,e)=>(_(),w("div",null,[s("div",E,[s("div",M,[e[7]||(e[7]=s("h1",{class:"text-2xl font-bold text-neutral-900 dark:text-neutral-50"},"Типы блоков",-1)),s("button",{type:"button",class:"btn btn-primary btn-md flex items-center gap-1.5",onClick:e[0]||(e[0]=t=>a.value=!0)},[o(r(S),{class:"w-4 h-4"}),e[6]||(e[6]=k("Создать тип",-1))])]),o(V,{columns:x,data:d.blockTypes},{"column-slug":i(({row:t})=>[s("span",z,g(t.slug),1)]),actions:i(({row:t})=>[s("div",D,[s("a",{href:r(v)(`/block-types/${t.id}/edit`),class:"w-7 h-7 rounded flex items-center justify-center text-neutral-400 hover:text-primary-500 hover:bg-primary-50 transition-colors"},[o(r(q),{class:"w-3.5 h-3.5"})],8,F),s("button",{type:"button",class:"w-7 h-7 rounded flex items-center justify-center text-neutral-400 hover:text-error-500 hover:bg-error-50 transition-colors",onClick:J=>y(t)},[o(r(A),{class:"w-3.5 h-3.5"})],8,I)])]),empty:i(()=>[s("div",G,[o(r(N),{class:"w-10 h-10 text-neutral-300 mx-auto mb-2"}),e[8]||(e[8]=s("p",{class:"text-sm text-neutral-500"},"Нет типов блоков",-1))])]),_:1},8,["data"])]),o($,{modelValue:a.value,"onUpdate:modelValue":e[4]||(e[4]=t=>a.value=t),title:"Создать тип блоков",onClose:e[5]||(e[5]=t=>a.value=!1)},{footer:i(()=>[s("div",H,[s("button",{type:"button",class:"btn btn-secondary btn-md",onClick:e[3]||(e[3]=t=>a.value=!1)},"Отмена"),s("button",{type:"button",class:"btn btn-primary btn-md",onClick:m},"Создать")])]),default:i(()=>[s("form",{class:"space-y-4",onSubmit:h(m,["prevent"])},[o(C,{modelValue:l.value.name,"onUpdate:modelValue":e[1]||(e[1]=t=>l.value.name=t),label:"Название",required:""},null,8,["modelValue"]),o(T,{modelValue:l.value.slug,"onUpdate:modelValue":e[2]||(e[2]=t=>l.value.slug=t),"source-value":l.value.name},null,8,["modelValue","source-value"])],32)]),_:1},8,["modelValue"])]))}};export{se as _};
