import{r as c,a as _,c as $,j as e,v as g,L as Q,I as R,i as D}from"./index-7c7a558c.js";import{B as q}from"./Breadcrumb-f4cb0f42.js";import{D as G,T as H}from"./TrashIcon-29561c1e.js";import{d as J,g as K}from"./categoryApi-a5b9b1ba.js";import"./Group-801c960a.js";const X=()=>{var m,o,p,j,u,N,f,b,v,w,k,C,I,E,F,S,L,A;const[d,T]=c.useState(25),z=25,n=8,{data:s,isLoading:l,isError:B,isFetching:M,error:i,refetch:x}=_("getCategories",()=>K({count:d})),h=$();c.useEffect(()=>{const t=localStorage.getItem("token"),r=localStorage.getItem("user");t&&r||h("/login")},[h]),c.useEffect(()=>{x()},[d,x]);let a=null;return l&&(a=e.jsx("tr",{className:"section-bg border-b dark:text-white",children:e.jsx("td",{colSpan:n,className:"text-center text-white",children:e.jsx("div",{className:"text-center flex justify-center items-center my-6",children:e.jsx(D,{color:"white",size:"lg",variant:"dots"})})})})),!l&&B&&(a=e.jsx("tr",{className:"section-bg border-b dark:text-white",children:e.jsx("td",{colSpan:n,className:"text-center text-white py-6",children:`${i==null?void 0:i.error}`})})),!l&&((p=(o=(m=s==null?void 0:s.data)==null?void 0:m.data)==null?void 0:o.categories)==null?void 0:p.length)===0&&(a=e.jsx("tr",{className:"section-bg border-b dark:text-white",children:e.jsx("td",{colSpan:n,className:"text-center text-white py-6",children:"No Category Found!"})})),!l&&((N=(u=(j=s==null?void 0:s.data)==null?void 0:j.data)==null?void 0:u.categories)==null?void 0:N.length)>0&&(a=(v=(b=(f=s==null?void 0:s.data)==null?void 0:f.data)==null?void 0:b.categories)==null?void 0:v.map((t,r)=>e.jsxs("tr",{className:"section-bg border-b dark:text-white",children:[e.jsx("td",{className:"px-6 py-4",children:t==null?void 0:t.id}),e.jsx("td",{className:"px-6 py-4",children:t==null?void 0:t.name}),e.jsx("td",{className:"px-6 py-4",children:t==null?void 0:t.is_feature}),e.jsx("td",{className:"px-6 py-4",children:t==null?void 0:t.status}),e.jsx("td",{className:"px-6 py-4",children:g(t==null?void 0:t.created_at)}),e.jsxs("td",{className:"px-6 py-4 flex items-center gap-4",children:[e.jsx(Q,{to:`/admin/updatecategory/${t==null?void 0:t.uuid}`,className:"font-medium text-blue-600 dark:text-blue-500 hover:underline",children:"Edit"}),e.jsx(G,{buttonText:e.jsx(H,{}),mutationFn:J,deleteId:t==null?void 0:t.uuid,refetchFn:x})]})]},r))),e.jsxs(e.Fragment,{children:[e.jsx(q,{title:"All Category"}),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:"pb-4 section-bg"}),e.jsx(R,{dataLength:(C=(k=(w=s==null?void 0:s.data)==null?void 0:w.data)==null?void 0:k.categories)!=null&&C.length?(F=(E=(I=s==null?void 0:s.data)==null?void 0:I.data)==null?void 0:E.categories)==null?void 0:F.length:0,next:()=>{T(t=>t+z)},hasMore:((A=(L=(S=s==null?void 0:s.data)==null?void 0:S.data)==null?void 0:L.categories)==null?void 0:A.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-4",children:"Id"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Name"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Feature"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Status"}),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:a})]})}),M&&e.jsx("div",{className:"text-center flex justify-center items-center my-6",children:e.jsx(D,{color:"white",size:"lg",variant:"dots"})})]})})]})};export{X as default};
