"use client"; import { ArrowLeft, ArrowRightLeft, Clock, Pencil, RotateCcw, TrendingUp, XCircle } from "lucide-react"; import Link from "next/link"; import { useState } from "react"; import { Avatar } from "@/components/ui/Avatar"; import { StatusChip } from "@/components/ui/StatusChip"; import { tenure } from "@/lib/format"; import type { Database } from "@/lib/supabase/types"; import { DatenAendernPanel } from "./panels/DatenAendernPanel"; import { KarenzPanel } from "./panels/KarenzPanel"; import { PromotePanel } from "./panels/PromotePanel"; import { RehirePanel } from "./panels/RehirePanel"; import { TerminatePanel } from "./panels/TerminatePanel"; import { TransferPanel } from "./panels/TransferPanel"; import { HistorieTab } from "./tabs/HistorieTab"; import { OrganisationTab } from "./tabs/OrganisationTab"; import { StammdatenTab } from "./tabs/StammdatenTab"; import { VertragTab } from "./tabs/VertragTab"; type EmployeeRow = Database["public"]["Tables"]["employees"]["Row"]; type Division = Database["public"]["Tables"]["divisions"]["Row"]; type Department = Database["public"]["Tables"]["departments"]["Row"]; type Team = Database["public"]["Tables"]["teams"]["Row"]; type Location = Database["public"]["Tables"]["locations"]["Row"]; type HistoryRow = Database["public"]["Tables"]["employee_history"]["Row"]; type MiniEmployee = { id: string; first_name: string; last_name: string; job_title: string; status?: string }; type OpenPosition = { id: string; position_number: string; title: string; team_id: string; is_lead: boolean }; type EmployeeDetailProps = { employee: EmployeeRow; manager: MiniEmployee | null; directReports: MiniEmployee[]; history: HistoryRow[]; divisions: Division[]; departments: Department[]; teams: Team[]; locations: Location[]; openPositions: OpenPosition[]; }; type PanelType = "transfer" | "promote" | "karenz" | "daten" | "terminate" | "rehire" | null; const TABS = ["Stammdaten", "Vertrag", "Organisation", "Historie"] as const; export function EmployeeDetail(props: EmployeeDetailProps) { const { employee, manager, directReports, history, divisions, departments, teams, locations } = props; const [tab, setTab] = useState<(typeof TABS)[number]>("Stammdaten"); const [panel, setPanel] = useState(null); const division = divisions.find((d) => d.id === employee.division_id); const team = employee.team_id ? teams.find((t) => t.id === employee.team_id) : undefined; const department = team ? departments.find((d) => d.id === team.department_id) : undefined; const breadcrumb = [division?.name, department?.name, team?.name].filter(Boolean).join(" › ") || "–"; const location = locations.find((l) => l.id === employee.location_id); const isActive = employee.status === "Aktiv" || employee.status === "Karenz"; return (
Zurück zu Mitarbeiter:innen

{employee.first_name} {employee.last_name}

{employee.job_title}

{breadcrumb}

Pers.-Nr. {employee.personnel_number} {employee.status !== "Geplant" && <> · Zugehörigkeit: {tenure(employee.entry_date, employee.exit_date)}}

{isActive && ( <> setPanel("transfer")} /> setPanel("promote")} /> setPanel("karenz")} /> setPanel("daten")} /> )} {employee.status === "Ausgetreten" && ( )}
{TABS.map((t) => ( ))}
{tab === "Stammdaten" && } {tab === "Vertrag" && } {tab === "Organisation" && } {tab === "Historie" && }
setPanel(null)} employee={employee} divisions={divisions} departments={departments} teams={teams} currentTeamId={employee.team_id} /> setPanel(null)} employee={employee} /> setPanel(null)} employee={employee} /> setPanel(null)} employee={employee} /> setPanel(null)} employee={employee} directReportCount={directReports.length} /> setPanel(null)} employee={employee} />
); } function ActionButton({ icon: Icon, label, onClick }: { icon: typeof ArrowRightLeft; label: string; onClick: () => void }) { return ( ); }