import{q as b,v as w,j as e,$ as R,Y as I}from"./app-CffHYkHW.js";import{A as y}from"./app-layout-D-VS7nVU.js";import{t as T}from"./index-Dw4sHwMN.js";import{C as B,a as D,b as L,c as k,d as A}from"./card-X_CDEGIm.js";import{L as i}from"./label-iPcRrN_N.js";import{I as n}from"./input-Bw4IOOzt.js";import{a as S,b as U,c as _,d as p,e as d,f as H,h as m}from"./table-DVZTgtP_.js";import{B as h}from"./button-qhe8lrPU.js";import{C as j}from"./checkbox-CLMtdSBA.js";import{B as P}from"./badge-soq0-NVD.js";import{A as $}from"./arrow-left-DFiSAE9E.js";import{L as E}from"./loader-circle-BRrBaJrT.js";import{S as Y}from"./save-D2L_UJE7.js";import"./utils-C8zp8JNC.js";import"./sheet-Bisw0FSz.js";import"./index-C0loMkA3.js";import"./index-Cy5bElus.js";import"./index-DPkgfxsD.js";import"./x-BfabuQJD.js";import"./createLucideIcon-DAR-hy5d.js";import"./index-C9NeyPdJ.js";import"./index-CjqRk3xD.js";import"./truck-DnoS8QCL.js";import"./package-BHw0cifz.js";import"./shopping-bag-AryJS2XX.js";import"./app-logo-icon-D3Jzt_fn.js";import"./bluetooth-context-CLrE8g1i.js";import"./sonner-CPUj7IiR.js";import"./select-ClrGyhQo.js";import"./chevron-down-C5A3yn87.js";const q=[{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:f,reset:u}=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(),f(route("apps.users.store"),{onSuccess:()=>{T("Data has been saved."),u()}})};return e.jsxs(y,{breadcrumbs:q,children:[e.jsx(R,{title:"Create User"}),e.jsx("div",{className:"p-4",children:e.jsxs(B,{children:[e.jsxs(D,{children:[e.jsx(L,{children:"Create User"}),e.jsx(k,{children:"This form for create user"})]}),e.jsx(A,{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(S,{children:e.jsxs(U,{children:[e.jsx(_,{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(H,{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($,{})," Go Back"]})}),e.jsxs(h,{variant:"default",type:"submit",disabled:x,children:[x?e.jsx(E,{className:"animate-spin"}):e.jsx(Y,{})," Save Data"]})]})]})})]})})]})}export{ve as default};
