import {formatDateIso} from "../_utils/date.ts" import {GameData} from "../_utils/game.ts" import {GameProgress, gameProgressToClassName, gameProgressToIconDef, gameProgressToTitle} from "../_utils/game.ts" import {ratingToClassName} from "../_utils/rating.ts" export type GameRowColumnKind = "rating" | "progress" | "name" | "namesort" | "hascontent" | "date" | "hoursplayed" export type GameRowColumnPriority = undefined | "rating" | "progress" | "mixed" export const gameRowColumnKindDefault: GameRowColumnKind[] = ["rating", "name", "namesort", "hascontent", "date", "progress", "hoursplayed"] export type GameRowProps = { game: GameData, columns?: GameRowColumnKind[] priority?: GameRowColumnPriority } export function GameRow({game, columns = gameRowColumnKindDefault, priority}: GameRowProps) { const activeClass: string = game.active ? "review-active" : "" const activeClassFa: string = game.active ? "fa-beat-fade" : "" const ratingText: string = game.rating ? `${game.rating}` : "" const ratingClass: string = ratingToClassName(game.rating) const progressClass: string = gameProgressToClassName(game.progress) const progressIcon: string = gameProgressToIconDef(game.progress) const progressTitle: string = gameProgressToTitle(game.progress) const priorityClass: string = priority ? `priority-${priority}` : "" const columnsElements = columns.map((kind, index) => { switch(kind) { case "rating": { return ( {ratingText} ) } case "progress": { return ( {progressIcon && } ) } case "name": { return ( {game.name} ) } case "namesort": { return ( ) } case "hascontent": { return ( {game.content && } ) } case "date": { const date = formatDateIso(game.date) return ( ) } case "hoursplayed": { return ( {(game.hours_played ?? 0) > 0 ? `${game.hours_played} h` : ""} ) } } }) return ( {columnsElements} ) }