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