import{r as n,ah as P,a0 as y,j as e,N as b}from"./index-CWMEhb0Z.js";import{C as E}from"./CourseCard-BlcG-iJP.js";import{P as k,a as A,b as i,c as w,d as j,e as I,f as L}from"./pagination-Bb4EKQd6.js";function O(){const[r,p]=n.useState([]),[o,m]=n.useState(!0),[c,h]=n.useState(null),[t,u]=n.useState(1),x=12;n.useEffect(()=>{f()},[]);const f=async()=>{try{m(!0),h(null);const s=await P.get("/courses");console.log(s.data.data),p(s.data.data),u(1)}catch(s){y.isAxiosError(s)&&h(s.message||"An error occurred while loading courses"),console.error("Error fetching courses:",s)}finally{m(!1)}},a=Math.ceil(r.length/x),g=(t-1)*x,N=g+x,v=r.slice(g,N),l=s=>{u(s),window.scrollTo({top:0,behavior:"smooth"})};return e.jsx("section",{children:e.jsxs("div",{className:"container mx-auto py-8 px-4",children:[e.jsx("header",{className:"mb-8",children:e.jsxs("div",{className:"bg-gradient-to-r from-main-400/10 to-main-500/10 rounded-3xl p-8 border border-main-400/20",children:[e.jsx("h1",{className:"text-4xl font-bold text-main-400 mb-3",children:"Our Courses"}),e.jsxs("p",{className:"text-neutral-700 text-lg",children:["Explore our collection of ",r.length," ",r.length===1?"course":"courses"," to enhance your learning"]})]})}),o&&e.jsx("div",{className:"flex justify-center items-center min-h-[400px]",children:e.jsx("div",{className:"text-xl text-neutral-600",children:"Loading..."})}),c&&!o&&e.jsx("div",{className:"flex justify-center items-center min-h-[400px]",children:e.jsx("div",{className:"text-xl text-red-600",children:c})}),!o&&!c&&r.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid xl:grid-cols-4 lg:grid-cols-3 md:grid-cols-2 gap-10 mt-8",children:v.map(s=>e.jsx(b,{to:`/course-details/${s.id}`,children:e.jsx(E,{course:s})},s.id))}),a>1&&e.jsx(k,{className:"my-4",children:e.jsxs(A,{children:[e.jsx(i,{children:e.jsx(w,{onClick:()=>t>1&&l(t-1),className:t===1?"pointer-events-none opacity-50":"cursor-pointer"})}),e.jsx(i,{className:"flex gap-1",children:[...Array(Math.min(3,a))].map((s,C)=>{const d=C+1;return e.jsx(j,{onClick:()=>l(d),isActive:t===d,className:"cursor-pointer",children:d},d)})}),a>4&&e.jsx(i,{children:e.jsx(I,{})}),a>3&&e.jsx(i,{children:e.jsx(j,{onClick:()=>l(a),isActive:t===a,className:"cursor-pointer",children:a})}),e.jsx(i,{children:e.jsx(L,{onClick:()=>t<a&&l(t+1),className:t===a?"pointer-events-none opacity-50":"cursor-pointer"})})]})})]}),!o&&!c&&r.length===0&&e.jsx("div",{className:"flex justify-center items-center min-h-[400px]",children:e.jsx("div",{className:"text-xl text-neutral-600",children:"No courses available"})})]})})}export{O as default};
