# Feature Specification: Pagination Controls Redesign

**Feature Branch**: `018-pagination-controls`
**Created**: 2026-05-10
**Status**: Draft

## User Scenarios & Testing *(mandatory)*

### User Story 1 - Navigate by Page Number (Priority: P1)

A user browsing the image library wants to jump directly to a specific page by clicking a numbered button rather than stepping through pages one at a time.

**Why this priority**: Direct page navigation is the core value of this feature — without numbered buttons the redesign delivers nothing new.

**Independent Test**: Load the library with enough images to produce multiple pages, confirm four numbered page buttons are visible, click one, and verify the correct page of images loads.

**Acceptance Scenarios**:

1. **Given** the library has more than one page of images, **When** the user views the pagination bar, **Then** up to four page number buttons are visible.
2. **Given** four page buttons are shown, **When** the user clicks a page number button, **Then** the library displays the images for that page and the clicked button appears in an active/selected state.
3. **Given** the total number of pages is four or fewer, **When** the user views the pagination bar, **Then** all pages are shown as numbered buttons with none hidden.

---

### User Story 2 - Step Forward and Backward (Priority: P2)

A user wants to move one page at a time using previous and next controls without having to locate a specific page number.

**Why this priority**: Sequential navigation is a common browsing pattern and complements numbered buttons.

**Independent Test**: With multiple pages available, click the next chevron (›) and confirm the library advances one page; click the previous chevron (‹) and confirm it retreats one page.

**Acceptance Scenarios**:

1. **Given** the user is not on the last page, **When** they click the next chevron (›), **Then** the library advances by one page.
2. **Given** the user is not on the first page, **When** they click the previous chevron (‹), **Then** the library retreats by one page.
3. **Given** the user is on the first page, **When** they view the pagination bar, **Then** the previous chevron (‹) is visually disabled and non-interactive.
4. **Given** the user is on the last page, **When** they view the pagination bar, **Then** the next chevron (›) is visually disabled and non-interactive.

---

### User Story 3 - Jump to First and Last Page (Priority: P3)

A user wants to jump directly to the first or last page of the library without stepping through intermediate pages.

**Why this priority**: First/last navigation is a convenience for large libraries; useful but not essential.

**Independent Test**: Navigate to any middle page, click the last-page double chevron (»), and confirm the final page loads; click the first-page double chevron («) and confirm page one loads.

**Acceptance Scenarios**:

1. **Given** the user is not on the first page, **When** they click the first-page double chevron («), **Then** the library jumps to page one.
2. **Given** the user is not on the last page, **When** they click the last-page double chevron (»), **Then** the library jumps to the final page.
3. **Given** the user is on the first page, **When** they view the pagination bar, **Then** the first-page double chevron («) is visually disabled and non-interactive.
4. **Given** the user is on the last page, **When** they view the pagination bar, **Then** the last-page double chevron (») is visually disabled and non-interactive.

---

### Edge Cases

- What happens when there is only one page of images? The entire pagination bar is hidden.
- What happens when the current page is in the middle of a large range (e.g. page 7 of 20)? The four visible page buttons centre around the current page where possible.
- What happens when the current page is near the start or end of the total range? The window of four buttons anchors to the start or end rather than going out of range.

## Requirements *(mandatory)*

### Functional Requirements

- **FR-001**: The pagination bar MUST display up to four numbered page buttons at a time.
- **FR-002**: The currently active page button MUST be visually distinguished from inactive page buttons.
- **FR-003**: The pagination bar MUST include a previous-page button (‹) and a next-page button (›).
- **FR-004**: The pagination bar MUST include a first-page button («) and a last-page button (»).
- **FR-005**: The previous (‹) and first-page («) controls MUST be disabled when the user is on page one.
- **FR-006**: The next (›) and last-page (») controls MUST be disabled when the user is on the final page.
- **FR-007**: The visible window of four page buttons MUST shift to keep the current page always in view.
- **FR-008**: The pagination bar MUST be hidden when the total number of pages is one or fewer.

## Success Criteria *(mandatory)*

### Measurable Outcomes

- **SC-001**: All six controls («, ‹, up to four page numbers, ›, ») are visible and correctly labelled on any page with more than four total pages.
- **SC-002**: Disabled controls are visually distinct and cannot be activated by the user.
- **SC-003**: The active page button always reflects the currently displayed page without requiring a page reload.
- **SC-004**: Navigating between pages does not introduce any additional loading delay beyond what the existing image fetch already takes.

## Assumptions

- The existing library already supports offset-based pagination; this feature changes only the navigation controls, not the underlying data fetching.
- The pagination bar is hidden when there is only one page, consistent with common library UX conventions.
- The four-button window shifts so the current page is always visible; no ellipsis or overflow indicator is required.
- Mobile layout is in scope; all controls must remain usable on small screens.
