2026-03-06 16:27:54 +00:00
|
|
|
<script setup lang="ts">
|
2026-03-06 22:13:19 +00:00
|
|
|
import { ref, onMounted, onUnmounted } from 'vue'
|
|
|
|
|
import { useRoute, useRouter, RouterLink } from 'vue-router'
|
|
|
|
|
import { useNostr } from '../composables/useNostr'
|
2026-03-06 16:27:54 +00:00
|
|
|
|
2026-03-06 22:13:19 +00:00
|
|
|
const route = useRoute()
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
const { bot: nostrBot, isLoggedIn, logout } = useNostr()
|
|
|
|
|
const botName = route.params.name as string
|
|
|
|
|
|
|
|
|
|
interface BotStats {
|
2026-03-06 16:27:54 +00:00
|
|
|
id: string
|
|
|
|
|
name: string
|
|
|
|
|
avatarSeed: string
|
2026-03-06 22:13:19 +00:00
|
|
|
profilePicUrl: string | null
|
2026-03-06 16:27:54 +00:00
|
|
|
eloRating: number
|
|
|
|
|
wins: number
|
|
|
|
|
losses: number
|
|
|
|
|
winStreak: number
|
|
|
|
|
bestStreak: number
|
|
|
|
|
tier: number
|
2026-03-06 22:13:19 +00:00
|
|
|
tierName: string
|
|
|
|
|
tierColor: string
|
|
|
|
|
winRate: number
|
|
|
|
|
totalFights: number
|
|
|
|
|
rank: number
|
|
|
|
|
totalBots: number
|
2026-03-06 16:27:54 +00:00
|
|
|
createdAt: string
|
2026-03-06 22:13:19 +00:00
|
|
|
recentFights: {
|
|
|
|
|
id: string
|
|
|
|
|
opponent: string
|
|
|
|
|
result: string
|
|
|
|
|
rounds: number
|
|
|
|
|
arena: string
|
|
|
|
|
date: string
|
|
|
|
|
}[]
|
2026-03-06 16:27:54 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-06 22:13:19 +00:00
|
|
|
interface QueueEntry {
|
|
|
|
|
botId: string
|
|
|
|
|
botName: string
|
|
|
|
|
eloRating: number
|
2026-03-06 16:27:54 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-06 22:13:19 +00:00
|
|
|
const stats = ref<BotStats | null>(null)
|
2026-03-06 16:27:54 +00:00
|
|
|
const isLoading = ref(true)
|
2026-03-06 22:13:19 +00:00
|
|
|
const isJoining = ref(false)
|
|
|
|
|
const showChoose = ref(false)
|
|
|
|
|
const waitingFighters = ref<QueueEntry[]>([])
|
|
|
|
|
let pollHandle: ReturnType<typeof setInterval> | null = null
|
|
|
|
|
|
|
|
|
|
const isOwner = ref(false)
|
2026-03-06 16:27:54 +00:00
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
try {
|
2026-03-06 22:13:19 +00:00
|
|
|
const res = await fetch(`/api/bots/${encodeURIComponent(botName)}/stats`)
|
|
|
|
|
if (res.ok) stats.value = await res.json()
|
2026-03-06 16:27:54 +00:00
|
|
|
} catch { /* */ }
|
|
|
|
|
isLoading.value = false
|
2026-03-06 22:13:19 +00:00
|
|
|
|
|
|
|
|
// Check ownership
|
|
|
|
|
isOwner.value = isLoggedIn.value && nostrBot.value?.name === botName
|
|
|
|
|
|
|
|
|
|
// Poll queue for "choose your fight"
|
|
|
|
|
pollQueue()
|
|
|
|
|
pollHandle = setInterval(pollQueue, 4000)
|
2026-03-06 16:27:54 +00:00
|
|
|
})
|
|
|
|
|
|
2026-03-06 22:13:19 +00:00
|
|
|
onUnmounted(() => {
|
|
|
|
|
if (pollHandle) clearInterval(pollHandle)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
async function pollQueue() {
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch('/api/queue/status')
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
const data = await res.json()
|
|
|
|
|
waitingFighters.value = data.queue || []
|
|
|
|
|
}
|
|
|
|
|
} catch { /* */ }
|
2026-03-06 16:27:54 +00:00
|
|
|
}
|
2026-03-06 22:13:19 +00:00
|
|
|
|
|
|
|
|
async function instantFight() {
|
|
|
|
|
if (!stats.value || isJoining.value) return
|
|
|
|
|
isJoining.value = true
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(`/api/queue/join/${stats.value.id}`, { method: 'POST' })
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
const data = await res.json()
|
|
|
|
|
router.push(`/arena/${data.fightId}`)
|
|
|
|
|
}
|
|
|
|
|
} catch { /* */ }
|
|
|
|
|
isJoining.value = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function fightSpecific(opponentBotId: string) {
|
|
|
|
|
if (!stats.value || isJoining.value) return
|
|
|
|
|
isJoining.value = true
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(`/api/fights/matchmake/${stats.value.id}`, { method: 'POST' })
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
const data = await res.json()
|
|
|
|
|
router.push(`/arena/${data.fightId}`)
|
|
|
|
|
}
|
|
|
|
|
} catch { /* */ }
|
|
|
|
|
isJoining.value = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleSignOut() {
|
|
|
|
|
logout()
|
|
|
|
|
router.push('/')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const tierClass = (t: number) => `tier-${t}`
|
2026-03-06 16:27:54 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div class="h-[calc(100vh-4rem)] flex flex-col px-6 py-6 overflow-hidden">
|
2026-03-06 22:13:19 +00:00
|
|
|
<div class="max-w-lg mx-auto w-full flex flex-col flex-1 min-h-0">
|
2026-03-06 16:27:54 +00:00
|
|
|
|
|
|
|
|
<div v-if="isLoading" class="flex-1 flex items-center justify-center">
|
|
|
|
|
<p class="font-display text-text-muted animate-pulse">LOADING...</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-03-06 22:13:19 +00:00
|
|
|
<div v-else-if="!stats" class="flex-1 flex items-center justify-center">
|
2026-03-06 16:27:54 +00:00
|
|
|
<p class="font-display text-text-muted">Bot not found.</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<template v-else>
|
2026-03-06 22:13:19 +00:00
|
|
|
<!-- Header -->
|
|
|
|
|
<div class="text-center mb-5">
|
|
|
|
|
<img
|
|
|
|
|
v-if="stats.profilePicUrl"
|
|
|
|
|
:src="stats.profilePicUrl"
|
|
|
|
|
alt=""
|
|
|
|
|
class="w-16 h-16 rounded-full mx-auto mb-2 border-2"
|
|
|
|
|
:style="{ borderColor: stats.tierColor }"
|
|
|
|
|
/>
|
|
|
|
|
<p class="font-display text-xs font-bold tracking-[0.2em] mb-1"
|
|
|
|
|
:style="{ color: stats.tierColor }">
|
|
|
|
|
{{ stats.tierName }}
|
2026-03-06 16:27:54 +00:00
|
|
|
</p>
|
2026-03-06 22:13:19 +00:00
|
|
|
<h2 class="font-display font-black text-3xl sm:text-4xl tracking-wider gradient-text">
|
|
|
|
|
{{ stats.name }}
|
2026-03-06 16:27:54 +00:00
|
|
|
</h2>
|
2026-03-06 22:13:19 +00:00
|
|
|
<p class="font-mono text-text-muted text-[10px] mt-1">
|
|
|
|
|
#{{ stats.rank }} of {{ stats.totalBots }}
|
2026-03-06 16:27:54 +00:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-03-06 22:13:19 +00:00
|
|
|
<!-- Stats -->
|
|
|
|
|
<div class="grid grid-cols-3 gap-2 mb-4">
|
|
|
|
|
<div class="border border-border bg-surface-raised/50 p-2.5 text-center">
|
|
|
|
|
<p class="font-display font-black text-xl text-neon-cyan">{{ Math.round(stats.eloRating) }}</p>
|
|
|
|
|
<p class="font-display text-[8px] text-text-muted tracking-wider mt-0.5">ELO</p>
|
2026-03-06 16:27:54 +00:00
|
|
|
</div>
|
2026-03-06 22:13:19 +00:00
|
|
|
<div class="border border-border bg-surface-raised/50 p-2.5 text-center">
|
|
|
|
|
<p class="font-display font-black text-xl">
|
|
|
|
|
<span class="text-neon-cyan">{{ stats.wins }}</span>
|
|
|
|
|
<span class="text-text-muted text-sm">-</span>
|
|
|
|
|
<span class="text-neon-pink">{{ stats.losses }}</span>
|
2026-03-06 16:27:54 +00:00
|
|
|
</p>
|
2026-03-06 22:13:19 +00:00
|
|
|
<p class="font-display text-[8px] text-text-muted tracking-wider mt-0.5">RECORD</p>
|
2026-03-06 16:27:54 +00:00
|
|
|
</div>
|
2026-03-06 22:13:19 +00:00
|
|
|
<div class="border border-border bg-surface-raised/50 p-2.5 text-center">
|
|
|
|
|
<p class="font-display font-black text-xl"
|
|
|
|
|
:class="stats.winRate >= 60 ? 'text-neon-cyan' : stats.winRate >= 40 ? 'text-neon-yellow' : 'text-neon-pink'">
|
|
|
|
|
{{ stats.winRate }}%
|
2026-03-06 16:27:54 +00:00
|
|
|
</p>
|
2026-03-06 22:13:19 +00:00
|
|
|
<p class="font-display text-[8px] text-text-muted tracking-wider mt-0.5">WIN RATE</p>
|
2026-03-06 16:27:54 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-03-06 22:13:19 +00:00
|
|
|
<!-- Streaks row -->
|
|
|
|
|
<div class="flex gap-2 mb-4">
|
|
|
|
|
<div class="flex-1 border border-border bg-surface-raised/50 p-2.5 text-center">
|
|
|
|
|
<p class="font-display font-bold text-base"
|
|
|
|
|
:class="stats.winStreak >= 3 ? 'text-neon-yellow' : 'text-text-primary'">
|
|
|
|
|
{{ stats.winStreak > 0 ? `${stats.winStreak}x` : '-' }}
|
|
|
|
|
</p>
|
|
|
|
|
<p class="font-display text-[8px] text-text-muted tracking-wider mt-0.5">STREAK</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex-1 border border-border bg-surface-raised/50 p-2.5 text-center">
|
|
|
|
|
<p class="font-display font-bold text-base text-text-primary">{{ stats.bestStreak }}x</p>
|
|
|
|
|
<p class="font-display text-[8px] text-text-muted tracking-wider mt-0.5">BEST</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex-1 border border-border bg-surface-raised/50 p-2.5 text-center">
|
|
|
|
|
<p class="font-display font-bold text-base text-text-primary">{{ stats.totalFights }}</p>
|
|
|
|
|
<p class="font-display text-[8px] text-text-muted tracking-wider mt-0.5">FIGHTS</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Fight actions (only for owner or anyone for now) -->
|
|
|
|
|
<div class="flex gap-2 mb-4">
|
|
|
|
|
<button
|
|
|
|
|
class="flex-1 py-3 bg-neon-pink/10 border-2 border-neon-pink/50 text-neon-pink
|
|
|
|
|
font-display font-black text-sm tracking-wider
|
|
|
|
|
hover:bg-neon-pink/20 transition-all neon-border-pink
|
|
|
|
|
disabled:opacity-30 disabled:cursor-not-allowed"
|
|
|
|
|
:disabled="isJoining"
|
|
|
|
|
@click="instantFight"
|
|
|
|
|
>
|
|
|
|
|
{{ isJoining ? 'MATCHING...' : 'INSTANT FIGHT' }}
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
class="flex-1 py-3 border-2 border-neon-purple/50 text-neon-purple
|
|
|
|
|
font-display font-bold text-sm tracking-wider
|
|
|
|
|
hover:bg-neon-purple/10 transition-all"
|
|
|
|
|
@click="showChoose = !showChoose"
|
|
|
|
|
>
|
|
|
|
|
CHOOSE FIGHT
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Choose your fight panel -->
|
|
|
|
|
<div v-if="showChoose" class="mb-4 border border-border bg-surface-raised/50 p-3">
|
|
|
|
|
<p class="font-display text-[10px] font-bold text-text-muted tracking-[0.15em] mb-2">
|
|
|
|
|
FIGHTERS WAITING
|
|
|
|
|
</p>
|
|
|
|
|
<div v-if="waitingFighters.length === 0" class="text-center py-3">
|
|
|
|
|
<p class="font-mono text-xs text-text-muted">Nobody waiting. Use Instant Fight instead.</p>
|
|
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
v-for="fighter in waitingFighters"
|
|
|
|
|
:key="fighter.botId"
|
|
|
|
|
class="w-full flex items-center justify-between px-3 py-2 border border-border
|
|
|
|
|
hover:border-neon-cyan/30 hover:bg-neon-cyan/5 transition-all mb-1 text-xs
|
|
|
|
|
disabled:opacity-30"
|
|
|
|
|
:disabled="isJoining || fighter.botId === stats.id"
|
|
|
|
|
@click="fightSpecific(fighter.botId)"
|
|
|
|
|
>
|
|
|
|
|
<span class="font-display font-bold text-text-primary">{{ fighter.botName }}</span>
|
|
|
|
|
<span class="font-mono text-text-muted">{{ Math.round(fighter.eloRating) }} ELO</span>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Recent fights -->
|
|
|
|
|
<p class="font-display text-[10px] font-bold text-text-muted tracking-[0.15em] mb-2">
|
|
|
|
|
RECENT BOUTS
|
2026-03-06 16:27:54 +00:00
|
|
|
</p>
|
2026-03-06 22:13:19 +00:00
|
|
|
<div class="flex-1 min-h-0 overflow-y-auto space-y-1.5">
|
2026-03-06 16:27:54 +00:00
|
|
|
<RouterLink
|
2026-03-06 22:13:19 +00:00
|
|
|
v-for="fight in stats.recentFights"
|
2026-03-06 16:27:54 +00:00
|
|
|
:key="fight.id"
|
|
|
|
|
:to="`/arena/${fight.id}`"
|
2026-03-06 22:13:19 +00:00
|
|
|
class="flex items-center justify-between px-3 py-2 border border-border
|
|
|
|
|
bg-surface-raised/30 hover:border-neon-pink/30 transition-all text-xs"
|
2026-03-06 16:27:54 +00:00
|
|
|
>
|
2026-03-06 22:13:19 +00:00
|
|
|
<span class="font-display font-bold w-6"
|
|
|
|
|
:class="fight.result === 'W' ? 'text-neon-cyan' : fight.result === 'L' ? 'text-neon-pink' : 'text-text-muted'">
|
|
|
|
|
{{ fight.result }}
|
2026-03-06 16:27:54 +00:00
|
|
|
</span>
|
2026-03-06 22:13:19 +00:00
|
|
|
<span class="font-mono text-text-secondary flex-1 ml-2">vs {{ fight.opponent }}</span>
|
|
|
|
|
<span class="font-mono text-[10px] text-text-muted">R{{ fight.rounds }}</span>
|
2026-03-06 16:27:54 +00:00
|
|
|
</RouterLink>
|
2026-03-06 22:13:19 +00:00
|
|
|
<div v-if="stats.recentFights.length === 0" class="text-center py-4">
|
|
|
|
|
<p class="font-mono text-text-muted text-xs">No fights yet. Hit Instant Fight!</p>
|
2026-03-06 16:27:54 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-06 22:13:19 +00:00
|
|
|
|
|
|
|
|
<!-- Sign out (only if owner) -->
|
|
|
|
|
<div v-if="isOwner" class="mt-3 text-center flex-shrink-0">
|
|
|
|
|
<button
|
|
|
|
|
class="font-mono text-[10px] text-text-muted hover:text-ko transition-colors"
|
|
|
|
|
@click="handleSignOut"
|
|
|
|
|
>
|
|
|
|
|
Sign out
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2026-03-06 16:27:54 +00:00
|
|
|
</template>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|