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

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

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

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