import{_ as L}from"./BOhf1Bbf.js";import{s as M,j as b,k as z,al as T,l as q,d as H,e as C,m as r,w as I,o as c,b as t,G as k,c as _,t as d,D as K,I as O,H as g,K as $,F as w,g as R}from"./Bgmy51Qv.js";import{u as j}from"./7pZkuj9N.js";import"./CNIrc0EA.js";import"./DZl4_Bww.js";import"./AmaTRG5a.js";import"./BHvLfWtM.js";import"./DuSynPle.js";import"./B2895E6R.js";import"./D_7E8SMU.js";const E={class:"input-wrapper"},J=["placeholder"],Q={key:0,class:"error"},W={class:"input-wrapper"},X={class:"b-b mb-10 mb-md-15 pb-10"},Y={for:"styled-checkbox-all",class:"mtb-5"},Z=["id","value","onChange"],ee=["for"],se={class:"permission-item"},te=["id","value"],le=["for"],fe={__name:"[id]",setup(oe){const P=j(),{allPermissions:p}=M(P),{getAllList:S}=P,v=b(!1),i=b([]),l=b([]),a=b({id:"",name:"",updated_permissions:[],permissions:[]}),V=z(()=>{var e;return(e=a.value)==null?void 0:e.permissions});T(V,e=>{l.value=e==null?void 0:e.map(s=>s.id)});const B=(e,s)=>e.reduce((n,o)=>{const u=o[s];return n[u]||(n[u]=[]),n[u].push(o),n},{}),U=e=>x(e==null?void 0:e.replace("_"," ").split(".")[1]),A=e=>x(e==null?void 0:e.replace(/\.|_/g," ")),x=e=>(e==null?void 0:e.charAt(0).toUpperCase())+(e==null?void 0:e.slice(1)),D=()=>{if(i.value=[],l.value=[],v.value)for(let e in p.value)l.value.push(p.value[e].id),i.value.push(p.value[e].group_name);i.value=[...new Set(i.value)],a.value.updated_permissions=l.value},N=(e,s)=>{const n=p.value.filter(o=>o.group_name===e).map(o=>o.id);s.target.checked?l.value=[...new Set([...l.value,...n])]:l.value=l.value.filter(o=>n.indexOf(o)===-1),a.value.updated_permissions=l.value},F=()=>{i.value=[],v.value=!1,a.value.updated_permissions=l.value};return q(async()=>{p.value||await S({api:"allPermissions",action:"setAllPermissions"})}),(e,s)=>{const n=L;return r(p)?(c(),H(n,{key:0,ref:"dataPageRef","set-api":"setRole","get-api":"getRole","route-name":"roles-permissions","empty-store-variable":"allRoles",name:e.$t("dataPage.rPer"),"validation-keys":["name"],result:r(a),gate:"role",onResult:s[4]||(s[4]=o=>a.value=o)},{form:I(({hasError:o})=>[t("div",E,[t("label",null,d(e.$t("user.name")),1),k(t("input",{type:"text",placeholder:e.$t("user.name"),name:"title","onUpdate:modelValue":s[0]||(s[0]=u=>r(a).name=u),ref:"title",class:K({invalid:!r(a).name&&o})},null,10,J),[[O,r(a).name]]),!r(a).name&&o?(c(),_("span",Q,d(e.$t("category.req",{type:e.$t("user.name")})),1)):C("",!0)]),t("div",W,[t("label",null,d(e.$t("user.per")),1),t("div",X,[k(t("input",{class:"styled-checkbox",id:"styled-checkbox-all",type:"checkbox","onUpdate:modelValue":s[1]||(s[1]=u=>g(v)?v.value=u:null),onChange:D},null,544),[[$,r(v)]]),t("label",Y,d(e.$t("index.all")),1)]),(c(!0),_(w,null,R(B(r(p),"group_name"),(u,f,h)=>(c(),_("div",{key:h,class:"permission-group"},[t("div",null,[k(t("input",{"onUpdate:modelValue":s[2]||(s[2]=m=>g(i)?i.value=m:null),class:"styled-checkbox",id:`styled-checkbox-${f}`,type:"checkbox",value:f,onChange:m=>N(f,m)},null,40,Z),[[$,r(i)]]),t("label",{for:`styled-checkbox-${f}`,class:"mtb-5 mt-md-15"},d(A(f)),9,ee)]),t("div",se,[(c(!0),_(w,null,R(u,(m,y)=>(c(),_("span",{key:`${h}-${y}`,class:"mr-15"},[k(t("input",{"onUpdate:modelValue":s[3]||(s[3]=G=>g(l)?l.value=G:null),class:"styled-checkbox",id:`checkbox-${h}-${y}`,type:"checkbox",value:m.id,onChange:F},null,40,te),[[$,r(l)]]),t("label",{for:`checkbox-${h}-${y}`,class:"mtb-7-5"},d(U(m.name)),9,le)]))),128))])]))),128))])]),_:1},8,["name","result"])):C("",!0)}}};export{fe as default};
