# Store Locator

## Objective

Help visitors find the nearest branch, with hours, directions, and a way to get in touch.

A searchable list of physical locations with distance, opening hours, contact details, and a map view.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Build the list first and the map second. The list of nearest locations with address, distance, hours, and phone number is the feature; the map is a way to scan it.
2. Offer to use the visitor's device location and always offer a text field for a postcode, town, or address alongside it. Never make the location prompt the only route in.
3. Store opening hours per location with the location's own time zone, including regular weekly hours and dated exceptions for holidays and one-off closures, and compute open or closed from those.
4. If the app already has Google Places Address Lookup, Mapbox Geocoding, or Address Autocomplete, use them to turn the typed query into coordinates. Do not add a second geocoding path for this one screen.
5. Do not require the map to render before results appear. Fetch and show the ranked list from the server, then enhance with the map, so a blocked or failed map script leaves a working page.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- Location permission is often denied or unavailable. Fall back immediately to the manual entry field with a plain explanation rather than leaving a spinner or a permission prompt the visitor already dismissed.
- A search can legitimately return nothing within the radius. Say that no location is within the distance searched, offer the nearest one beyond it, and never present an empty list as an error.
- Open or closed must be computed in the location's own time zone against its holiday exceptions, not the visitor's clock. A branch shown as open on a public holiday sends someone to a locked door.
- Filtering must apply to the map and the list together. Panning the map should update the list, and narrowing the list should update the pins, or the two views will disagree about what exists.
- Map tiles are heavy and are blocked on some networks and by some extensions. The page must remain fully usable with addresses, hours, and directions links when the map never loads.
- Directions should hand off to the visitor's own maps application with the destination pre-filled, rather than attempting turn-by-turn routing in the page.
- Each result needs a phone number that dials on mobile and an address that is selectable as text, because people copy addresses more often than they click through.
- Locations that are temporarily closed or not yet open need their own state, distinct from closed-for-the-evening.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] Results are ranked by distance from either a detected location or a typed query.
- [ ] Denied location permission leads straight to manual entry with no dead end.
- [ ] Open and closed status is correct for the location's time zone and its holiday exceptions.
- [ ] The map and the result list always show the same set of locations.
- [ ] The page lists locations, hours, and directions links with the map unavailable.
- [ ] An empty radius result explains itself and offers the nearest location beyond it.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
