import { parse as yamlParse } from 'yaml';
import type { SiteData, Project } from '../types';

import brandRaw from './brand.yaml?raw';
import navRaw from './nav.yaml?raw';
import categoriesRaw from './categories.yaml?raw';
import statusesRaw from './statuses.yaml?raw';
import platformsRaw from './platforms.yaml?raw';
import aboutRaw from './about.yaml?raw';
import zhRaw from './i18n/zh.yaml?raw';
import enRaw from './i18n/en.yaml?raw';

const projectFiles = import.meta.glob('./projects/*.yaml', {
  eager: true,
  query: '?raw',
  import: 'default',
}) as Record<string, string>;

const projects: Project[] = Object.values(projectFiles)
  .map((raw) => yamlParse(raw) as Project)
  .sort((a, b) => a.order - b.order);

export const siteData: SiteData = {
  brand: yamlParse(brandRaw),
  nav: yamlParse(navRaw),
  categories: yamlParse(categoriesRaw),
  statuses: yamlParse(statusesRaw),
  platforms: yamlParse(platformsRaw),
  projects,
  about: yamlParse(aboutRaw),
  i18n: {
    zh: yamlParse(zhRaw),
    en: yamlParse(enRaw),
  },
};
