import{q as y,v as D,R as T,j as e,$ as v}from"./app-BGey7YPf.js";import{h as o,A}from"./app-layout-mnJEmZ7X.js";import{H}from"./header-D0w47C-P.js";import{D as U,a as C,b as P,c as M,d as S,e as w}from"./dialog-OAe1w9Cd.js";import{T as B,a as E,b as F,c as R,d as c,e as l,f as I,g as L,h as d}from"./table-C3FnqSRz.js";import{L as _}from"./label-BbSRpehS.js";import{I as O}from"./input-CGSIKYsG.js";import{C as $,A as q,M as z,P as G}from"./page-pagination-D1u9TBBY.js";import{B as J}from"./button-submit-end-BkQSWpq2.js";import"./button-D5r5edT8.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"./use-toast-DGElh_6W.js";import"./select-BqSuhmAT.js";import"./index-BuSoVzfP.js";import"./chevron-down-DOZGaFlM.js";import"./trash-Blc6Iqr5.js";import"./chevron-left-7ssMp1N3.js";import"./save-Bm3_KHjE.js";function K(){const{permissions:r,currentPage:x,perPage:h}=y().props,{data:t,setData:i,post:m,processing:u,errors:j,reset:n,transform:g}=D({id:"",name:"",open:!1,isUpdate:!1}),[k,p]=T.useState(!1);g(a=>({...a,_method:a.isUpdate?"put":"post"}));const f=a=>{i(s=>({...s,id:a.id,name:a.name,open:!0,isUpdate:!0}))},b=a=>{p(!0),i(s=>({...s,id:a.id}))},N=async a=>{a.preventDefault(),t.isUpdate?m(route("apps.permissions.update",t.id),{onSuccess:()=>{n(),i(s=>({...s,open:!1,isUpdate:!1}))}}):m(route("apps.permissions.store"),{onSuccess:()=>{n(),i(s=>({...s,open:!1,isUpdate:!1}))}})};return e.jsxs(e.Fragment,{children:[e.jsx(v,{title:"Hak Akses"}),e.jsx(H,{title:"Hak Akses",subtitle:"Halaman ini digunakan untuk mengelola data hak akses pengguna",children:e.jsxs(U,{open:t.open,onOpenChange:a=>i({...t,open:a,name:"",id:"",isUpdate:!1}),children:[o(["permissions-create"])&&e.jsxs(C,{className:"px-4 py-2 flex items-center gap-2 rounded-lg text-sm font-semibold text-gray-700 border hover:bg-gray-100 dark:text-gray-200 dark:hover:bg-gray-900 dark:border-gray-800 focus:outline-none",children:[e.jsx($,{className:"size-4"})," ",e.jsx("span",{className:"hidden sm:inline-flex",children:"Tambah Hak Akses"})]}),e.jsxs(P,{className:"p-0",children:[e.jsxs(M,{className:"p-4 border-b",children:[e.jsxs(S,{children:[t.isUpdate?"Ubah":"Tambah"," Hak Akses"]}),e.jsxs(w,{className:"text-sm",children:["Form ini digunakan untuk ",t.isUpdate?"mengubah data hak akses":"menambahkan data hak akses"]})]}),e.jsx("form",{onSubmit:N,children:e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-2",children:[e.jsx(_,{children:"Nama Hak Akses"}),e.jsx(O,{type:"text",name:"name",value:t.name,onChange:a=>i("name",a.target.value),placeholder:"Masukkan nama hak akses"}),e.jsx("p",{className:"text-red-500 text-xs",children:j.name})]}),e.jsx(J,{reset:n,processing:u})]})})]})]})}),e.jsxs("div",{className:"p-6",children:[e.jsx("div",{className:"mb-5",children:e.jsx(B,{withFilterPage:!0,currentPage:x,perPage:h,url:route("apps.permissions.index"),placeholder:"Cari data hak akses berdasarkan nama hak akses"})}),e.jsx(E,{children:e.jsxs(F,{children:[e.jsx(R,{children:e.jsxs(c,{children:[e.jsx(l,{className:"w-[10px] text-center",children:"No"}),e.jsx(l,{children:"Nama Hak Akses"}),e.jsx(l,{className:"w-[10px] text-center",children:"Aksi"})]})}),e.jsx(I,{children:r.data.length===0?e.jsx(L,{colSpan:3,message:"data hak akses"}):r.data.map((a,s)=>e.jsxs(c,{children:[e.jsx(d,{className:"text-center",children:++s+(r.current_page-1)*r.per_page}),e.jsx(d,{children:a.name}),e.jsx(d,{children:e.jsx("div",{className:"flex items-center justify-center",children:(o(["permissions-update"])||o(["permissions-delete"]))&&e.jsx(q,{permissionPrefix:"permissions",isModal:!0,actionEdit:()=>f(a),actionDelete:()=>b(a)})})})]},s))})]})}),e.jsx(z,{open:k,onOpenChange:p,url:route("apps.permissions.destroy",t.id)}),e.jsx(G,{data:r})]})]})}K.layout=r=>e.jsx(A,{children:r});export{K as default};
