---
import BaseLayout from '../../layouts/BaseLayout.astro';
import EntryList from '../../components/EntryList.astro';
import { getAllEntries } from '../../lib/entries';

export async function getStaticPaths() {
  const entries = await getAllEntries();
  const categories = [...new Set(entries.map((e) => e.category))];
  return categories.map((category) => ({
    params: { category },
    props: {
      category,
      entries: entries.filter((e) => e.category === category),
    },
  }));
}

const { category, entries } = Astro.props;
---

<BaseLayout title={`Category: ${category}`}>
  <h1>Category: {category}</h1>
  <EntryList entries={entries} />
  <p class="back"><a href="/">← back</a></p>

  <style>
    h1 { margin-bottom: 1rem; }
    .back { margin-top: 2rem; font-size: 0.9rem; }
  </style>
</BaseLayout>
