"use client"; import React, { useEffect, useState } from "react"; import { useParams, useRouter } from "next/navigation"; import { Button, Badge, RenderAppBreadcrumb } from "ikoncomponents"; import { Pencil, CalendarDays, UserRound, Building2, Hash } from "lucide-react"; import { getProjectByIdentifierApi } from "@/app/utils/api/projectApi"; import { useAppCache } from "@/app/utils/context/AppCacheContext"; import { Project } from "../types/project"; export default function ProjectDetailsLayout({ children, }: { children: React.ReactNode; }) { const router = useRouter(); const { projectIdentifier } = useParams(); // Resolves the project manager UUID to a display name. const { userNameMap } = useAppCache(); const [project, setProject] = useState(null); useEffect(() => { if (!projectIdentifier) return; let active = true; getProjectByIdentifierApi(projectIdentifier as string) .then((data) => { if (active) setProject(data); }) .catch((error) => console.error("Failed to load project", error)); return () => { active = false; }; }, [projectIdentifier]); const managerName = project?.projectManager ? userNameMap.get(project.projectManager) ?? "—" : "—"; const startDate = project?.contractedStartDate || project?.projectStartDate || "—"; // Initials for the avatar tile (first letter of up to two name words). const initials = (project?.projectName || "") .split(" ") .filter(Boolean) .slice(0, 2) .map((word) => word[0]) .join("") .toUpperCase() || "—"; // Map a status to a badge style so the state reads at a glance. const statusVariant = (() => { switch (project?.projectStatus?.toLowerCase()) { case "completed": return "verified" as const; case "active": case "ongoing": return "default" as const; default: return "secondary" as const; } })(); const handleEdit = () => { router.push(`/main/planning/projects/${projectIdentifier}?mode=edit`); }; return (
{/* App-bar breadcrumb (same mechanism as the FX Rate page). The sidebar shell sets level 1 ("Projects"); this registers the project name at level 2 and updates once the project has loaded. */}
{/* Top accent bar */}
{/* Title row: avatar + name/subtitle + edit */}
{/* Avatar tile */}
{initials}

{project?.projectName ?? "—"}

{project?.projectStatus ?? "—"}
{projectIdentifier}
{/* Divider */}
{/* Meta row: icon-tiled fields */}

Project Manager

{managerName}

Client

{project?.accountName || "—"}

Start Date

{startDate}

{/* ================= MAIN CONTENT ================= */}
{children}
); }