import {formatDateIso} from "../_utils/date.ts" import {ratingToClassName} from "../_utils/rating.ts" import { ReviewData } from "../_utils/review.ts"; export type ReviewRowColumnKind = "rating" | "name" | "namesort" | "hascontent" | "date" export type ReviewRowColumnPriority = undefined | "rating" | "progress" | "mixed" export const reviewRowColumnKindDefault: ReviewRowColumnKind[] = ["rating", "name", "namesort", "hascontent", "date"] export type ReviewRowProps = { review: ReviewData, columns?: ReviewRowColumnKind[] priority?: ReviewRowColumnPriority } export function ReviewRow({review, columns = reviewRowColumnKindDefault, priority}: ReviewRowProps) { const activeClass: string = review.active ? "review-active" : "" const activeClassFa: string = review.active ? "fa-beat-fade" : "" const ratingText: string = review.rating ? `${review.rating}` : "" const ratingClass: string = ratingToClassName(review.rating) const priorityClass: string = priority ? `priority-${priority}` : "" const columnsElements = columns.map((kind, index) => { switch(kind) { case "rating": { return ( {ratingText} ) } case "name": { return ( {review.name} ) } case "namesort": { return ( ) } case "hascontent": { return ( {review.content && } ) } case "date": { const date = formatDateIso(review.date) return ( ) } } }) return ( {columnsElements} ) }