import { error, redirect } from '@sveltejs/kit';
import { staticPages, type StaticPageSlug } from '$lib/content/static-pages';
import { getSharedPageContent } from '$lib/server/content';

export async function load({ params }) {
  if (params.slug === 'about-us') {
    throw redirect(301, '/about');
  }

  if (params.slug === 'booking') {
    throw redirect(301, '/contact-us');
  }

  const slug = params.slug as StaticPageSlug;
  const page = staticPages[slug];

  if (!page) {
    throw error(404, 'Page not found');
  }

  return {
    content: await getSharedPageContent(),
    page,
    slug
  };
}
