import Image from "next/image"; import Link from "next/link"; import ReactMarkdown from "react-markdown"; import * as Tabs from "@radix-ui/react-tabs"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle, CardDescription, CardFooter } from "@/components/ui/card"; import { Progress } from "@/components/ui/progress"; import { Separator } from "@/components/ui/separator"; import { createSupabaseClient } from "@/lib/supabase/serverComponentClient"; import FollowShareButtons from "./followShareButton"; import { getProjectData } from "@/lib/data/projectQuery"; import { getDealList } from "@/app/api/dealApi"; import { sumByKey, toPercentage } from "@/lib/utils"; import { redirect } from "next/navigation"; import { isOwnerOfProject } from "./query"; import { UpdateTab } from "./UpdateTab"; import remarkGfm from "remark-gfm"; import Gallery from "@/components/carousel"; const PHOTO_MATERIAL_ID = 2; export default async function ProjectDealPage({ params }: { params: { id: number } }) { const supabase = createSupabaseClient(); const { data: projectData, error: projectDataError } = await getProjectData(supabase, params.id); const { data: user, error: userError } = await supabase.auth.getUser(); const { data: projectMaterial, error: projectMaterialError } = await supabase .from("project_material") .select("material_url") .eq("project_id", params.id) .eq("material_type_id", PHOTO_MATERIAL_ID); if (projectMaterialError) { console.error("Error while fetching project material" + projectMaterialError); } if (!projectData) { redirect("/deals"); } if (projectDataError) { return (

Error fetching data. Please try again.

); } if (userError || !user) { return (

Error fetching data. Please try again.

); } const isOwner = await isOwnerOfProject(supabase, params.id, user.user?.id); const projectBusinessOwnerId = projectData.user_id; const dealList = await getDealList(projectBusinessOwnerId); const totalDealAmount = sumByKey(dealList, "deal_amount"); // timeDiff, if negative convert to zero const timeDiff = Math.max(new Date(projectData.investment_deadline).getTime() - new Date().getTime(), 0); const hourLeft = Math.floor(timeDiff / (1000 * 60 * 60)); const carouselData = projectMaterial && projectMaterial.length > 0 ? projectMaterial.flatMap((item) => (item.material_url || ["/boiler1.jpg"]).map((url: string) => ({ src: url, })) ) : [{ src: "/boiler1.jpg", alt: "Default Boiler Image" }]; return (
{/* Name, star and share button packed */}
{/* image carousel */}

${totalDealAmount}

{toPercentage(totalDealAmount, projectData?.target_investment)}% raised of $ {projectData?.target_investment} max goal

{dealList.length}

Investors

{projectData?.investment_deadline ? ( <>

{Math.floor(hourLeft)} hours

Left to invest

) : (

No deadline

)}
{isOwner && ( )}
{/*

${totalDealAmount}

{toPercentage(totalDealAmount, projectData?.target_investment)}% raised of $ {projectData?.target_investment} max goal

{dealList.length}

Investors

{projectData?.investment_deadline ? ( <>

{Math.floor(hourLeft)} hours

Left to invest

) : (

No deadline

)}

Dataroom

*/}
{/* menu */}
Pitch {/* General Data */} Updates {projectData.project_name} Project Pitch
{projectData?.project_description || "No pitch available."}
{/* general general Description

general Content

*/} Update Project log and updates
); }