import{r as c,a as B,c as M,j as t,v as R,L as $,I as H,i as L}from"./index-7c7a558c.js";import{B as Q}from"./Breadcrumb-21e99ae5.js";import{D as W,T as _}from"./TrashIcon-29561c1e.js";import{d as q,a as G}from"./courseApi-e3b335b8.js";import"./Group-801c960a.js";const X=()=>{var m,p,j,o,N,b,f,g,y,v,w,S,k,C,D,E,F,I;const[i,T]=c.useState(25),P=25,n=8,{data:a,isLoading:s,isError:A,isFetching:z,error:x,refetch:r}=B("getCourses",()=>G({count:i})),h=M();c.useEffect(()=>{const e=localStorage.getItem("token"),d=localStorage.getItem("user");e&&d||h("/login")},[h]),c.useEffect(()=>{r()},[i,r]);let l=null;return s&&(l=t.jsx("tr",{className:" border-b dark:text-white",children:t.jsx("td",{colSpan:n,className:"text-center text-white",children:t.jsx("div",{className:"text-center flex justify-center items-center my-6",children:t.jsx(L,{color:"white",size:"lg",variant:"dots"})})})})),!s&&A&&(l=t.jsx("tr",{className:" border-b dark:text-white",children:t.jsx("td",{colSpan:n,className:"text-center text-white py-6",children:`${x==null?void 0:x.error}`})})),!s&&((j=(p=(m=a==null?void 0:a.data)==null?void 0:m.data)==null?void 0:p.courses)==null?void 0:j.length)===0&&(l=t.jsx("tr",{className:" border-b dark:text-white",children:t.jsx("td",{colSpan:n,className:"text-center text-white py-6",children:"No Courses Found!"})})),!s&&((b=(N=(o=a==null?void 0:a.data)==null?void 0:o.data)==null?void 0:N.courses)==null?void 0:b.length)>0&&(l=(y=(g=(f=a==null?void 0:a.data)==null?void 0:f.data)==null?void 0:g.courses)==null?void 0:y.map((e,d)=>t.jsxs("tr",{className:" border-b text-white dark:text-white",children:[t.jsx("td",{"data-label":"Serial",className:"px-6 py-4",children:d+1}),t.jsx("td",{"data-label":"Name",className:"px-6 py-4",children:e==null?void 0:e.title}),t.jsx("td",{"data-label":"Sub Title",className:"px-6 py-4",children:e==null?void 0:e.subtitle}),t.jsx("td",{"data-label":"Description",className:"px-6 py-4",children:e==null?void 0:e.description}),t.jsx("td",{"data-label":"Price",className:"px-6 py-4",children:e==null?void 0:e.price}),t.jsx("td",{"data-label":"Status",className:"px-6 py-4",children:(e==null?void 0:e.status)==0?"Pending":(e==null?void 0:e.status)==1?"Published":(e==null?void 0:e.status)==2?"Waiting For Review":(e==null?void 0:e.status)==3?"Hold":"Draft"}),t.jsx("td",{"data-label":"Date",className:"px-6 py-4",children:R(e==null?void 0:e.created_at)}),t.jsx("td",{"data-label":"Action",className:"px-6 py-4",children:t.jsxs("div",{className:"flex items-center justify-end gap-2",children:[t.jsx($,{to:`/admin/updatecourse/${e==null?void 0:e.uuid}`,className:"font-medium text-blue-600 dark:text-blue-500 hover:underline",children:"Edit"}),t.jsx(W,{buttonText:t.jsx(_,{}),mutationFn:q,deleteId:e==null?void 0:e.uuid,refetchFn:r})]})})]},d))),t.jsxs(t.Fragment,{children:[t.jsx(Q,{title:"Courses"}),t.jsx("div",{className:"container mx-auto my-5 p-5",children:t.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:[t.jsx(H,{dataLength:(S=(w=(v=a==null?void 0:a.data)==null?void 0:v.data)==null?void 0:w.courses)!=null&&S.length?(D=(C=(k=a==null?void 0:a.data)==null?void 0:k.data)==null?void 0:C.courses)==null?void 0:D.length:0,next:()=>{T(e=>e+P)},hasMore:((I=(F=(E=a==null?void 0:a.data)==null?void 0:E.data)==null?void 0:F.courses)==null?void 0:I.length)==i,children:t.jsxs("table",{className:"w-full text-sm text-left text-gray-500 dark:text-gray-400",children:[t.jsx("thead",{className:"text-xs text-gray-200 uppercase text-black",children:t.jsxs("tr",{children:[t.jsx("th",{scope:"col",className:"p-6",children:"Serial"}),t.jsx("th",{scope:"col",className:"px-6 py-3",children:"Name"}),t.jsx("th",{scope:"col",className:"px-6 py-3",children:"Sub Title"}),t.jsx("th",{scope:"col",className:"px-6 py-3",children:"Description"}),t.jsx("th",{scope:"col",className:"px-6 py-3",children:"Price"}),t.jsx("th",{scope:"col",className:"px-6 py-3",children:"Status"}),t.jsx("th",{scope:"col",className:"px-6 py-3",children:"Date"}),t.jsx("th",{scope:"col",className:"px-6 py-3",children:"Action"})]})}),t.jsx("tbody",{children:l})]})}),z&&t.jsx("div",{className:"text-center flex justify-center items-center my-6",children:t.jsx(L,{color:"white",size:"lg",variant:"dots"})})]})})]})};export{X as default};
