import type { ReactNode } from "react";
import { notFound } from "next/navigation";

import {
  CHARACTERS,
  getCharacterBySlug,
} from "@/data/constants/character";
import { CharacterRouteBoundary } from "@/providers/character-route-boundary";

export const dynamicParams = false;

export function generateStaticParams() {
  return CHARACTERS.map((character) => ({
    characterSlug: character.slug,
  }));
}

export default async function CharacterLayout({
  children,
  params,
}: {
  children: ReactNode;
  params: Promise<{ characterSlug: string }>;
}) {
  const { characterSlug } = await params;
  const character = getCharacterBySlug(characterSlug);
  if (!character) notFound();

  return (
    <CharacterRouteBoundary character={character}>
      {children}
    </CharacterRouteBoundary>
  );
}
