"use client"; import { BadgeCheckIcon, ClipboardCheckIcon } from "lucide-react"; import { Badge } from "@/components/ui/badge"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemMedia, ItemTitle, } from "@/components/ui/item"; import { Separator } from "@/components/ui/separator"; import { getLeadershipDisplayLabel, PERFORMANCE_LEVELS } from "@/lib/evaluations/levels"; import { LeadershipEvaluationDialog } from "./LeadershipEvaluationDialog"; import type { EvaluationMissionOption, EvaluationSummary, LatestMissionRow, } from "./evaluation-types"; interface LeadershipEvaluationSectionProps { readonly username: string; readonly summary: EvaluationSummary | null; readonly summaryError: string | null; readonly eligibleMissions: readonly EvaluationMissionOption[]; readonly latestMissionRows: readonly LatestMissionRow[]; readonly canSubmitEvaluation: boolean; readonly canViewSubordinate: boolean; } const PERFORMANCE_GRADIENT = `linear-gradient(to right, ${[...PERFORMANCE_LEVELS] .reverse() .map((level) => level.color) .join(", ")})`; function formatDate(value: string): string { return new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric", year: "numeric", }).format(new Date(value)); } function formatPercentage(value: number): string { return `${value.toFixed(value % 1 === 0 ? 0 : 1)}%`; } export function LeadershipEvaluationSection({ username, summary, summaryError, eligibleMissions, latestMissionRows, canSubmitEvaluation, canViewSubordinate, }: LeadershipEvaluationSectionProps) { return (

Leadership Evaluation

Leadership performance {canSubmitEvaluation && eligibleMissions.length > 0 && ( )} Anonymous ratings from unit members ranked above or below this operator. {summaryError ? (

{summaryError}

) : summary ? ( <> {summary.leader.visible && summary.leader.averageScore !== null && summary.leader.levels !== null ? (
Average rating {Math.round(summary.leader.averageScore)}%
{summary.leader.totalRaters} responses
Needs work Exceptional

Level distribution

All submitted ratings
{PERFORMANCE_LEVELS.map((performanceLevel) => { const levelSummary = summary.leader.levels?.find( (level) => level.id === performanceLevel.id, ); const percentage = levelSummary?.percentage ?? 0; const count = levelSummary?.count ?? 0; return (
{getLeadershipDisplayLabel(performanceLevel)}
{formatPercentage(percentage)} ยท {count}
); })}
{latestMissionRows.length > 0 && (

Latest mission ratings

{latestMissionRows.map((mission) => ( {mission.missionName} {formatDate(mission.startDateTime)} {getLeadershipDisplayLabel(mission.level)} ))}
)}
) : (
Confidential baseline

Leadership ratings remain private until at least three distinct operators have responded.

)} {canViewSubordinate && summary.subordinate && ( <>
Subordinate performance Latest command review
{summary.subordinate.level.label}
Updated {formatDate(summary.subordinate.at)}
)} ) : (

Evaluation data is unavailable right now.

)} {canSubmitEvaluation && eligibleMissions.length === 0 && (

No completed missions with a Yes RSVP are available to rate yet.

)}
); }