import NotesInfo from '../../../public/notes.json';
import { NoteEntry } from '../components/note-entry';

function NotesPage() {
	const notes = Object.entries(NotesInfo)
		.map(([slug, note]) => {
			return {
				slug,
				title: note.title,
				mtime: new Date(note.mtime)
			}
		})
		.sort(
			(a, b) => {
				return b.mtime.getTime() - a.mtime.getTime();
			}
		);

	return (
		<>
			{
				!notes || notes.length === 0
				&& <>No notes found</>
				|| <table>
					<tbody>
						{notes.map(
							(note: any) => {
								return (<NoteEntry note={note} key={note.slug} />);
							}
						)}
					</tbody>
				</table>
			}
		</>
	)
}


export default NotesPage;
