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