import{d as P,h as S,r as d,o as t,c as o,a as s,F as x,j as D,t as E,D as B,l as N,i as V,z as A,e as _,x as y,f as k,k as w,p as R,E as F,S as U,U as I}from"../index.js";import{$ as M}from"./jquery-Ce1xMU6f.js";import"../vendor.js";const T={class:"modal-dialog"},j={class:"modal-content"},z=s("h3",{class:"modal-title"},"Role Permissions",-1),q=s("span",{"aria-hidden":"true"},"×",-1),G=[q],H={class:"modal-body"},J={key:0,class:"fa-3x fas fa-circle-notch fa-spin"},K={key:0},O={key:1},Q=s("br",null,null,-1),W={class:"text-muted mt-0"},X=P({__name:"PermissionsModal",emits:["closed"],setup(L,{expose:v,emit:C}){const p=S(),i=d(!1),u=d(""),c=d(null),r=d([]),f=d([]),$=C;v({show:g,close:m});async function b(l){i.value=!0,u.value=l,f.value=[];try{const e=await p.roles.byId(u.value).permissions.get()??[];r.value=e.sort((n,h)=>n.localeCompare(h))}catch(e){console.error(e);const n=e;f.value=n.errors??[],B({type:"error",text:"Load role permissions failed."}),m()}finally{i.value=!1}}function g(l){M(c.value).modal("show"),b(l)}function m(){M(c.value).modal("hide"),$("closed"),a()}function a(){f.value=[],r.value=[]}return(l,e)=>(t(),o("div",{ref_key:"modalElement",ref:c,class:"modal fade",role:"dialog"},[s("div",T,[s("form",j,[s("div",{class:"modal-header"},[z,s("button",{type:"button",class:"close","data-dismiss":"modal","aria-label":"Close",onClick:m},G)]),s("div",H,[i.value?(t(),o("i",J)):(t(),o(x,{key:1},[r.value&&r.value.length>0?(t(),o("ul",K,[(t(!0),o(x,null,D(r.value,n=>(t(),o("li",{key:n},E(n),1))),128))])):(t(),o("p",O," (none) "))],64)),Q,s("small",W,"Role Id: "+E(u.value),1)]),s("div",{class:"modal-footer"},[s("button",{type:"button",class:"btn btn-outline-secondary","data-dismiss":"modal","aria-label":"Close",onClick:m}," Close ")])])])],512))}}),Y={class:"card"},Z={class:"card-header"},ss=s("i",{class:"fa fa-sync"},null,-1),es={class:"mb-0"},ts=s("span",{class:"fa fa-plus"},null,-1),os={class:"card-body col-md-6 offset-md-6"},as=s("i",{class:"fa-3x fas fa-circle-notch fa-spin"},null,-1),ls=[as],ns={class:"table-responsive"},is={key:0,class:"table table-striped table-hover card-body mb-0"},cs=s("thead",null,[s("tr",null,[s("th",null,"Role"),s("th",null," ")])],-1),ds={class:"nowrap align-middle"},rs={class:"nowrap align-middle"},us={key:0,class:"float-right"},_s=["onClick","disabled"],ms=s("i",{class:"fa fa-edit"},null,-1),hs=["onClick"],fs=s("i",{class:"fa fa-lock"},null,-1),bs=["onClick","disabled"],vs=s("i",{class:"fa fa-trash"},null,-1),ps={class:"float-right"},ys=["onClick","disabled"],ks=s("i",{class:"fa fa-trash"},null,-1),ws=P({__name:"Roles",setup(L){const v=N(),C=S(),p=F(),i=d(!1),u=d([]),c=d(-1),r=d(null);V(async()=>{await b()});function f(a){r.value.show(a.id)}async function $(a){c.value=-1,(await fetch(`${U.rolesBaseUrl}/${a.id}`,{method:"DELETE"})).ok&&(B({type:"info",text:"Role has been removed."}),await b())}async function b(){i.value=!0;try{u.value=await C.roles.get()??[]}catch(a){console.error(a),B({type:"error",text:"Load roles failed."})}finally{i.value=!1}}async function g(){await p.push({path:"/admin/roles/add"})}async function m(a){await p.push({path:`/admin/roles/${a.id}`})}return(a,l)=>(t(),o("div",null,[A(X,{ref_key:"permissionsModal",ref:r},null,512),s("div",Y,[s("div",Z,[s("button",{class:"float-right btn-sm btn btn-outline-primary rounded-pill",onClick:l[0]||(l[0]=e=>b())},[ss,_(" Refresh ")]),s("h3",es,[_(" Roles  "),y(v).checkPermission(y(I).AdministrationModify)?(t(),o("button",{key:0,class:"btn btn-sm btn-outline-primary",onClick:g},[ts,_(" New Role ")])):k("",!0)])]),w(s("div",os,ls,512),[[R,i.value]]),w(s("div",ns,[u.value.length?(t(),o("table",is,[cs,s("tbody",null,[(t(!0),o(x,null,D(u.value,(e,n)=>(t(),o("tr",{key:e.id},[s("td",ds,E(e.name),1),s("td",rs,[y(v).checkPermission(y(I).AdministrationModify)?(t(),o("span",us,[s("button",{title:"",class:"btn btn-sm btn-outline-primary mr-1",onClick:h=>m(e),disabled:e.isBuiltIn},[ms,_(" Edit ")],8,_s),s("button",{title:"",class:"btn btn-sm btn-outline-primary mr-1",onClick:h=>f(e)},[fs,_(" Permissions ")],8,hs),c.value!=n?(t(),o("button",{key:0,class:"btn btn-sm btn-outline-danger",onClick:h=>c.value=n,disabled:e.isBuiltIn},[vs,_(" Delete ")],8,bs)):k("",!0),w(s("span",ps,[s("button",{class:"btn btn-sm btn-outline-secondary",onClick:l[1]||(l[1]=h=>c.value=-1)}," Cancel "),s("button",{class:"btn btn-sm btn-danger",onClick:h=>$(e),disabled:i.value||e.isBuiltIn},[ks,_(" Confirm ")],8,ys)],512),[[R,c.value===n]])])):k("",!0)])]))),128))])])):k("",!0)],512),[[R,!i.value]])])]))}});export{ws as default};
