import ManageTournaments from "@/features/admin/components/manage-tournaments";
import { tournamentQueries } from "@/features/tournaments/queries";
import { prefetchServerQuery } from "@/lib/tanstack-query/utils/prefetch";
import { createFileRoute } from "@tanstack/react-router";

export const Route = createFileRoute("/_authed/admin/tournaments/")({
  beforeLoad: async ({ context }) => {
    const { queryClient } = context;
    await prefetchServerQuery(queryClient, tournamentQueries.list());
  },
  loader: () => ({
    header: {
      withBackButton: true,
      title: "Manage Tournaments",
    },
    refresh: tournamentQueries.list().queryKey,
    withPadding: false,
  }),
  component: RouteComponent,
});

function RouteComponent() {
  return <ManageTournaments />;
}
