import{T as C,m as y,A as $,c,a as _,b as e,t as r,d as M,v as P,u as p,F as h,r as f,w as A,k as N,g as R,o as d,n as S}from"./app-13978987.js";import{_ as T}from"./AdminLayout-bd13ff9d.js";import{_ as V}from"./PageHeader-8c638686.js";import w from"./ValidationErrors-24b8746b.js";import"./dropdown-45d66330.js";const B={class:"container p-4 sm:p-6"},E={class:"space-y-6"},O={class:"card"},D={class:"card-body"},F={class:"mb-3"},G={for:"customCheck12",class:"toggle toggle-sm"},j=["checked"],q=e("div",{class:"toggle-body"},null,-1),z={class:"label label-md"},I=e("hr",null,null,-1),L={class:"grid grid-cols-12"},U={class:"col-span-3"},H={class:"flex items-center gap-2"},J=["onChange","checked","id","value","data-class"],K=["for"],Q=["onChange","checked","id","value"],W=["for"],X=e("br",null,null,-1),Y={class:"card-footer"},Z=e("i",{class:"fa fa-save"},null,-1),ee=R({layout:T}),ie=Object.assign(ee,{__name:"Create",props:["buttons","permissions_groups"],setup(u){const m=u,t=C({permissions:[],name:null}),l=y([]),v=$(()=>m.permissions_groups.length===l.value.length),g=()=>{if(l.value=[],t.permissions.length<1){m.permissions_groups.forEach(s=>{l.value.push(s.group_name),s.permissions.forEach(n=>{t.permissions.push(n.name)})});return}t.permissions=[]},b=s=>{const n=l.value.indexOf(s);n!==-1?l.value.splice(n,1):l.value.push(s);const o=m.permissions_groups.filter(i=>l.value.includes(i.group_name)).flatMap(i=>i.permissions.map(a=>a.name));t.permissions=l.value.length>=1?o:[]},k=s=>{const n=t.permissions.indexOf(s);n!==-1?t.permissions.splice(n,1):t.permissions.push(s)},x=()=>{t.post(route("admin.role.store"),{onSuccess:()=>{t.reset(),createToast({title:"Created",description:"Role Created successfully"},{transition:"slide",position:"top-right"})}})};return(s,n)=>(d(),c("main",B,[_(V,{title:s.trans("Create Role"),buttons:u.buttons},null,8,["title","buttons"]),e("div",E,[e("div",O,[e("div",D,[e("div",F,[e("label",null,r(s.trans("Role Name")),1),M(e("input",{type:"text",class:"input",required:"",name:"name",placeholder:"sub admin","onUpdate:modelValue":n[0]||(n[0]=o=>p(t).name=o)},null,512),[[P,p(t).name]])]),_(w),e("div",null,[e("label",G,[e("input",{checked:v.value,onInput:g,class:"toggle-input peer sr-only",id:"customCheck12",type:"checkbox"},null,40,j),q,e("span",z,r(s.trans("Check All Permissions")),1)])]),I,(d(!0),c(h,null,f(u.permissions_groups,(o,i)=>(d(),c("div",{class:"mt-3",key:o.key},[e("div",L,[e("div",U,[e("div",H,[e("input",{onChange:a=>b(o.group_name),checked:l.value.includes(o.group_name),type:"checkbox",class:"checkbox",id:i+"Management",value:o.group_name,"data-class":`role-${i}-management-checkbox`},null,40,J),e("label",{class:"label",for:i+"Management"},r(o.group_name)+" name ",9,K)])]),e("div",{class:S(`col-span-9 role-${i}-management-checkbox`)},[(d(!0),c(h,null,f(o.permissions,a=>(d(),c("div",{class:"flex items-center gap-2",key:a.id},[e("input",{onChange:se=>k(a.name),checked:p(t).permissions.includes(a.name),type:"checkbox",class:"checkbox",name:"permissions[]",id:`checkPermission${a.id}`,value:a.name},null,40,Q),e("label",{class:"label",for:`checkPermission${a.id}`},r(a.name),9,W)]))),128)),X],2)])]))),128))]),e("div",Y,[e("button",{onClick:A(x,["prevent"]),type:"submit",class:"btn btn-primary"},[Z,N(" "+r(s.trans("Save")),1)])])])])]))}});export{ie as default};
