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

import { getCharacterBySlug } from "@/data/constants/character";
import { PrivateRoomRouteProvider } from "@/providers/private-room-route-provider";

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

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