import { useMemo } from "react";
import { Box, Stack, Typography } from "@mui/material";
import { formatDateTime } from "@/lib/time-utils";
export type CommentTimelineItem = {
id: string | number;
author: string;
createdAt?: string;
body: string;
};
type CommentTimelineProps = {
items: CommentTimelineItem[];
emptyMessage?: string;
maxHeightClass?: string;
};
export function CommentTimeline({
items,
emptyMessage = "No comments yet.",
maxHeightClass = "max-h-72",
}: CommentTimelineProps) {
const sorted = useMemo(
() =>
[...items].sort((a, b) => {
const aTime = a.createdAt ? new Date(a.createdAt).getTime() : 0;
const bTime = b.createdAt ? new Date(b.createdAt).getTime() : 0;
return aTime - bTime;
}),
[items],
);
if (!sorted.length) {
return {emptyMessage};
}
return (
{sorted.map((item) => (
{item.author}
{item.createdAt ? formatDateTime(item.createdAt) : ""}
{item.body}
))}
);
}