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

import { getCharacterBySlug } from "@/data/constants/character";
import { PaymentRouteProvider } from "@/providers/payment-route-provider";

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

  return (
    <PaymentRouteProvider scopeKey={character.id}>
      {children}
    </PaymentRouteProvider>
  );
}
