"use client" import React from 'react' import Collapse from './Collapse' import ScheduleCollapse from './ScheduleCollapse' import { CoursesProps, ScheduleProps } from '@/types' async function reorganizedSchedule(schedule: ScheduleProps[]) { const sortedSchedule = schedule.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime()); // Then, reorganize the sorted schedule const reorganizedSchedule = sortedSchedule.reduce>((acc, item) => { const date = new Date(item.date); const yearMonth = `${date.getFullYear()}年${String(date.getMonth() + 1).padStart(2, '0')}月`; if (!acc[yearMonth]) { acc[yearMonth] = { yearAndMonth: yearMonth, schedule: [] }; } acc[yearMonth].schedule.push(item); return acc; }, {}); return Object.values(reorganizedSchedule); } const Accordion = async ({ courseData }: { courseData: CoursesProps }) => { const newSchedule = await reorganizedSchedule(courseData.schedule) return (

{"課程時間表"}

{ newSchedule.map((item, index) => { return ( ) }) }
) } export default Accordion