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