import{q as g,v,j as e,$ as C,Y as T}from"./app-BGey7YPf.js";import{A}from"./app-layout-mnJEmZ7X.js";import{C as N,a as P,b as H,c as L,d as y}from"./card-CgL3Iyx6.js";import{L as m}from"./label-BbSRpehS.js";import{I as D}from"./input-CGSIKYsG.js";import{H as S}from"./header-D0w47C-P.js";import{a as w,b as G,c as I,d as c,e as d,f as B,h as p}from"./table-C3FnqSRz.js";import{B as x}from"./button-D5r5edT8.js";import{C as h,A as $}from"./checkbox-B5y2oT9V.js";import{u as F}from"./use-toast-DGElh_6W.js";import{L as R,S as Y}from"./save-Bm3_KHjE.js";import"./chevron-right-CE_1krjA.js";import"./separator-Di-l93J0.js";import"./icons-hx7HvmR4.js";import"./index-BFyaOBDQ.js";import"./x-C4WIHhXm.js";import"./index-Q2wK6uZI.js";import"./index-CwO5dfCw.js";import"./theme-provider-NKMbg-kV.js";import"./select-BqSuhmAT.js";import"./index-BuSoVzfP.js";import"./chevron-down-DOZGaFlM.js";function q(){F();const{permissions:r}=g().props,{data:i,setData:n,errors:l,processing:o,post:u,reset:j}=v({name:"",selectedPermissions:[]}),f=s=>{let a=i.selectedPermissions;a.some(t=>t===s.target.value)?a=a.filter(t=>t!==s.target.value):a.push(s.target.value),n("selectedPermissions",a)},b=s=>{const a=r.map(t=>t.name);n("selectedPermissions",s.target.checked?a:[])},k=s=>{s.preventDefault(),u(route("apps.roles.store"),{onSuccess:()=>{j()}})};return e.jsxs(e.Fragment,{children:[e.jsx(C,{title:"Tambah Akses Group"}),e.jsx(S,{title:"Tambah Akses Group",subtitle:"Halaman ini digunakan untuk menambahkan data akses group"}),e.jsx("div",{className:"p-6",children:e.jsxs(N,{children:[e.jsxs(P,{children:[e.jsx(H,{children:"Tambah Akses Group"}),e.jsx(L,{children:"Form ini digunakan untuk menambahkan data akses group"})]}),e.jsx(y,{children:e.jsxs("form",{onSubmit:k,children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-2",children:[e.jsx(m,{children:"Nama Akses Group"}),e.jsx(D,{type:"text",name:"name",value:i.name,onChange:s=>n("name",s.target.value),placeholder:"Masukkan nama akses group"}),e.jsx("p",{className:"text-red-500 text-xs",children:l.name})]}),e.jsxs("div",{className:"mb-4 flex flex-col gap-2",children:[e.jsx(m,{children:"Hak Akses"}),e.jsx(w,{children:e.jsxs(G,{children:[e.jsx(I,{children:e.jsxs(c,{children:[e.jsx(d,{className:"w-[50px] text-center",children:e.jsx(h,{onChange:s=>b(s),checked:i.selectedPermissions.length===r.length})}),e.jsx(d,{children:"Nama Hak Akses"})]})}),e.jsx(B,{children:r.map((s,a)=>e.jsxs(c,{children:[e.jsx(p,{className:"w-[50px] text-center",children:e.jsx(h,{checked:i.selectedPermissions.includes(s.name),onChange:f,value:s.name,id:`permission-${a}`},a)}),e.jsx(p,{children:s.name})]},a))})]})}),e.jsx("p",{className:"text-red-500 text-xs",children:l.selectedPermissions})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(x,{variant:"destructive",asChild:!0,children:e.jsxs(T,{href:"/apps/roles",children:[e.jsx($,{})," Kembali"]})}),e.jsxs(x,{variant:"default",type:"submit",disabled:o,children:[o?e.jsx(R,{className:"animate-spin"}):e.jsx(Y,{})," Simpan Data"]})]})]})})]})})]})}q.layout=r=>e.jsx(A,{children:r});export{q as default};
