"use client" import ProjectCard from "@/components/dashboard/projectCard/" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardTitle, } from "@/components/ui/card" import { HoverCard, HoverCardContent, HoverCardTrigger, } from "@/components/ui/hover-card" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" import { deleteSandbox, updateSandbox } from "@/lib/actions" import { MAX_FREE_GENERATION } from "@/lib/constant" import { Sandbox, User } from "@/lib/types" import { cn } from "@/lib/utils" import { Heart, LucideIcon, Package2, PlusCircle, Sparkles } from "lucide-react" import Link from "next/link" import { useMemo, useState } from "react" import { toast } from "sonner" import Avatar from "../ui/avatar" import { Badge } from "../ui/badge" import { Progress } from "../ui/progress" export default function ProfilePage({ publicSandboxes, privateSandboxes, user, currentUser, }: { publicSandboxes: Sandbox[] privateSandboxes: Sandbox[] user: User currentUser: User | null }) { const [deletingId, setDeletingId] = useState("") const isLoggedIn = Boolean(currentUser) const hasPublicSandboxes = publicSandboxes.length > 0 const hasPrivateSandboxes = privateSandboxes.length > 0 const onVisibilityChange = useMemo( () => async (sandbox: Pick) => { const newVisibility = sandbox.visibility === "public" ? "private" : "public" toast(`Project ${sandbox.name} is now ${newVisibility}.`) await updateSandbox({ id: sandbox.id, visibility: newVisibility, }) }, [] ) const onDelete = useMemo( () => async (sandbox: Pick) => { setDeletingId(sandbox.id) toast(`Project ${sandbox.name} deleted.`) await deleteSandbox(sandbox.id) setDeletingId("") }, [] ) const stats = useMemo(() => { const allSandboxes = isLoggedIn ? [...publicSandboxes, ...privateSandboxes] : publicSandboxes const totalSandboxes = allSandboxes.length const totalLikes = allSandboxes.reduce( (sum, sandbox) => sum + sandbox.likeCount, 0 ) return { sandboxes: totalSandboxes === 1 ? "1 sandbox" : `${totalSandboxes} sandboxes`, likes: totalLikes === 1 ? "1 like" : `${totalLikes} likes`, } }, [isLoggedIn, publicSandboxes, privateSandboxes]) const joinDate = useMemo( () => new Date(user.createdAt).toLocaleDateString("en-US", { month: "long", year: "numeric", }), [user.createdAt] ) return ( <>
{user.name} {`@${user.username}`}

{`Joined ${joinDate}`}

{isLoggedIn && }
Public {isLoggedIn && Private} {hasPublicSandboxes ? (
{publicSandboxes.map((sandbox) => { return ( {isLoggedIn ? ( ) : ( )} ) })}
) : ( )}
{isLoggedIn && ( {hasPrivateSandboxes ? (
{privateSandboxes.map((sandbox) => ( ))}
) : ( )}
)}
) } function EmptyState({ title, description, isLoggedIn, }: { title: string description: string isLoggedIn: boolean }) { return ( {title} {description} {isLoggedIn && ( )} ) } interface StatsItemProps { icon: LucideIcon label: string } const StatsItem = ({ icon: Icon, label }: StatsItemProps) => (
{label}
) const SubscriptionBadge = ({ user }: { user: User }) => { return ( Free
AI Generations {`${user.generations} / ${MAX_FREE_GENERATION}`}
) }