import{u as b,a as w,j as e,H as R,L as I}from"./app-CyJEXGyv.js";import{A as y}from"./app-layout-DbUGBUec.js";import{t as T}from"./index-BtT9Eyya.js";import{C as L,a as k,b as B,c as D,d as _}from"./card-BjOMVxEn.js";import{L as i}from"./label-CPJPVYbz.js";import{I as n}from"./input-De4RhZu7.js";import{a as A,b as H,c as S,d as p,e as d,f as U,h as m}from"./table-fuaFg2Mm.js";import{B as h}from"./button-COEJSQkW.js";import{C as j}from"./checkbox-GQkAN5_R.js";import{B as P}from"./badge-BSEA-Kjk.js";import{A as E}from"./arrow-left-BFpIQw4C.js";import{L as F}from"./loader-circle-C9PZqms-.js";import{S as G}from"./save-5G4mHmGr.js";import"./utils-D3rN0LeJ.js";import"./sheet-D9YCjyPN.js";import"./index-JbHgsFAK.js";import"./index-BiS8IM9B.js";import"./x-CEXz2EER.js";import"./createLucideIcon-DqnlFWer.js";import"./index-CeYyXWc4.js";import"./index-D448AvbX.js";import"./truck-DSNzHzca.js";import"./package-Ca-wQg6n.js";import"./shopping-bag-kX2qM3ec.js";import"./app-logo-icon-bwP4qd8Q.js";import"./bluetooth-context-DlC5mQaA.js";import"./index-l-_2VD5G.js";import"./sonner-DMUJNVEP.js";import"./select-787Dhddj.js";import"./chevron-down-CelnyKCC.js";const $=[{title:"Users",href:route("apps.users.index")},{title:"Create User",href:"#"}];function ve(){const{roles:c}=b().props,{data:t,setData:l,errors:o,processing:x,post:u,reset:f}=w({name:"",username:"",email:"",password:"",password_confirmation:"",selectedRoles:[]}),v=s=>{let a=t.selectedRoles;a.some(r=>r===s.target.value)?a=a.filter(r=>r!==s.target.value):a.push(s.target.value),l("selectedRoles",a)},g=s=>{const a=c.map(r=>r.name);l("selectedRoles",s.target.checked?a:[])},N=s=>{s.preventDefault(),u(route("apps.users.store"),{onSuccess:()=>{T("Data has been saved."),f()}})};return e.jsxs(y,{breadcrumbs:$,children:[e.jsx(R,{title:"Create User"}),e.jsx("div",{className:"p-4",children:e.jsxs(L,{children:[e.jsxs(k,{children:[e.jsx(B,{children:"Create User"}),e.jsx(D,{children:"This form for create user"})]}),e.jsx(_,{children:e.jsxs("form",{onSubmit:N,children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-2",children:[e.jsxs(i,{children:["Name",e.jsx("span",{className:"text-rose-500",children:"*"})]}),e.jsx(n,{type:"text",value:t.name,onChange:s=>l("name",s.target.value),placeholder:"Input fullname"}),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.jsxs(i,{children:["Username",e.jsx("span",{className:"text-rose-500",children:"*"})]}),e.jsx(n,{type:"text",value:t.username,onChange:s=>l("username",s.target.value),placeholder:"Input username"}),e.jsx("p",{className:"text-red-500 text-xs",children:o.username})]}),e.jsxs("div",{className:"mb-4 flex flex-col gap-2",children:[e.jsxs(i,{children:["Email",e.jsx("span",{className:"text-rose-500",children:"*"})]}),e.jsx(n,{type:"email",value:t.email,onChange:s=>l("email",s.target.value),placeholder:"Input email"}),e.jsx("p",{className:"text-red-500 text-xs",children:o.email})]}),e.jsxs("div",{className:"mb-4 flex flex-col gap-2",children:[e.jsxs(i,{children:["Password",e.jsx("span",{className:"text-rose-500",children:"*"})]}),e.jsx(n,{type:"password",value:t.password,onChange:s=>l("password",s.target.value),placeholder:"Input password"}),e.jsx("p",{className:"text-red-500 text-xs",children:o.password})]}),e.jsxs("div",{className:"mb-4 flex flex-col gap-2",children:[e.jsxs(i,{children:["Password Confirmation",e.jsx("span",{className:"text-rose-500",children:"*"})]}),e.jsx(n,{type:"password",value:t.password_confirmation,onChange:s=>l("password_confirmation",s.target.value),placeholder:"Input password confirmation"}),e.jsx("p",{className:"text-red-500 text-xs",children:o.password_confirmation})]}),e.jsxs("div",{className:"mb-4 flex flex-col gap-2",children:[e.jsxs(i,{children:["Roles",e.jsx("span",{className:"text-rose-500",children:"*"})]}),e.jsx(A,{children:e.jsxs(H,{children:[e.jsx(S,{children:e.jsxs(p,{children:[e.jsx(d,{className:"w-[50px] text-center",children:e.jsx(j,{onChange:s=>g(s),checked:t.selectedRoles.length===c.length})}),e.jsx(d,{children:"Role"}),e.jsx(d,{children:"Permissions"})]})}),e.jsx(U,{children:c.map((s,a)=>e.jsxs(p,{children:[e.jsx(m,{className:"w-[50px]",children:e.jsx("div",{className:"flex justify-center",children:e.jsx(j,{checked:t.selectedRoles.includes(s.name),onChange:r=>v(r),value:s.name,id:`role-${a}`},a)})}),e.jsx(m,{children:s.name}),e.jsx(m,{children:e.jsx("div",{className:"flex flex-wrap gap-2",children:s.permissions.map((r,C)=>e.jsx(P,{variant:"default",children:r.name},C))})})]},a))})]})}),e.jsx("p",{className:"text-red-500 text-xs",children:o.selectedRoles})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{variant:"destructive",asChild:!0,children:e.jsxs(I,{href:route("apps.users.index"),children:[e.jsx(E,{})," Go Back"]})}),e.jsxs(h,{variant:"default",type:"submit",disabled:x,children:[x?e.jsx(F,{className:"animate-spin"}):e.jsx(G,{})," Save Data"]})]})]})})]})})]})}export{ve as default};
