---
import i18next from 'i18next';
import config from '../../astro-i18next.config.mjs';

export interface Props {
  path: string;
}

const { path } = Astro.props;

const pages = await Astro.glob('../../public/locales/**/*.md');
let markdown;

markdown = pages.find((page) =>
  page.file.includes(`locales/${i18next.language}/${path}`),
);

if (!markdown) {
  markdown = pages.find((page) =>
    page.file.includes(`locales/${config.defaultLocale}/${path}`),
  );
}

if (!markdown) {
  throw Error(`The file: "${path}" was not found.`);
}

const { Content } = markdown;
---

<Content />
