import { LoaderFunction, json } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import { withAuth } from "~/auth/withAuth";
import { FineTuneWithDatasetDto } from "~/browser-client";
import { FineTuningPage } from "~/pages/finetuning/FineTuningPage";

type LoaderType = {
  fineTunes: FineTuneWithDatasetDto[];
};

export const loader: LoaderFunction = withAuth(async ({ api, params }) => {
  const envId = params.envId!;
  const fineTunes = await api.fineTuning.finetuneControllerGetFineTunesForEnv({
    envId,
  });
  return json<LoaderType>({ fineTunes });
});

export default function FineTuningRoute() {
  const { fineTunes } = useLoaderData<LoaderType>();

  return <FineTuningPage fineTunes={fineTunes} />;
}
