import{r as o,a as F,c as L,j as e,v as D,L as k,I as T,i as A}from"./index-7c7a558c.js";import{B as _}from"./Breadcrumb-f4cb0f42.js";import{f as z,h as B}from"./adminManageApi-69611741.js";import{D as G,T as M}from"./TrashIcon-29561c1e.js";import"./Group-801c960a.js";const H=()=>{var m,h,u,p,j,g,b,f,N,y,w,v;const[d,S]=o.useState(25),E=25,l=10,{data:t,isLoading:c,isError:I,isFetching:R,error:n,refetch:i}=F("getAdminRoles",()=>B({count:d})),x=L();o.useEffect(()=>{const a=localStorage.getItem("token"),r=localStorage.getItem("user");a&&r||x("/login")},[x]),o.useEffect(()=>{i()},[d,i]);let s=null;return c&&(s=e.jsx("tr",{className:"section-bg border-b dark:text-white",children:e.jsx("td",{colSpan:l,className:"text-center text-white",children:e.jsx("div",{className:"text-center flex justify-center items-center my-6",children:e.jsx(A,{color:"white",size:"lg",variant:"dots"})})})})),!c&&I&&(s=e.jsx("tr",{className:"section-bg border-b dark:text-white",children:e.jsx("td",{colSpan:l,className:"text-center text-white py-6",children:`${n==null?void 0:n.error}`})})),!c&&((h=(m=t==null?void 0:t.data)==null?void 0:m.data)==null?void 0:h.roles.length)===0&&(s=e.jsx("tr",{className:"section-bg border-b dark:text-white",children:e.jsx("td",{colSpan:l,className:"text-center text-white py-6",children:"No Roles Found!"})})),!c&&((p=(u=t==null?void 0:t.data)==null?void 0:u.data)==null?void 0:p.roles.length)>0&&(s=(g=(j=t==null?void 0:t.data)==null?void 0:j.data)==null?void 0:g.roles.map((a,r)=>e.jsxs("tr",{className:"section-bg border-b dark:text-white",children:[e.jsx("td",{"data-label":"Serial",className:"px-6 py-4",children:a.id}),e.jsx("td",{"data-label":"Name",className:"px-6 py-4",children:a.name}),e.jsx("td",{"data-label":"Guard",className:"px-6 py-4",children:a.guard_name}),e.jsx("td",{"data-label":"Date",className:"px-6 py-4",children:D(a.created_at)}),e.jsx("td",{"data-label":"Action",className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(k,{to:`/admin/role/${a==null?void 0:a.id}`,className:"font-medium text-blue-600 dark:text-blue-500 hover:underline",children:"Edit"}),e.jsx(G,{buttonText:e.jsx(M,{}),mutationFn:z,deleteId:a==null?void 0:a.id,refetchFn:i})]})})]},r))),e.jsxs(e.Fragment,{children:[e.jsx(_,{title:"Roles"}),e.jsx("div",{className:"container mx-auto my-5 p-5",children:e.jsxs("div",{className:"relative overflow-x-auto shadow-md sm:rounded-lg section-bg p-2",children:[e.jsx("div",{className:"my-6",children:e.jsx(k,{to:"/admin/add_role",className:"text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800",children:"Add New"})}),e.jsx(T,{dataLength:(f=(b=t==null?void 0:t.data)==null?void 0:b.data)!=null&&f.roles.length?(y=(N=t==null?void 0:t.data)==null?void 0:N.data)==null?void 0:y.roles.length:0,next:()=>{S(a=>a+E)},hasMore:((v=(w=t==null?void 0:t.data)==null?void 0:w.data)==null?void 0:v.roles.length)==d,children:e.jsxs("table",{className:"w-full text-sm text-left text-gray-500 dark:text-gray-400",children:[e.jsx("thead",{className:"text-xs text-gray-700 uppercase bg-white text-black",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"p-6",children:"Serial"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Name"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Guard"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Date"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Action"})]})}),e.jsx("tbody",{children:s})]})}),R&&e.jsx("div",{className:"text-center flex justify-center items-center my-6",children:e.jsx(A,{color:"white",size:"lg",variant:"dots"})})]})})]})};export{H as default};
