"use client";

import { useEffect } from "react";
import { useUser } from "@/hooks/use-user-context";
import { UserEvaluation, Team } from "@/lib/types";

interface ClientWrapperProps {
  userEvaluation: UserEvaluation | null;
  teams: Team[];
  children: React.ReactNode;
}

export function ClientWrapper({
  userEvaluation,
  teams,
  children,
}: ClientWrapperProps) {
  const { setUserInfo } = useUser();

  // Update user info in navigation when user evaluation is loaded
  useEffect(() => {
    if (userEvaluation) {
      const teamName =
        teams.find((t) => t.id === userEvaluation.profile.teamId)?.name || "";
      setUserInfo({
        firstName: userEvaluation.profile.firstName,
        lastName: userEvaluation.profile.lastName,
        teamName,
      });
    } else {
      setUserInfo(null);
    }
  }, [userEvaluation, teams, setUserInfo]);

  return <>{children}</>;
}
