import{q as N,v as w,j as e,$ as T,Y as R}from"./app-BGey7YPf.js";import{A as y}from"./app-layout-mnJEmZ7X.js";import{C as A,a as S,b as H,c as L,d as D}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 _,c as I,d as h,e as c,f as K,h as p}from"./table-C3FnqSRz.js";import{B as u}from"./button-D5r5edT8.js";import{C as j,A as P}from"./checkbox-B5y2oT9V.js";import{u as $}from"./use-toast-DGElh_6W.js";import{B as E}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:d}=$(),{roles:m}=N().props,{data:r,setData:n,errors:t,processing:x,post:g,reset:f}=w({username:"",name:"",email:"",password:"",password_confirmation:"",selectedRoles:[]}),v=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=m.map(l=>l.name);n("selectedRoles",a.target.checked?s:[])},b=a=>{a.preventDefault(),g(route("apps.users.store"),{onSuccess:()=>{d({variant:"success",title:"Success",description:"Data berhasil disimpan"}),f()}})};return e.jsxs(e.Fragment,{children:[e.jsx(T,{title:"Tambah Pengguna"}),e.jsx(B,{title:"Tambah Pengguna",subtitle:"Halaman ini digunakan untuk menambahkan data pengguna"}),e.jsx("div",{className:"p-6",children:e.jsxs(A,{children:[e.jsxs(S,{children:[e.jsx(H,{children:"Tambah Pengguna"}),e.jsx(L,{children:"Form ini digunakan untuk menambahkan data pengguna"})]}),e.jsx(D,{children:e.jsxs("form",{onSubmit:b,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(_,{children:[e.jsx(I,{children:e.jsxs(h,{children:[e.jsx(c,{className:"w-[50px] text-center",children:e.jsx(j,{onChange:a=>k(a),checked:r.selectedRoles.length===m.length})}),e.jsx(c,{children:"Nama Akses Group"}),e.jsx(c,{children:"Hak Akses"})]})}),e.jsx(K,{children:m.map((a,s)=>e.jsxs(h,{children:[e.jsx(p,{className:"w-[50px] text-center",children:e.jsx(j,{checked:r.selectedRoles.includes(a.name),onChange:v,value:a.name,id:`role-${s}`},s)}),e.jsx(p,{children:a.name}),e.jsx(p,{children:e.jsx("div",{className:"flex flex-wrap gap-2",children:a.permissions.map((l,C)=>e.jsx(E,{children:l.name},C))})})]},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(u,{variant:"destructive",asChild:!0,children:e.jsxs(R,{href:"/apps/roles",children:[e.jsx(P,{})," Kembali"]})}),e.jsxs(u,{variant:"default",type:"submit",disabled:x,children:[x?e.jsx(F,{className:"animate-spin"}):e.jsx(G,{})," Simpan Data"]})]})]})})]})})]})}Y.layout=d=>e.jsx(y,{children:d});export{Y as default};
