import{_ as m}from"./TextField-BlXlwWsx.js";import{_ as T}from"./SlugField-BpBJsMXI.js";import{u as h}from"./useApi-C0u-srqq.js";import{L as w,a as C,u as U}from"./DateField.vue_vue_type_style_index_0_lang-BFhdkW_K.js";import{u as N}from"./useUnsavedChanges-BW4Wkrng.js";import{u as B}from"./useCmsUrl-BMH6Mdh_.js";import{A as S}from"./save-BiBE8Men.js";import{T as $}from"./trash-2-z3Bhtg-8.js";import{r as d,v as f,x as L,l as o,z as c,p as r,B as A,E as v,k as E,D as O,f as j}from"./x-CuOWXDIc.js";const q={class:"p-6"},D={class:"flex items-center justify-between mb-6"},I={class:"flex items-center gap-3"},J=["href"],z={class:"text-2xl font-bold text-neutral-900 dark:text-neutral-50"},F={class:"flex items-center gap-2"},G=["disabled"],H={class:"max-w-2xl space-y-4"},ee={__name:"Edit",props:{blockType:{type:Object,required:!0}},setup(b){const s=b,{put:y,del:k}=h(),n=U(),{confirm:x}=C(),{cmsUrl:p}=B(),i=d(!1),l=d({}),e=d({name:s.blockType.name||"",slug:s.blockType.slug||"",description:s.blockType.description||"",icon:s.blockType.icon||""}),g=JSON.stringify(e.value);N(j(()=>JSON.stringify(e.value)!==g));async function _(){if(await x({title:"Удалить тип блока?",message:`"${s.blockType.name}" будет удалён.`,variant:"danger",confirmText:"Удалить"}))try{await k(`/api/cms/block-types/${s.blockType.id}`),n.success("Удалён"),window.location.href=p("/block-types")}catch{n.error("Ошибка удаления")}}async function V(){i.value=!0,l.value={};try{await y(`/api/cms/block-types/${s.blockType.id}`,e.value),n.success("Тип блока сохранён")}catch(u){u.errors&&(l.value=u.errors),n.error("Ошибка сохранения")}finally{i.value=!1}}return(u,t)=>(f(),L("div",q,[o("div",D,[o("div",I,[o("a",{href:c(p)("/block-types"),class:"text-neutral-400 hover:text-neutral-600"},[r(c(S),{class:"w-5 h-5"})],8,J),o("h1",z,A(e.value.name||"Тип блока"),1)]),o("div",F,[o("button",{type:"button",class:"btn btn-danger-outline btn-md flex items-center gap-1.5",onClick:_},[r(c($),{class:"w-4 h-4"}),t[4]||(t[4]=v("Удалить",-1))]),o("button",{type:"button",class:"btn btn-primary btn-md flex items-center gap-1.5",disabled:i.value,onClick:V},[i.value?(f(),E(c(w),{key:0,class:"w-4 h-4 animate-spin"})):O("",!0),t[5]||(t[5]=v("Сохранить ",-1))],8,G)])]),o("div",H,[r(m,{modelValue:e.value.name,"onUpdate:modelValue":t[0]||(t[0]=a=>e.value.name=a),label:"Название",required:"",error:l.value.name},null,8,["modelValue","error"]),r(T,{modelValue:e.value.slug,"onUpdate:modelValue":t[1]||(t[1]=a=>e.value.slug=a),"source-value":e.value.name,error:l.value.slug},null,8,["modelValue","source-value","error"]),r(m,{modelValue:e.value.description,"onUpdate:modelValue":t[2]||(t[2]=a=>e.value.description=a),label:"Описание",type:"textarea",rows:3,error:l.value.description,placeholder:"Краткое описание типа блоков"},null,8,["modelValue","error"]),r(m,{modelValue:e.value.icon,"onUpdate:modelValue":t[3]||(t[3]=a=>e.value.icon=a),label:"Иконка",error:l.value.icon,placeholder:"Название иконки (напр. boxes)",hint:"Имя иконки из набора Lucide Icons"},null,8,["modelValue","error"])])]))}};export{ee as _};
