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

import { getCharacterBySlug } from "@/data/constants/character";
import { ChatRouteProviders } from "@/providers/chat-route-providers";

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

  return (
    <ChatRouteProviders
      characterId={character.id}
      emptyChatGreeting={character.emptyChatGreeting}
    >
      {children}
    </ChatRouteProviders>
  );
}
