---
import '../../global.css'
import { firestore, Game, getSession } from '../../lib/game-saving/account'
import Navbar from '../../components/navbar-main'
import StandardHead from '../../components/standard-head.astro'
import ms from 'ms'
import Button from '../../components/design-system/button'
import { IoLogOutOutline, IoTrashOutline } from 'react-icons/io5'
import { isRandomGameName } from '../../lib/words'
const session = await getSession(Astro.cookies)
if (!session || !session.session.full) return Astro.redirect(`/login?to=${Astro.request.url}`, 302)
const _games = await firestore.collection('games')
.where('ownerId', '==', session.user.id)
.orderBy('modifiedAt', 'desc')
.get()
const allGames = _games.docs.map(doc => ({ id: doc.id, ...doc.data() } as Game))
let games = allGames.filter(game => !isRandomGameName(game.name))
let unnamedGames = allGames.filter(game => isRandomGameName(game.name))
if (games.length === 0 && unnamedGames.length > 0) {
games = unnamedGames
unnamedGames = []
}
---
Your Games
{games.length === 0 ? (
It's all spooky and empty here. Make a game already!
) : null}
{unnamedGames.length > 0 ? (
) : null}