import { getProjectWithContract, getNotesForProject, } from "@/lib/queries/projects"; import NoteForm from "@/components/NoteForm"; import ProjectTasksSection from "@/components/ProjectTasksSection"; import { Card, CardHeader, CardContent } from "@/components/ui/Card"; import Button from "@/components/ui/Button"; import Badge from "@/components/ui/Badge"; import Link from "next/link"; import { differenceInCalendarDays, parseISO } from "date-fns"; import { formatDate } from "@/lib/utils"; import PageContainer from "@/components/ui/PageContainer"; import PageHeader from "@/components/ui/PageHeader"; import ProjectStatusDropdown from "@/components/ProjectStatusDropdown"; import ProjectMap from "@/components/ui/ProjectMap"; export default async function ProjectViewPage({ params }) { const { id } = await params; const project = getProjectWithContract(id); const notes = getNotesForProject(id); if (!project) { return (

Project not found.

); } const daysRemaining = project.finish_date ? differenceInCalendarDays(parseISO(project.finish_date), new Date()) : null; const getDeadlineVariant = (days) => { if (days < 0) return "danger"; if (days <= 7) return "warning"; return "success"; }; return ( {daysRemaining !== null && ( {daysRemaining === 0 ? "Due Today" : daysRemaining > 0 ? `${daysRemaining} days left` : `${Math.abs(daysRemaining)} days overdue`} )} } />{" "}
{/* Main Project Information */}
{" "}

Project Information

{project.project_type === "design" ? "Design (P)" : project.project_type === "construction" ? "Construction (R)" : project.project_type === "design+construction" ? "Design + Construction (P+R)" : "Unknown"}
Location

{project.city || "N/A"}

Address

{project.address || "N/A"}

Plot

{project.plot || "N/A"}

District

{project.district || "N/A"}

Unit

{project.unit || "N/A"}

{" "}
Deadline

{project.finish_date ? formatDate(project.finish_date) : "N/A"}

WP

{project.wp || "N/A"}

Investment Number

{project.investment_number || "N/A"}

{project.contact && (
Contact

{project.contact}

)} {project.coordinates && (
Coordinates

{project.coordinates}

)} {project.notes && (
Notes

{project.notes}

)}
{/* Contract Details */}

Contract Details

Contract Number

{project.contract_number || "N/A"}

Contract Name

{project.contract_name || "N/A"}

Customer

{project.customer || "N/A"}

Investor

{project.investor || "N/A"}

{/* Status Sidebar */}

Project Status

{" "}
Current Status
{daysRemaining !== null && (
Timeline
{daysRemaining === 0 ? "Due Today" : daysRemaining > 0 ? `${daysRemaining} days remaining` : `${Math.abs(daysRemaining)} days overdue`}
)}
{/* Quick Actions */}

Quick Actions

{" "}
{" "} {/* Project Location Map */} {project.coordinates && (
{" "}

Project Location

)} {/* Project Tasks Section */}
{/* Notes Section */}

Notes

{notes.length === 0 ? (

No notes yet

Add your first note using the form above.

) : (
{notes.map((n) => (
{n.note_date}

{n.note}

))}
)}
); }