131 lines
4.5 KiB
Plaintext
131 lines
4.5 KiB
Plaintext
package teamsview
|
|
|
|
import "git.haelnorr.com/h/oslstats/internal/db"
|
|
import "git.haelnorr.com/h/oslstats/internal/view/component/links"
|
|
import "fmt"
|
|
import "sort"
|
|
|
|
templ TeamDetailPlayerStats(playerStats []*db.TeamAllTimePlayerStats) {
|
|
if len(playerStats) == 0 {
|
|
<div class="bg-surface0 border border-surface1 rounded-lg p-8 text-center">
|
|
<p class="text-subtext0 text-lg">No player stats yet.</p>
|
|
<p class="text-subtext1 text-sm mt-2">Player statistics will appear here once games are played.</p>
|
|
</div>
|
|
} else {
|
|
<div x-data="{ activeView: 'goals' }">
|
|
<!-- Sub-view Tabs -->
|
|
<div class="flex gap-2 mb-4">
|
|
<button
|
|
@click="activeView = 'goals'"
|
|
:class="activeView === 'goals'
|
|
? 'bg-blue text-mantle'
|
|
: 'bg-surface0 border border-surface1 text-subtext0 hover:text-text hover:bg-surface1'"
|
|
class="px-4 py-2 rounded-lg font-medium text-sm transition hover:cursor-pointer"
|
|
>
|
|
Goals
|
|
</button>
|
|
<button
|
|
@click="activeView = 'assists'"
|
|
:class="activeView === 'assists'
|
|
? 'bg-blue text-mantle'
|
|
: 'bg-surface0 border border-surface1 text-subtext0 hover:text-text hover:bg-surface1'"
|
|
class="px-4 py-2 rounded-lg font-medium text-sm transition hover:cursor-pointer"
|
|
>
|
|
Assists
|
|
</button>
|
|
<button
|
|
@click="activeView = 'saves'"
|
|
:class="activeView === 'saves'
|
|
? 'bg-blue text-mantle'
|
|
: 'bg-surface0 border border-surface1 text-subtext0 hover:text-text hover:bg-surface1'"
|
|
class="px-4 py-2 rounded-lg font-medium text-sm transition hover:cursor-pointer"
|
|
>
|
|
Saves
|
|
</button>
|
|
</div>
|
|
<!-- Goals View -->
|
|
<div x-show="activeView === 'goals'">
|
|
@playerStatsTable(playerStats, "goals")
|
|
</div>
|
|
<!-- Assists View -->
|
|
<div x-show="activeView === 'assists'" style="display: none;">
|
|
@playerStatsTable(playerStats, "assists")
|
|
</div>
|
|
<!-- Saves View -->
|
|
<div x-show="activeView === 'saves'" style="display: none;">
|
|
@playerStatsTable(playerStats, "saves")
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
|
|
templ playerStatsTable(playerStats []*db.TeamAllTimePlayerStats, statType string) {
|
|
{{
|
|
// Make a copy so sorting doesn't affect other views
|
|
sorted := make([]*db.TeamAllTimePlayerStats, len(playerStats))
|
|
copy(sorted, playerStats)
|
|
|
|
switch statType {
|
|
case "goals":
|
|
sort.Slice(sorted, func(i, j int) bool {
|
|
return sorted[i].Goals > sorted[j].Goals
|
|
})
|
|
case "assists":
|
|
sort.Slice(sorted, func(i, j int) bool {
|
|
return sorted[i].Assists > sorted[j].Assists
|
|
})
|
|
case "saves":
|
|
sort.Slice(sorted, func(i, j int) bool {
|
|
return sorted[i].Saves > sorted[j].Saves
|
|
})
|
|
}
|
|
|
|
statLabel := "Goals"
|
|
statShort := "G"
|
|
if statType == "assists" {
|
|
statLabel = "Assists"
|
|
statShort = "A"
|
|
} else if statType == "saves" {
|
|
statLabel = "Saves"
|
|
statShort = "SV"
|
|
}
|
|
_ = statLabel
|
|
}}
|
|
<div class="bg-surface0 border border-surface1 rounded-lg overflow-hidden">
|
|
<div class="overflow-x-auto">
|
|
<table class="w-full">
|
|
<thead class="bg-mantle border-b border-surface1">
|
|
<tr>
|
|
<th class="px-3 py-2 text-center text-xs font-semibold text-subtext0 w-10">#</th>
|
|
<th class="px-3 py-2 text-left text-xs font-semibold text-text">Player</th>
|
|
<th class="px-2 py-2 text-center text-xs font-semibold text-text" title="Seasons Played">SZN</th>
|
|
<th class="px-2 py-2 text-center text-xs font-semibold text-text" title="Periods Played">PP</th>
|
|
<th class="px-2 py-2 text-center text-xs font-semibold text-blue" title={ statLabel }>{ statShort }</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-surface1">
|
|
for i, ps := range sorted {
|
|
<tr class="hover:bg-surface1 transition-colors">
|
|
<td class="px-3 py-2 text-center text-sm font-medium text-subtext0">
|
|
{ fmt.Sprint(i + 1) }
|
|
</td>
|
|
<td class="px-3 py-2 text-sm font-medium">
|
|
@links.PlayerLinkFromStats(ps.PlayerID, ps.PlayerName)
|
|
</td>
|
|
<td class="px-2 py-2 text-center text-sm text-subtext0">{ fmt.Sprint(ps.SeasonsPlayed) }</td>
|
|
<td class="px-2 py-2 text-center text-sm text-subtext0">{ fmt.Sprint(ps.PeriodsPlayed) }</td>
|
|
if statType == "goals" {
|
|
<td class="px-2 py-2 text-center text-sm font-bold text-blue">{ fmt.Sprint(ps.Goals) }</td>
|
|
} else if statType == "assists" {
|
|
<td class="px-2 py-2 text-center text-sm font-bold text-blue">{ fmt.Sprint(ps.Assists) }</td>
|
|
} else {
|
|
<td class="px-2 py-2 text-center text-sm font-bold text-blue">{ fmt.Sprint(ps.Saves) }</td>
|
|
}
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
}
|