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