import{r as i,a as S,c as P,j as e,B as E,L,i as I}from"./index-7c7a558c.js";import{B as k}from"./Breadcrumb-065f300e.js";import{n as B}from"./studentApi-6e4fac08.js";const R=()=>{var y,N,f,b;const[m,T]=i.useState(25),[a,o]=i.useState(1),c=10,d=7,{data:s,isLoading:u,isError:C,error:r,isFetching:A,refetch:p}=S("getStudentCourses",()=>B({count:m})),h=P();i.useEffect(()=>{const t=localStorage.getItem("token"),n=localStorage.getItem("user");t&&n||h("/login")},[h]),i.useEffect(()=>{p()},[m,p]);const g=(a-1)*c,v=g+c,j=((N=(y=s==null?void 0:s.data)==null?void 0:y.data)==null?void 0:N.slice(g,v))||[];let l=null;u?l=e.jsx("tr",{className:"bg-second",children:e.jsx("td",{colSpan:d,className:"text-center text-white flex md:table-cell justify-center items-center",children:e.jsx("div",{className:"text-center flex justify-center items-center my-6",children:e.jsx(I,{color:"dark",size:"lg",variant:"dots"})})})}):C?l=e.jsx("tr",{className:"bg-second",children:e.jsx("td",{colSpan:d,className:"text-center text-white py-6",children:"No Courses Found!"})}):j.length===0?l=e.jsx("tr",{className:"bg-second ",children:e.jsx("td",{colSpan:d,className:"text-center text-white py-6",children:`${r==null?void 0:r.error}`})}):l=j.map((t,n)=>{var w;return e.jsxs("tr",{className:"bg-gradient-to-r from-main to-second border-b text-white ",children:[e.jsx("td",{className:"w-4 p-4",children:n+1}),e.jsx("td",{"data-label":"Image",className:"px-6 py-4 font-medium text-gray-100 whitespace-nowrap",children:e.jsx("div",{className:"flex items-center justify-center",children:t!=null&&t.image?e.jsx("img",{className:"w-[150px]",src:`${E}${t==null?void 0:t.image}`}):""})}),e.jsx("td",{"data-label":"Title",className:"px-6 py-4 font-medium text-gray-100 whitespace-nowrap",children:t==null?void 0:t.title}),e.jsx("td",{"data-label":"Course Type",className:"px-6 py-4 font-medium text-center text-gray-100 whitespace-nowrap",children:t==null?void 0:t.course_type}),e.jsx("td",{"data-label":"Category",className:"px-6 py-4 font-medium text-gray-100 whitespace-nowrap",children:(w=t==null?void 0:t.category)==null?void 0:w.name}),e.jsx("td",{"data-label":"Price",className:"px-6 py-4 font-medium text-gray-100 whitespace-nowrap",children:t==null?void 0:t.price}),e.jsx("td",{"data-label":"Action",className:"px-6 py-4 font-medium text-gray-100 whitespace-nowrap",children:e.jsx(L,{to:`/student/courses/${t==null?void 0:t.slug}`,className:"font-medium text-white hover:underline",children:"View"})})]},n)});const x=Math.ceil((((b=(f=s==null?void 0:s.data)==null?void 0:f.data)==null?void 0:b.length)||0)/c);return e.jsxs(e.Fragment,{children:[e.jsx(k,{title:"Course List"}),e.jsxs("div",{className:"container mx-auto my-5 lg:p-5 min-h-screen",children:[e.jsx("div",{className:"relative overflow-x-auto shadow-md border-dashed border rounded-tr-xl rounded-bl-xl mb-40 md:mb-20",children:e.jsxs("table",{className:"w-full text-sm text-left text-gray-500 table-auto",children:[e.jsx("thead",{className:"text-xs uppercase bg-secondBg border-b text-white",children:e.jsxs("tr",{className:"",children:[e.jsx("th",{scope:"col",className:"p-4",children:"SL"}),e.jsx("th",{scope:"col",className:"px-6 py-3 text-center",children:"Image"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Title"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Course Type"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Category"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Price"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Action"})]})}),e.jsx("tbody",{children:l})]})}),e.jsxs("div",{className:"flex justify-center items-center mt-4",children:[e.jsx("button",{onClick:()=>{a>1&&o(t=>t-1)},disabled:a===1,className:"px-4 py-2 rounded-md bg-main text-white mr-2",children:"Previous"}),e.jsxs("span",{className:"text-gray-600",children:["Page ",a," of ",x]}),e.jsx("button",{onClick:()=>{a<x&&o(t=>t+1)},disabled:a>=x,className:"px-4 py-2 rounded-md bg-main text-white ml-2",children:"Next"})]})]})]})};export{R as default};
