import type { Courses } from '../types/codyops-courses';

export const getUniqueCategories = (
  courses: Courses[]
) => {
  const coursesEntries = courses.flatMap(
    (course: Courses) => [...course.category]
  );
  return [...new Set(coursesEntries)];
};

export const getUniqueLevels = (courses: Courses[]) => {
  const coursesEntries = courses.map(
    (course: Courses) => course.level
  );
  return [...new Set(coursesEntries)];
};

export const sortCoursesByDate = (courses: Courses[]) =>
  courses
    .filter((course) => course.status !== 'draft') // Assuming 'draft' status is used instead of a 'draft' property
    .sort(
      (a, b) =>
        Math.floor(new Date(b.date_created || '').getTime() / 1000) -
        Math.floor(new Date(a.date_created || '').getTime() / 1000)
    );
