Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 57x 1x 1x 19x 19x 19x 19x 19x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 215x 215x 215x 215x 215x 215x 215x 1x 1x 1x 1x 1x 1x 180x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 171x 171x 1x 1x 80x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 172x 1x 1x 1x 1x 1x 311x 311x 311x 311x 311x 1x 1x 1x 1x 1x 1x 308x 308x 19x 1x 1x 1x 1x 1x 1x 1x 311x 311x 18x 18x 18x 18x 311x 18x 1x 1x 311x 311x 1x 1x 107x 179x 107x 1x 1x 191x 107x 107x 107x 107x 107x 107x 107x 107x 107x 191x 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 321x 1179x 321x 321x 321x 321x 321x 321x 321x 321x 321x 321x 214x 214x 107x 107x 107x 107x 182x 12x 12x 12x 12x 12x 12x 107x 107x 107x 107x 107x 107x 107x 107x 108x 107x 1x | <template>
<div
:class="[
'bg-card rounded-xl shadow-sm border border-line overflow-hidden',
compact ? 'mb-3 sm:mb-6' : 'mb-6',
]"
data-testid="tournament-hero"
>
<!-- Status ribbon: where this tournament is in its own life. Hidden
entirely when the tournament has no parsable dates — unknown renders
as absent, not as "upcoming". -->
<div
v-if="status"
class="flex items-center gap-2 flex-wrap px-4 sm:px-5 py-2 bg-brand-600 text-white text-xs font-medium tracking-wide"
data-testid="tournament-status-ribbon"
:data-state="status.state"
>
<span
class="w-1.5 h-1.5 rounded-full shrink-0"
:class="
status.state === 'live' ? 'bg-red-400 animate-pulse' : 'bg-accent-400'
"
></span>
<span class="uppercase">{{ status.label }}</span>
<span v-if="ribbonStageLabel" class="opacity-60">·</span>
<span v-if="ribbonStageLabel" class="uppercase opacity-90">{{
ribbonStageLabel
}}</span>
<span
v-if="countdown"
class="ml-auto font-mono tabular-nums"
data-testid="tournament-countdown"
>{{ countdown }} to
{{ status.state === 'live' ? 'next kickoff' : 'first kickoff' }}</span
>
</div>
<!-- The admin's one line (SB-1797). Its own strip under the ribbon, so it
shows even when the ribbon is hidden for want of dates. None set: no
element at all. -->
<div
v-if="announcement"
class="flex items-start gap-2 px-4 sm:px-5 py-2 bg-brand-700 text-accent-300 text-sm font-semibold break-words"
data-testid="tournament-announcement"
:title="compact ? announcement : undefined"
>
<svg
viewBox="0 0 24 24"
class="mt-0.5 h-4 w-4 shrink-0"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M3 11v2a1 1 0 0 0 1 1h2l5 4V6L6 10H4a1 1 0 0 0-1 1Z" />
<path d="M15.5 8.5a5 5 0 0 1 0 7M18.5 5.5a9 9 0 0 1 0 13" />
</svg>
<span
:class="['min-w-0', compact ? 'line-clamp-2 sm:line-clamp-none' : '']"
>{{ announcement }}</span
>
</div>
<!-- Compact on a phone for a large tournament (SB-1865): one-line title
and dates / location, the rest behind "More", so the day strip is on
the first screen. From `sm` up nothing is hidden. -->
<div
:class="[
'px-4 sm:px-5 flex items-start gap-3 sm:gap-4 flex-wrap',
compact ? 'pt-3 sm:pt-4' : 'pt-4',
compact && !expanded ? 'max-sm:pb-3' : '',
]"
>
<img
v-if="tournament.logo_url"
:src="tournament.logo_url"
:alt="`${tournament.name} logo`"
:class="[
'object-contain shrink-0',
compact ? 'w-10 h-10 sm:w-16 sm:h-16' : 'w-14 h-14 sm:w-16 sm:h-16',
]"
data-testid="tournament-logo"
/>
<div class="min-w-0 flex-1">
<div class="flex items-start gap-2">
<h2
:class="[
'flex-1 min-w-0 text-xl sm:text-2xl font-bold text-fg leading-tight',
compact ? 'max-sm:text-lg max-sm:truncate' : '',
]"
:title="compact ? tournament.name : undefined"
>
{{ tournament.name }}
</h2>
<button
v-if="compact"
type="button"
class="sm:hidden shrink-0 -mt-1.5 -mr-2 h-11 px-3 rounded-full text-sm font-medium text-brand-600 dark:text-brand-300 hover:bg-surface-alt focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500"
:aria-expanded="expanded ? 'true' : 'false'"
data-testid="tournament-hero-more"
@click="expanded = !expanded"
>
{{ expanded ? 'Less' : 'More' }}
</button>
</div>
<div
:class="[
'flex flex-wrap items-center gap-x-2 gap-y-1 text-sm text-fg-muted',
compact ? 'mt-0.5 sm:mt-1.5' : 'mt-1.5',
]"
>
<span v-if="dateRange">{{ dateRange }}</span>
<span v-if="dateRange && tournament.location" aria-hidden="true"
>·</span
>
<span v-if="tournament.location">{{ tournament.location }}</span>
<template v-for="ag in tournament.age_groups || []" :key="ag.id">
<span :class="extraClass" aria-hidden="true">·</span>
<TournamentChip :class="extraClass" variant="age">{{
ag.name
}}</TournamentChip>
</template>
<span :class="extraClass" aria-hidden="true">·</span>
<span :class="extraClass"
>{{ matchCount }} {{ matchCount === 1 ? 'match' : 'matches' }}</span
>
<template v-if="descriptionLink">
<span aria-hidden="true">·</span>
<a
:href="descriptionLink.href"
target="_blank"
rel="noopener noreferrer"
class="text-brand-600 dark:text-brand-300 hover:text-accent-600 dark:hover:text-accent-300 font-medium underline underline-offset-2"
data-testid="tournament-schedule-link"
@click.stop
>{{ descriptionLink.label }} ↗</a
>
</template>
</div>
<p
v-if="descriptionText"
:class="['mt-2 text-sm text-fg-muted', extraClass]"
data-testid="tournament-description"
>
{{ descriptionText }}
</p>
</div>
<slot name="actions" />
</div>
<!-- Your next match. Absent for signed-out visitors and for a club with no
fixtures here — the strip collapses rather than rendering an empty
promise. -->
<div
v-if="nextMyMatch"
class="mx-4 sm:mx-5 mt-4 rounded-lg border border-accent-400 bg-accent-50 dark:bg-accent-900/30 px-3 sm:px-4 py-2.5 flex items-center gap-3 flex-wrap cursor-pointer hover:border-accent-500 transition-colors"
data-testid="tournament-next-match"
@click="$emit('select-match', nextMyMatch)"
>
<span
class="text-[10px] font-semibold uppercase tracking-widest text-accent-700 dark:text-accent-300 shrink-0"
>Your next match</span
>
<span class="flex-1 min-w-[180px] text-sm font-semibold text-fg truncate">
{{ nextMyMatch.home_team?.name }}
<span class="font-normal text-fg-muted"
>vs {{ nextMyMatch.away_team?.name }}</span
>
</span>
<span
class="font-mono text-xs font-semibold text-fg tabular-nums shrink-0"
>
{{ nextMyMatchWhen }}
</span>
</div>
<!-- Quick stats. Every tile is a plain count of what is on this page, so
none of them need a coverage denominator; the "played" tile is dimmed
at zero because zero played is an honest count of a tournament that has
not started, not a missing measurement. -->
<div :class="['mt-4 border-t border-line flex flex-wrap', extraClass]">
<div
v-for="stat in stats"
:key="stat.key"
class="flex-1 min-w-[88px] px-4 sm:px-5 py-2.5 border-r border-line last:border-r-0"
data-testid="tournament-stat"
>
<div
:class="[
'text-xl sm:text-2xl font-bold leading-none tabular-nums',
stat.dim ? 'text-fg-muted' : 'text-fg',
]"
>
{{ stat.value }}
</div>
<div
class="text-[10px] font-semibold uppercase tracking-widest text-fg-muted mt-1"
>
{{ stat.label }}
</div>
</div>
</div>
</div>
</template>
<script setup>
import { computed, onMounted, onUnmounted, ref } from 'vue';
import TournamentChip from './ui/TournamentChip.vue';
import {
tournamentStatus,
formatCountdown,
formatTournamentDateRange,
isMyMatch,
relativeDayLabel,
SCORED_STATUSES,
} from '../utils/tournamentStatus';
import { announcementText } from '../composables/useTournamentAnnouncements';
const props = defineProps({
tournament: { type: Object, required: true },
matches: { type: Array, default: () => [] },
// Exact size of the tournament when `matches` is only part of it — a large
// tournament is paged (SB-1749). Null means `matches` is all of them.
totalMatches: { type: Number, default: null },
myClubId: { type: Number, default: null },
myTeamId: { type: Number, default: null },
stageLabel: { type: String, default: null },
});
defineEmits(['select-match']);
// A ticking clock so "22h 14m" stays true without a page refresh. One interval
// for the whole card; cleared on unmount.
const now = ref(new Date());
let timer = null;
onMounted(() => {
timer = setInterval(() => {
now.value = new Date();
}, 30000);
});
onUnmounted(() => {
if (timer) clearInterval(timer);
});
// `matches` is one page of a larger tournament. Anything read off it — a live
// match, the next kickoff, the stage in play, the viewer's next match — would
// describe that page and could be wrong for the tournament, so none is shown.
const isPartial = computed(() => props.totalMatches != null);
// A large tournament's card folds on a phone (SB-1865); `extraClass` hides
// what "More" reveals, below `sm` only.
const compact = isPartial;
const expanded = ref(false);
const extraClass = computed(() =>
compact.value && !expanded.value ? 'max-sm:hidden' : ''
);
// For a partial list the status comes from the tournament's own dates alone:
// "Happening today" and "Completed" are true without a single match, while
// "Live now" and the countdown are not knowable from a page.
const status = computed(() =>
tournamentStatus(
props.tournament,
isPartial.value ? [] : props.matches,
now.value
)
);
const announcement = computed(() => announcementText(props.tournament));
const ribbonStageLabel = computed(() =>
isPartial.value ? null : props.stageLabel
);
const countdown = computed(() => {
const target = status.value?.countdownTo;
if (!target) return null;
return formatCountdown(new Date(target) - now.value);
});
const dateRange = computed(() => formatTournamentDateRange(props.tournament));
const matchCount = computed(() => props.totalMatches ?? props.matches.length);
// `tournaments.description` is frequently just the source schedule URL. Render
// it as a named link rather than as a 66-character string of body text.
const URL_RE = /^https?:\/\/\S+$/i;
const descriptionLink = computed(() => {
const raw = (props.tournament.description || '').trim();
if (!URL_RE.test(raw)) return null;
let label = 'View schedule';
try {
const host = new URL(raw).hostname.replace(/^www\./, '');
if (host.includes('gotsport')) label = 'Schedule on GotSport';
else label = `Schedule on ${host}`;
} catch {
// Unparsable despite matching the shape — fall back to the generic label.
}
return { href: raw, label };
});
const descriptionText = computed(() => {
const raw = (props.tournament.description || '').trim();
return raw && !URL_RE.test(raw) ? raw : null;
});
const myMatches = computed(() =>
props.matches.filter(m =>
isMyMatch(m, { clubId: props.myClubId, teamId: props.myTeamId })
)
);
const nextMyMatch = computed(() => {
if (isPartial.value) return null;
const upcoming = myMatches.value
.filter(m => !SCORED_STATUSES.includes(m.match_status))
.filter(m => m.match_status !== 'cancelled')
.filter(
m => !m.scheduled_kickoff || new Date(m.scheduled_kickoff) > now.value
)
.slice()
.sort((a, b) =>
(a.scheduled_kickoff || '') < (b.scheduled_kickoff || '') ? -1 : 1
);
return upcoming[0] ?? null;
});
const nextMyMatchWhen = computed(() => {
const m = nextMyMatch.value;
if (!m) return '';
const day = relativeDayLabel(m.match_date, now.value);
const dayLabel =
day ??
(m.match_date
? new Date(
`${String(m.match_date).slice(0, 10)}T00:00:00`
).toLocaleDateString('en-US', { weekday: 'short' })
: '');
if (!m.scheduled_kickoff) return dayLabel;
const time = new Date(m.scheduled_kickoff).toLocaleTimeString('en-US', {
hour: 'numeric',
minute: '2-digit',
hour12: true,
});
const away = formatCountdown(new Date(m.scheduled_kickoff) - now.value);
return away ? `${dayLabel} ${time} · in ${away}` : `${dayLabel} ${time}`;
});
const stats = computed(() => {
const played = props.matches.filter(m =>
SCORED_STATUSES.includes(m.match_status)
).length;
const days = new Set(
props.matches
.map(m => m.match_date)
.filter(Boolean)
.map(d => String(d).slice(0, 10))
).size;
// Part of a larger tournament: played, days and "your matches" counted from
// the loaded rows would be numbers about a page. Only the total is known.
if (props.totalMatches != null) {
return [{ key: 'total', value: props.totalMatches, label: 'Matches' }];
}
const out = [];
// Only shown when the viewer actually has a club in this tournament —
// otherwise the tile would read "0 your matches", which is a claim about a
// club that isn't here.
if (myMatches.value.length > 0) {
out.push({
key: 'mine',
value: myMatches.value.length,
label: 'Your matches',
});
}
out.push({
key: 'played',
value: played,
label: 'Played',
dim: played === 0,
});
out.push({ key: 'total', value: props.matches.length, label: 'Matches' });
if (days > 0)
out.push({ key: 'days', value: days, label: days === 1 ? 'Day' : 'Days' });
return out;
});
</script>
|