import{d as C,T as $,k as V,m as M,r as P,c,o as r,a as e,b as _,l as E,t as d,v as N,u as p,F as v,g,n as S,x as A,h as B}from"./app-Do7K7VDV.js";import{_ as I}from"./AdminLayout-DeT_GLTC.js";import{V as O}from"./AssetModal-C18ToIEK.js";import"./ToastrContainer-CtYDvNPN.js";import"./_plugin-vue_export-helper-DlAUqK2U.js";import"./InputFieldError-0BmYlL24.js";const T={class:"space-y-6"},w={class:"card"},D={class:"card-body"},F={class:"mb-3"},G={for:"customCheck12",class:"toggle toggle-sm"},R=["checked"],j={class:"label label-md"},q={class:"grid grid-cols-12"},z={class:"col-span-3"},L={class:"flex items-center gap-2"},U=["onChange","checked","id","value","data-class"],H=["for"],J=["onChange","checked","id","value"],K=["for"],Q={class:"card-footer"},W=C({layout:I}),te=Object.assign(W,{__name:"Create",props:["permissions_groups"],setup(h){const m=h,n=$({permissions:[],name:null}),l=V([]),f=M(()=>m.permissions_groups.length===l.value.length),b=()=>{if(l.value=[],n.permissions.length<1){m.permissions_groups.forEach(o=>{l.value.push(o.group_name),o.permissions.forEach(s=>{n.permissions.push(s.name)})});return}n.permissions=[]},k=o=>{const s=l.value.indexOf(o);s!==-1?l.value.splice(s,1):l.value.push(o);const u=m.permissions_groups.filter(t=>l.value.includes(t.group_name)).flatMap(t=>t.permissions.map(i=>i.name));n.permissions=l.value.length>=1?u:[]},x=o=>{const s=n.permissions.indexOf(o);s!==-1?n.permissions.splice(s,1):n.permissions.push(o)},y=()=>{n.post(route("admin.role.store"),{onSuccess:()=>{n.reset()}})};return(o,s)=>{const u=P("Icon");return r(),c("div",T,[e("div",w,[e("div",D,[e("div",F,[e("label",null,d(o.trans("Role Name")),1),E(e("input",{type:"text",class:"input",required:"",name:"name",placeholder:"sub admin","onUpdate:modelValue":s[0]||(s[0]=t=>p(n).name=t)},null,512),[[N,p(n).name]])]),_(O),e("div",null,[e("label",G,[e("input",{checked:f.value,onInput:b,class:"toggle-input peer sr-only",id:"customCheck12",type:"checkbox"},null,40,R),s[1]||(s[1]=e("div",{class:"toggle-body"},null,-1)),e("span",j,d(o.trans("Check All Permissions")),1)])]),s[3]||(s[3]=e("hr",null,null,-1)),(r(!0),c(v,null,g(h.permissions_groups,(t,i)=>(r(),c("div",{class:"mt-3",key:t.key},[e("div",q,[e("div",z,[e("div",L,[e("input",{onChange:a=>k(t.group_name),checked:l.value.includes(t.group_name),type:"checkbox",class:"checkbox",id:i+"Management",value:t.group_name,"data-class":`role-${i}-management-checkbox`},null,40,U),e("label",{class:"label",for:i+"Management"},d(t.group_name),9,H)])]),e("div",{class:S(`col-span-9 role-${i}-management-checkbox`)},[(r(!0),c(v,null,g(t.permissions,a=>(r(),c("div",{class:"flex items-center gap-2",key:a.id},[e("input",{onChange:X=>x(a.name),checked:p(n).permissions.includes(a.name),type:"checkbox",class:"checkbox",name:"permissions[]",id:`checkPermission${a.id}`,value:a.name},null,40,J),e("label",{class:"label",for:`checkPermission${a.id}`},d(a.name),9,K)]))),128)),s[2]||(s[2]=e("br",null,null,-1))],2)])]))),128))]),e("div",Q,[e("button",{onClick:A(y,["prevent"]),type:"submit",class:"btn btn-primary"},[_(u,{icon:"bx:save"}),B(" "+d(o.trans("Save")),1)])])])])}}});export{te as default};
