---
import ArchivePanel from "@components/ArchivePanel.astro";
import I18nKey from "@i18n/i18nKey";
import { i18n } from "@i18n/translation";
import MainGridLayout from "@layouts/MainGridLayout.astro";
import { getCategoryList } from "@utils/content-utils";

export async function getStaticPaths() {
	const categories = await getCategoryList();

	const standardPaths = categories.map((category) => {
		return {
			params: {
				category: encodeURIComponent(category.name.trim()),
			},
			props: {
				decodedCategory: category.name.trim(),
			},
		};
	});

	const nonEncodedCJKPaths = categories
		.filter((category) =>
			/[\u3000-\u9fff\uac00-\ud7af\u4e00-\u9faf]/.test(category.name),
		)
		.map((category) => ({
			params: {
				category: category.name.trim(), // Do not encode CJK characters
			},
			props: {
				decodedCategory: category.name.trim(),
			},
		}));

	return [...standardPaths, ...nonEncodedCJKPaths];
}

const { decodedCategory } = Astro.props;
const category =
	decodedCategory || decodeURIComponent(Astro.params.category as string);
---

<MainGridLayout title={i18n(I18nKey.archive)} description={i18n(I18nKey.archive)}>
    <ArchivePanel categories={[category]}></ArchivePanel>
</MainGridLayout>
