package components import ( "fmt" "time" "github.com/ryanhamamura/games/connect4" "github.com/starfederation/datastar-go/datastar" ) templ GameList(games []GameListItem) { if len(games) > 0 {

Your Games

for _, g := range games { @gameListEntry(g) }
} } templ gameListEntry(g GameListItem) {
{ opponentDisplay(g) } { statusText(g) }
{ formatTimeAgo(g.LastPlayed) }
} func statusText(g GameListItem) string { switch connect4.Status(g.Status) { case connect4.StatusWaitingForPlayer: return "Waiting for opponent" case connect4.StatusInProgress: if g.IsMyTurn { return "Your turn!" } return "Opponent's turn" } return "" } func statusClass(g GameListItem) string { switch connect4.Status(g.Status) { case connect4.StatusWaitingForPlayer: return "text-sm opacity-60" case connect4.StatusInProgress: if g.IsMyTurn { return "text-sm text-success font-bold" } return "text-sm" } return "" } func opponentDisplay(g GameListItem) string { if g.OpponentName == "" { return "Waiting for opponent..." } return "vs " + g.OpponentName } func formatTimeAgo(t time.Time) string { if t.IsZero() { return "" } duration := time.Since(t) if duration < time.Minute { return "just now" } if duration < time.Hour { mins := int(duration.Minutes()) if mins == 1 { return "1 minute ago" } return fmt.Sprintf("%d minutes ago", mins) } if duration < 24*time.Hour { hours := int(duration.Hours()) if hours == 1 { return "1 hour ago" } return fmt.Sprintf("%d hours ago", hours) } days := int(duration.Hours() / 24) if days == 1 { return "yesterday" } return fmt.Sprintf("%d days ago", days) }