import{d as f,h as b,r as i,o as n,c as r,a as e,k as h,n as y,z as g,F as x,j as V,t as k,f as C,e as R,E as N,D as u}from"../index.js";import{_ as w,n as F}from"./PermissionList.vue_vue_type_script_setup_true_lang-C-HIQyD3.js";import"../vendor.js";const $={class:"card"},A=e("div",{class:"card-header"},[e("h3",{class:"mb-0"}," New Role ")],-1),B={class:"card-body"},D={class:"form-group"},T=e("label",{for:"nameField"},"Name",-1),U=e("h4",null,"Permissions",-1),q=e("br",null,null,-1),E={key:0,class:"alert alert-danger",role:"alert"},P={class:"card-footer text-right"},j=e("span",{class:"fa fa-plus"},null,-1),G=f({__name:"AddRole",setup(z){const m=b(),p=N(),s=i(""),d=i([]),o=i([]);async function v(){if(o.value=[],!!s.value)try{const l={name:s.value,permissions:d.value??[]};await m.roles.post(l),u({type:"success",text:`Role ${s.value} has been added.`}),await c()}catch(l){console.error(l);const t=l;o.value=t.errors??[],u({type:"error",text:`Role ${s.value} could not be added.`})}}async function c(){await F(p)}return(l,t)=>(n(),r("div",$,[A,e("div",B,[e("div",D,[T,h(e("input",{id:"nameField",type:"text",class:"form-control",required:"","onUpdate:modelValue":t[0]||(t[0]=a=>s.value=a)},null,512),[[y,s.value]])]),U,g(w,{modelValue:d.value,"onUpdate:modelValue":t[1]||(t[1]=a=>d.value=a)},null,8,["modelValue"]),q,o.value&&o.value.length>0?(n(),r("div",E,[(n(!0),r(x,null,V(o.value,(a,_)=>(n(),r("p",{key:_},k(a.message),1))),128))])):C("",!0)]),e("div",P,[e("button",{type:"button",class:"btn btn-outline-secondary","data-dismiss":"modal","aria-label":"Close",onClick:c}," Cancel "),e("button",{type:"button",class:"btn btn-success m-1",title:"Add role",onClick:t[2]||(t[2]=a=>v())},[j,R(" Add ")])])]))}});export{G as default};
