# Golf Ops Score Entry

Mobile-first score entry app for multi-league golf operations.

## App Index

Local routes:
- `http://localhost:8080/` - Landing page (placeholder hub)
- `http://localhost:8080/score/` - Score Entry app
- `http://localhost:8080/admin` - League Config engine
- `http://localhost:8080/dashboard` - League Dashboard demo

Deployed routes on `golfops.app`:
- `/` - Landing page (main branch hub)
- `/score/` - Score Entry
- `/admin` - League Config
- `/dashboard` - League Dashboard

## What this version includes

- `Golf Ops` branded UI with optional logo slot.
- League / season / week / match selectors (Supabase-backed).
- Event-capable competition foundation in admin/backend schema.
- Setup screen for confirming matchup and swapping subs.
- Three score-entry views:
  - Entry: By Hole
  - Entry: By Player
  - View: Net Pops
- Live scoring styles (birdie/bogey/par visual treatment).
- Full-screen review modal with gross/net/bonus/total summaries.
- Submit to Supabase `score_submissions` + mark `matches.status = submitted`.
- Demo fallback if Supabase is unavailable.

## Files

- `index.html` - landing page (main deployment hub)
- `score/index.html` - redirect wrapper for score entry
- `apps/scoring/index.html` - score entry app shell
- `apps/scoring/app.js` - score entry logic
- `supabase/schema.sql` - score-entry baseline schema + lock functions
- `supabase/schema_golfops.sql` - additive GolfOps dashboard/config relational schema
- `supabase/schema_unified_sync.sql` - bridge layer syncing admin-config + golfops to score-entry tables
- `supabase/schema_platform_extensions.sql` - auth/session/import/qr/ops extension schema
- `docs/event_foundation_2026-04-13.md` - event category foundation and next-step workflow
- `supabase/seed_test_12_team_11_week.sql` - score-entry test league seed
- `supabase/seed_golfops_premiere_demo.sql` - PGA/LIV-themed GolfOps demo seed
- `supabase/seed_unified_sync.sql` - publishes GolfOps week into score-entry `matches`
- `supabase/contracts/finalize_week_contract.md` - finalize-week backend contract
- `supabase/contracts/provisional_hc_contract.md` - provisional handicap backend contract

## Configuration

In `apps/scoring/index.html`, update:

```html
window.GOLF_OPS_CONFIG = {
  branding: {
    name: "Golf Ops",
    logoUrl: ""
  },
  supabaseUrl: "https://YOUR_PROJECT.supabase.co",
  supabaseAnonKey: "YOUR_ANON_KEY",
  scoring: {
    defaults: {
      holeWinPoints: 1,
      holeTiePoints: 0.5,
      bonusLowNet: 1,
      bonusMatchWin: 0,
      playCourseHandicapPercent: 80
    },
    leagues: {
      TEST12: {
        holeWinPoints: 1,
        holeTiePoints: 0.5,
        bonusLowNet: 1,
        bonusMatchWin: 0,
        playCourseHandicapPercent: 80
      }
    }
  }
};
```

- Set `branding.logoUrl` to your logo path or URL when ready.
- If Supabase keys are blank/invalid, app uses demo data.
- `scoring.leagues` supports league `id`, `code`, or `name` keys.
- `play_course_handicap_percent` in `public.leagues` is used first when present (falls back to config).

## Fresh Supabase Project Setup

Run in this order:

1. `supabase/schema.sql`
2. `supabase/schema_golfops.sql`
3. `supabase/schema_unified_sync.sql`
4. `supabase/schema_platform_extensions.sql`
5. `supabase/seed_golfops_premiere_demo.sql`
6. `supabase/seed_unified_sync.sql`
7. Optional: `supabase/seed_test_12_team_11_week.sql`

This gives you:
- Score Entry working against `public.leagues`, `public.matches`, `public.score_submissions`.
- Admin Config-ready ingest function: `public.golfops_create_league_from_config(config, manual_roster)`.
- Dashboard-ready relational model under `public.golfops_*`.
- Cross-app bridge function: `public.golfops_publish_week_to_score_entry(golfops_league_id, week_number)`.

## Current Backend Sync Scope

Fully covered now:
- Score Entry DB reads/writes (`leagues`, `matches`, `score_submissions`).
- Dashboard foundational relational model (`golfops_*` + read views).
- Admin Config payload persistence path via SQL function (`golfops_create_league_from_config`).
- Event category schema + signup snapshot foundation.
- Week publish bridge from Dashboard data to Score Entry match rows.

Still pending backend implementation:
- Edge Function runtime logic for finalize-week payout math and locking (contracts are documented).
- Live dashboard wiring from JS mock state to Supabase queries.
- Auth/RLS tightening for production roles.

## Local preview

```bash
python3 -m http.server 8080
```

Open:
- `http://localhost:8080/`
- `http://localhost:8080/score/`
- `http://localhost:8080/admin`
- `http://localhost:8080/dashboard`

## App Structure

- `index.html`: landing page placeholder hub.
- `score/index.html`: score-entry route wrapper.
- `apps/scoring/`: score entry app.
- `apps/admin-config/`: league configuration admin app.
- `apps/league-dashboard/`: league dashboard app.
- `shared/league-schema.js`: shared enums/defaults/schema keys for cross-app use.
- `docs/source-of-truth/`: dashboard source verification docs and audit outputs.

## Dashboard Source Audit

Run:

```bash
./scripts/audit-league-dashboard.sh
```

Outputs:
- `docs/source-of-truth/league_dashboard_change_log.md`

## Deployment (V1)

- `vercel.json` includes static hosting defaults and rewrites for `/admin` and `/dashboard`.
- Follow [`DEPLOY_V1.md`](./DEPLOY_V1.md) for preflight and launch steps.
- This app is static (no build step required).

### Important

- Supabase anon key is safe for client use, but keep RLS policies strict.
- Before production, remove or disable test seed data.
