import{q as v,v as C,j as e,$ as A,Y as N}from"./app-BGey7YPf.js";import{A as P}from"./app-layout-mnJEmZ7X.js";import{C as T,a as H,b as L,c as y,d as D}from"./card-CgL3Iyx6.js";import{L as d}from"./label-BbSRpehS.js";import{I as S}from"./input-CGSIKYsG.js";import{H as w}from"./header-D0w47C-P.js";import{a as G,b as I,c as B,d as c,e as p,f as U,h as x}from"./table-C3FnqSRz.js";import{B as h}from"./button-D5r5edT8.js";import{C as u,A as $}from"./checkbox-B5y2oT9V.js";import{u as E}from"./use-toast-DGElh_6W.js";import{L as F,S as R}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 Y(){E();const{role:r,permissions:n}=v().props,{data:i,setData:l,errors:o,processing:m,post:j,reset:f}=C({name:r.name,selectedPermissions:r.permissions.map(s=>s.name),_method:"put"}),b=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),l("selectedPermissions",a)},g=s=>{const a=n.map(t=>t.name);l("selectedPermissions",s.target.checked?a:[])},k=s=>{s.preventDefault(),j(route("apps.roles.update",r.id),{onSuccess:()=>{f()}})};return e.jsxs(e.Fragment,{children:[e.jsx(A,{title:"Ubah Akses Group"}),e.jsx(w,{title:"Ubah Akses Group",subtitle:"Halaman ini digunakan untuk mengubah data akses group"}),e.jsx("div",{className:"p-6",children:e.jsxs(T,{children:[e.jsxs(H,{children:[e.jsx(L,{children:"Ubah Akses Group"}),e.jsx(y,{children:"Form ini digunakan untuk mengubah data akses group"})]}),e.jsx(D,{children:e.jsxs("form",{onSubmit:k,children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-2",children:[e.jsx(d,{children:"Nama Akses Group"}),e.jsx(S,{type:"text",name:"name",value:i.name,onChange:s=>l("name",s.target.value),placeholder:"Masukkan nama akses group"}),e.jsx("p",{className:"text-red-500 text-xs",children:o.name})]}),e.jsxs("div",{className:"mb-4 flex flex-col gap-2",children:[e.jsx(d,{children:"Hak Akses"}),e.jsx(G,{children:e.jsxs(I,{children:[e.jsx(B,{children:e.jsxs(c,{children:[e.jsx(p,{className:"w-[50px] text-center",children:e.jsx(u,{onChange:s=>g(s),checked:i.selectedPermissions.length===n.length})}),e.jsx(p,{children:"Nama Hak Akses"})]})}),e.jsx(U,{children:n.map((s,a)=>e.jsxs(c,{children:[e.jsx(x,{className:"w-[50px] text-center",children:e.jsx(u,{checked:i.selectedPermissions.includes(s.name),onChange:b,value:s.name,id:`permission-${a}`},a)}),e.jsx(x,{children:s.name})]},a))})]})}),e.jsx("p",{className:"text-red-500 text-xs",children:o.selectedPermissions})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{variant:"destructive",asChild:!0,children:e.jsxs(N,{href:"/apps/roles",children:[e.jsx($,{})," Kembali"]})}),e.jsxs(h,{variant:"default",type:"submit",disabled:m,children:[m?e.jsx(F,{className:"animate-spin"}):e.jsx(R,{})," Simpan Data"]})]})]})})]})})]})}Y.layout=r=>e.jsx(P,{children:r});export{Y as default};
