import * as React from "react";
import { EvalTemplateForm } from "@/src/features/evals/components/template-form";
import { api } from "@/src/utils/api";
import { type EvalTemplate } from "@langfuse/shared";
import { useRouter } from "next/router";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/src/components/ui/select";
import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
import { useState } from "react";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import Page from "@/src/components/layouts/page";
import { Switch } from "@/src/components/ui/switch";
import { Command } from "@/src/components/ui/command";
import { Badge } from "@/src/components/ui/badge";
import { StatusBadge } from "@/src/components/layouts/status-badge";
import {
SidePanel,
SidePanelContent,
SidePanelHeader,
SidePanelTitle,
} from "@/src/components/ui/side-panel";
import { LangfuseIcon } from "@/src/components/LangfuseLogo";
export const EvalTemplateDetail = () => {
const router = useRouter();
const projectId = router.query.projectId as string;
const templateId = router.query.id as string;
const [isEditing, setIsEditing] = useState(false);
// get the current template by id
const template = api.evals.templateById.useQuery({
projectId: projectId,
id: templateId,
});
// get all templates for the current template name
const allTemplates = api.evals.allTemplatesForName.useQuery(
{
projectId: projectId,
name: template.data?.name ?? "",
isUserManaged: template.data?.projectId !== null,
},
{
enabled:
!template.isPending &&
!template.isError &&
template.data?.name !== undefined,
},
);
const handleTemplateSelect = (newTemplate: EvalTemplate) => {
// Update URL without full page reload
router.push(
`/project/${projectId}/evals/templates/${newTemplate.id}`,
undefined,
{ shallow: true },
);
};
return (