import{q as g,v as N,j as e,$ as P,Y as T}from"./app-CffHYkHW.js";import{A as R}from"./app-layout-D-VS7nVU.js";import{t as D}from"./index-Dw4sHwMN.js";import{C as I,a as L,b as k,c as y,d as A}from"./card-X_CDEGIm.js";import{L as d}from"./label-iPcRrN_N.js";import{I as S}from"./input-Bw4IOOzt.js";import{a as w,b as B,c as E,d as c,e as p,f as H,h as x}from"./table-DVZTgtP_.js";import{B as h}from"./button-qhe8lrPU.js";import{C as j}from"./checkbox-CLMtdSBA.js";import{A as $}from"./arrow-left-DFiSAE9E.js";import{L as Y}from"./loader-circle-BRrBaJrT.js";import{S as q}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 G=[{title:"Roles",href:route("apps.roles.index")},{title:"Edit Role",href:"#"}];function fe(){const{role:i,permissions:o}=g().props,{data:t,setData:l,errors:n,processing:m,post:f,reset:u}=N({name:i.name,selectedPermissions:i.permissions.map(s=>s.name),_method:"put"}),v=s=>{let r=t.selectedPermissions;r.some(a=>a===s.target.value)?r=r.filter(a=>a!==s.target.value):r.push(s.target.value),l("selectedPermissions",r)},b=s=>{const r=o.map(a=>a.name);l("selectedPermissions",s.target.checked?r:[])},C=s=>{s.preventDefault(),f(route("apps.roles.update",i.id),{onSuccess:()=>{D("Data has been saved."),u()}})};return e.jsxs(R,{breadcrumbs:G,children:[e.jsx(P,{title:"Edit Role"}),e.jsx("div",{className:"p-4",children:e.jsxs(I,{children:[e.jsxs(L,{children:[e.jsx(k,{children:"Edit Role"}),e.jsx(y,{children:"This form for edit role"})]}),e.jsx(A,{children:e.jsxs("form",{onSubmit:C,children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-2",children:[e.jsxs(d,{children:["Role Name",e.jsx("span",{className:"text-rose-500",children:"*"})]}),e.jsx(S,{type:"text",name:"name",value:t.name,onChange:s=>l("name",s.target.value),placeholder:"Input roles name"}),e.jsx("p",{className:"text-red-500 text-xs",children:n.name})]}),e.jsxs("div",{className:"mb-4 flex flex-col gap-2",children:[e.jsxs(d,{children:["Permissions",e.jsx("span",{className:"text-rose-500",children:"*"})]}),e.jsx(w,{children:e.jsxs(B,{children:[e.jsx(E,{children:e.jsxs(c,{children:[e.jsx(p,{className:"w-[50px] text-center",children:e.jsx(j,{onChange:s=>b(s),checked:t.selectedPermissions.length===o.length})}),e.jsx(p,{children:"Permission Name"})]})}),e.jsx(H,{children:o.map((s,r)=>e.jsxs(c,{children:[e.jsx(x,{className:"w-[50px]",children:e.jsx("div",{className:"flex justify-center",children:e.jsx(j,{checked:t.selectedPermissions.includes(s.name),onChange:a=>v(a),value:s.name,id:`permission-${r}`},r)})}),e.jsx(x,{children:s.name})]},r))})]})}),e.jsx("p",{className:"text-red-500 text-xs",children:n.selectedPermissions})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{variant:"destructive",asChild:!0,children:e.jsxs(T,{href:"/apps/roles",children:[e.jsx($,{})," Go Back"]})}),e.jsxs(h,{variant:"default",type:"submit",disabled:m,children:[m?e.jsx(Y,{className:"animate-spin"}):e.jsx(q,{})," Save Data"]})]})]})})]})})]})}export{fe as default};
