import{r as c,a as _,c as $,j as e,v as Q,L as R,I as q,i as D}from"./index-7c7a558c.js";import{B as G}from"./Breadcrumb-21e99ae5.js";import{D as H,T as J}from"./TrashIcon-29561c1e.js";import{d as K,g as O}from"./categoryApi-a5b9b1ba.js";import"./Group-801c960a.js";const Y=()=>{var m,o,p,j,u,f,N,b,w,v,C,I,k,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:r}=_("getCategories",()=>O({count:d})),h=$();c.useEffect(()=>{const t=localStorage.getItem("token"),x=localStorage.getItem("user");t&&x||h("/login")},[h]),c.useEffect(()=>{r()},[d,r]);let a=null;return l&&(a=e.jsx("tr",{className:" border-b 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:" border-b 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:" border-b text-white",children:e.jsx("td",{colSpan:n,className:"text-center text-white py-6",children:"No Category Found!"})})),!l&&((f=(u=(j=s==null?void 0:s.data)==null?void 0:j.data)==null?void 0:u.categories)==null?void 0:f.length)>0&&(a=(w=(b=(N=s==null?void 0:s.data)==null?void 0:N.data)==null?void 0:b.categories)==null?void 0:w.map((t,x)=>e.jsxs("tr",{className:" border-b 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:Q(t==null?void 0:t.created_at)}),e.jsxs("td",{className:"px-6 py-4 flex items-center gap-4",children:[e.jsx(R,{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(H,{buttonText:e.jsx(J,{}),mutationFn:K,deleteId:t==null?void 0:t.uuid,refetchFn:r})]})]},x))),e.jsxs(e.Fragment,{children:[e.jsx(G,{title:"All Category"}),e.jsx("div",{className:"container mx-auto my-5 p-5",children:e.jsxs("div",{className:"relative overflow-x-auto p-2 bg-gradient-to-r from-main to-second shadow-md border-dashed border rounded-tr-xl rounded-bl-xl",children:[e.jsx(q,{dataLength:(I=(C=(v=s==null?void 0:s.data)==null?void 0:v.data)==null?void 0:C.categories)!=null&&I.length?(F=(E=(k=s==null?void 0:s.data)==null?void 0:k.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{Y as default};
