# Detailed Restoration Plan for League Detail Pages

## Executive Summary
Restore `/leagues/:id` to full functionality per [`ALPHA_PLAN.md`](docs/ALPHA_PLAN.md:123):
- Logo display.
- Team members (roster).
- Races (schedule).
- SoF (avg Strength of Field).
- All tabs/subpages with data.

**Timeline**: Surgical fixes (data queries, templates, cleanup). Production-ready: Data from bootstrap adapters, no mocks.

## Current State (From Tools)
- Routes: Tabs via layout.tsx (Overview, Schedule, Standings, Rulebook + admin).
- page.tsx: [`LeagueDetailPageQuery`](apps/website/lib/page-queries/LeagueDetailPageQuery.ts:1) → LeagueService → partial DTO → hardcoded empty ViewData.
- Templates: Overview shows stats (0s), sidebar empty. Detail has breadcrumb/tabs.
- Subpages: schedule/standings exist (empty fallbacks), no roster/page.tsx.

## Target State
```
Data: Full relations from seeded adapters.
UI: Logo header, roster preview, races summary, SoF stat, populated tabs.
```

## Mermaid Flow
```mermaid
graph LR
  PQ[LeagueDetailPageQuery]
  LS[LeagueService.getLeagueDetailData<br/>FIX: +includes(relations)]
  VB[ViewDataBuilder<br/>FIX: real inputs, avgSOF]
  LT[LeagueDetailTemplate<br/>Tabs active]
  OV[OverviewTemplate<br/>Logo/stats/roster]
  SP[Sub Queries/Templates]
  
  Bootstrap[Adapters/Bootstrap Seed] -.-> LS
```

## Step-by-Step Execution (Todo)
1. **Data (1-3)**:
   - Read/extend LeagueService: Repo.findById({include: ['memberships', 'races', 'sponsors', 'logoUrl']}).
   - Bootstrap: Seed demo-league w/ logo/members/races.sof.
   - VB: Pass query data, compute SOF avg.

2. **UI (4-8)**:
   - Logo: Add to DTO/template header (img fallback icon).
   - Roster preview in overview (members.slice(0,5)).
   - Create roster/page.tsx (members table).
   - schedule/page.tsx: Races list (date/track/sof/status).
   - standings/page.tsx: Standings + per-race SOF.

3. **Tabs (9)**:
   - DetailTemplate: usePathname for active tab.

4. **Cleanup (10-11)**:
   - search_files unused exports.
   - Delete.

5. **Verify (12-13)**:
   - eslint/tsc/test.
   - Manual demo-league test.

## Files to Edit (Clickable)
[`LeagueService`](lib/services/leagues/LeagueService.ts)
[`LeagueDetailPageQuery`](lib/page-queries/LeagueDetailPageQuery.ts)
[`LeagueDetailViewDataBuilder`](lib/builders/view-data/LeagueDetailViewDataBuilder.ts)
[`LeagueOverviewTemplate`](templates/LeagueOverviewTemplate.tsx)
[`roster/page.tsx`](app/leagues/[id]/roster/page.tsx) (new)

## Success Criteria
- Demo league: Logo shows, members>0, races list, SOF>0, tabs data.
- No empties/hardcodes.
- Tests pass.

Review/approve before code.