# Task: Add League Round Check-in Tracking UI

## Page: `/tee-time/manage/leagues`

This page displays a table of league registrations. The data comes from:

**GET:** `process.php?getAdminData&type=leagues&userName={userName}&userId={userId}&date={year}`

Each row in the `members` array now has a new field **`rounds_used`** (integer) alongside the existing `rounds` (string, total purchased). Example row:

```json
{
  "league_id": "55",
  "league": "Tuesdays Ladies Leagues 8AM",
  "rounds": "10",
  "rounds_used": 3,
  "first_name": "vicki",
  "last_name": "hopkins",
  "email": "vickihopkins@hotmail.ca"
}
```

---

---

## API: Update League Registration (edit member details)

**POST** to `process.php`:

```json
{
  "updateLeagueRegistration": true,
  "leagueBookingId": 55,
  "fields": {
    "first_name": "Vicki",
    "last_name": "Hopkins",
    "email": "vickihopkins@hotmail.ca",
    "phone": "4165771044",
    "address": "2 Marion Drive",
    "city": "Uxbridge",
    "postalcode": "L9P1L1"
  },
  "userName": "admin",
  "userId": "da55abc9e736fd2ed7a65be15002629b"
}
```

Only these 7 fields are editable: `first_name`, `last_name`, `email`, `phone`, `address`, `city`, `postalcode`.

**Success:** `{ "success": true }`
**Error:** `{ "success": false, "error": "Registration not found" }`

---

## What to change in the UI

### 1. Rounds column — show used/total

Currently shows just `rounds` (e.g. `10`). Change to show:

**`{rounds_used} / {rounds}`** (e.g. `3 / 10`)

- When `rounds_used == rounds` → green text or green checkmark (all rounds used up)
- When `rounds_used == 0` → normal text `0 / 10`

---

### 2. Add "Check In" button per row

Small button (mat-icon-button with `add_circle` icon, or text "Check In") next to the rounds display or in a new column.

**Disable** when `rounds_used >= rounds`.

**On click → POST** to `process.php`:

```json
{
  "checkInLeagueRound": true,
  "leagueBookingId": 55,
  "userName": "admin",
  "userId": "da55abc9e736fd2ed7a65be15002629b",
  "notes": ""
}
```

- `leagueBookingId` = the `league_id` from the row
- `userName` and `userId` = same admin session values used for all other API calls on this page

**Success response:**

```json
{
  "success": true,
  "round_number": 4,
  "rounds_used": 4,
  "rounds_total": 10,
  "checked_in_at": "Apr 9, 2026 02:30 pm"
}
```

→ Update the row's `rounds_used` locally to the returned value. Show a success toast.
→ The backend also automatically sends an email to the golfer with their round check-in confirmation (round #, progress bar, remaining rounds). No UI work needed for that.

**Error response (all used):**

```json
{
  "success": false,
  "error": "All rounds have been used (10/10)"
}
```

→ Show error toast with the message.

---

### 3. Add "View History" button per row

Small icon button (`history` or `list` mat-icon). Opens a **modal/dialog**.

**On open → GET:**

```
process.php?getLeagueRoundCheckins&leagueBookingId=55&userName=admin&userId=da55abc9e736fd2ed7a65be15002629b
```

**Response:**

```json
{
  "success": true,
  "checkins": [
    { "round": 1, "date": 1744200600, "by": "admin", "notes": "" },
    { "round": 2, "date": 1744805400, "by": "admin", "notes": "rainy day" }
  ],
  "rounds_used": 2,
  "rounds_total": 10
}
```

**`date` is a Unix timestamp in seconds.** Convert in Angular: `new Date(checkin.date * 1000)` then format as `MMM d, yyyy h:mm a`.

**Modal title:** `Check-in History - {first_name} {last_name} ({rounds_used}/{rounds_total} rounds)`

**Display as a table:**

| Round # | Date | Checked in by | Notes | Action |
|---------|------|---------------|-------|--------|
| 1 | Apr 2, 2026 10:30 AM | admin | | [Undo] |
| 2 | Apr 9, 2026 2:30 PM | admin | rainy day | [Undo] |

If `checkins` is empty, show "No check-ins yet".

---

### 4. Undo button in the history modal

Each row has an "Undo" button. On click, confirm ("Are you sure you want to undo round #X?"), then:

**POST** to `process.php`:

```json
{
  "undoLeagueRoundCheckin": true,
  "leagueBookingId": 55,
  "roundIndex": 0,
  "userName": "admin",
  "userId": "da55abc9e736fd2ed7a65be15002629b"
}
```

- **`roundIndex`** = the **0-based array index** of the check-in (first = 0, second = 1, etc.)

**Success response:**

```json
{ "success": true, "rounds_used": 1 }
```

→ Re-fetch the check-in list to refresh the modal. Update the parent table row's `rounds_used`.

**Error response:**

```json
{ "success": false, "error": "Check-in not found" }
```

---

## Key mapping

| UI field | API param |
|----------|-----------|
| `league_id` from members array | `leagueBookingId` in all 3 API calls |
| Admin session username | `userName` |
| Admin session user ID | `userId` |
| API base URL | Same `process.php` used for everything else on this manage page |
