package seasonsview import "git.haelnorr.com/h/oslstats/internal/db" import "git.haelnorr.com/h/oslstats/internal/view/baseview" import "time" import "strconv" import "git.haelnorr.com/h/oslstats/internal/permissions" import "git.haelnorr.com/h/oslstats/internal/contexts" templ DetailPage(season *db.Season) { @baseview.Layout(season.Name) {
@SeasonDetails(season)
} } templ SeasonDetails(season *db.Season) { {{ permCache := contexts.Permissions(ctx) canEditSeason := permCache.HasPermission(permissions.SeasonsUpdate) }}

{ season.Name }

{ season.ShortName } @SlapVersionBadge(season.SlapVersion) @StatusBadge(season, false, false)
if canEditSeason { Edit } Back to Seasons

Regular Season

Start Date: { formatDateLong(season.StartDate) }
End Date: if !season.EndDate.IsZero() { { formatDateLong(season.EndDate.Time) } } else { Not set }
Duration: if !season.EndDate.IsZero() { { formatDuration(season.StartDate, season.EndDate.Time) } } else { Ongoing }

Finals

Start Date: if !season.FinalsStartDate.IsZero() { { formatDateLong(season.FinalsStartDate.Time) } } else { Not set }
End Date: if !season.FinalsEndDate.IsZero() { { formatDateLong(season.FinalsEndDate.Time) } } else { Not set }
Duration: if !season.FinalsStartDate.IsZero() && !season.FinalsEndDate.IsZero() { { formatDuration(season.FinalsStartDate.Time, season.FinalsEndDate.Time) } } else { Not scheduled }

Leagues

if len(season.Leagues) == 0 {

No leagues assigned to this season.

} else {
for _, league := range season.Leagues {

{ league.Name }

{ league.ShortName }
}
}
} func formatDateLong(t time.Time) string { return t.Format("January 2, 2006") } func formatDuration(start, end time.Time) string { days := int(end.Sub(start).Hours()/24) + 1 if days == 1 { return "1 day" } else if days < 7 { return strconv.Itoa(days) + " days" } else if days < 30 { weeks := days / 7 if weeks == 1 { return "1 week" } return strconv.Itoa(weeks) + " weeks" } else if days < 365 { months := days / 30 if months == 1 { return "1 month" } return strconv.Itoa(months) + " months" } else { years := days / 365 if years == 1 { return "1 year" } return strconv.Itoa(years) + " years" } } templ SlapVersionBadge(version string) { if version == "rebound" { Rebound } else if version == "slapshot1" { Slapshot 1 } }