import{v as i,x as u,l as s,p as r,z as d,E as k,$,a7 as h,F as U,y as B,k as L,q as m,s as T,B as b,D as N,U as P,r as c,f as S}from"./x-CuOWXDIc.js";import{_ as q}from"./Modal-DFk22f1Y.js";import{_ as D}from"./ItemCard-AiAfmmeY.js";import{_ as F}from"./TextField-BlXlwWsx.js";import{_ as M}from"./SlugField-BpBJsMXI.js";import{u as z}from"./useApi-C0u-srqq.js";import{u as A}from"./DateField.vue_vue_type_style_index_0_lang-BFhdkW_K.js";import{u as E}from"./useCmsUrl-BMH6Mdh_.js";import{P as I}from"./ruler-IYY3v2Di.js";import{S as j}from"./search-ITz7hQUi.js";import{P as g}from"./zap-Dlr53vCB.js";const G={class:"templates-index"},H={class:"templates-index__header"},J={class:"templates-index__filters"},K={class:"templates-index__search"},O={key:0,class:"item-grid"},Q={key:1,class:"item-grid__empty"},R={class:"item-grid__empty-title"},W={class:"templates-index__modal-footer"},ie={__name:"Index",props:{templates:{type:Array,default:()=>[]}},setup(y){const p=y,{post:x}=z(),f=A(),{cmsUrl:v}=E(),l=c(""),o=c(!1),n=c({name:"",slug:""}),_=S(()=>{if(!l.value)return p.templates;const a=l.value.toLowerCase();return p.templates.filter(e=>{var t;return e.name.toLowerCase().includes(a)||((t=e.slug)==null?void 0:t.toLowerCase().includes(a))})}),V=a=>{switch(a.source){case"vendor":return"vendor";case"storage":return"storage";case"app":return"app";default:return a.source||"storage"}},C=a=>{switch(a.source){case"vendor":return"badge badge-neutral";case"storage":return"badge badge-info";case"app":return"badge badge-success";default:return"badge badge-neutral"}};async function w(){var a;try{const e=await x("/api/cms/templates",n.value);o.value=!1,f.success("Шаблон создан");const t=((a=e.data)==null?void 0:a.id)||e.id;t&&(window.location.href=v(`/templates/${t}/edit`))}catch{f.error("Ошибка создания")}}return(a,e)=>(i(),u("div",null,[s("div",G,[s("div",H,[e[9]||(e[9]=s("h1",{class:"templates-index__title"},"Шаблоны",-1)),s("button",{type:"button",class:"btn btn-primary btn-md",onClick:e[0]||(e[0]=t=>o.value=!0)},[r(d(I),{class:"icon-md"}),e[8]||(e[8]=k(" Создать шаблон ",-1))])]),s("div",J,[s("div",K,[r(d(j),{class:"templates-index__search-icon"}),$(s("input",{"onUpdate:modelValue":e[1]||(e[1]=t=>l.value=t),type:"text",placeholder:"Поиск шаблонов...",class:"input input-sm templates-index__search-input"},null,512),[[h,l.value]])])]),_.value.length?(i(),u("div",O,[(i(!0),u(U,null,B(_.value,t=>(i(),L(D,{key:t.id,href:d(v)(`/templates/${t.id}/edit`),title:t.name,image:t.screenshot_url},{icon:m(()=>[r(d(g),{class:"icon-xl"})]),badges:m(()=>[s("span",{class:T(C(t))},b(V(t)),3)]),_:2},1032,["href","title","image"]))),128))])):(i(),u("div",Q,[r(d(g),{class:"item-grid__empty-icon"}),s("p",R,b(l.value?"Шаблоны не найдены":"Нет шаблонов"),1),l.value?N("",!0):(i(),u("button",{key:0,type:"button",class:"btn btn-primary btn-sm",onClick:e[2]||(e[2]=t=>o.value=!0)}," Создать первый шаблон "))]))]),r(q,{modelValue:o.value,"onUpdate:modelValue":e[6]||(e[6]=t=>o.value=t),title:"Создать шаблон","body-class":"modal__body--visible",onClose:e[7]||(e[7]=t=>o.value=!1)},{footer:m(()=>[s("div",W,[s("button",{type:"button",class:"btn btn-secondary btn-md",onClick:e[5]||(e[5]=t=>o.value=!1)},"Отмена"),e[10]||(e[10]=s("button",{type:"submit",form:"create-template-form",class:"btn btn-primary btn-md"},"Создать",-1))])]),default:m(()=>[s("form",{id:"create-template-form",class:"templates-index__create-form",onSubmit:P(w,["prevent"])},[r(F,{modelValue:n.value.name,"onUpdate:modelValue":e[3]||(e[3]=t=>n.value.name=t),label:"Название",required:""},null,8,["modelValue"]),r(M,{modelValue:n.value.slug,"onUpdate:modelValue":e[4]||(e[4]=t=>n.value.slug=t),"source-value":n.value.name},null,8,["modelValue","source-value"])],32)]),_:1},8,["modelValue"])]))}};export{ie as _};
