import React from 'react'; import Box from '@mui/material/Box'; import Menu from '@mui/material/Menu'; import MenuItem from '@mui/material/MenuItem'; import SwapVertIcon from '@mui/icons-material/SwapVert'; import type { SxProps, Theme } from '@mui/material/styles'; import { Button } from '../../atoms/Button'; // ─── Types ────────────────────────────────────────────────────────────────── /** A sort option shown in the menu */ export interface SortOption { /** Machine-readable value (e.g. 'price_low'). Passed back via `onChange`. */ value: string; /** Human-readable label (e.g. 'Price low to high'). Shown in the menu and, * in the `verbose` variant, on the trigger button. */ label: string; } /** Props for the FA SortMenu molecule */ export interface SortMenuProps { /** Current sort value (controlled). Must match one of the options' values. */ value: string; /** Fires when the user picks a different sort option. */ onChange: (value: string) => void; /** Sort options to surface in the menu, in display order. */ options: SortOption[]; /** Trigger label variant: * - `compact` (default): button reads just "Sort by"; current value * surfaces only in the menu's selected item and in the aria-label. * Best for narrow surfaces (mobile, chip-strip floating controls). * - `verbose`: button reads "Sort: " with a leading * swap-vertical icon. Best for desktop where horizontal space is * cheap and the current value is worth surfacing inline. */ variant?: 'compact' | 'verbose'; /** MUI sx prop — applied to the trigger Button. Callers pass chrome * (bgcolor, border, shadow, radius, height) here. */ sx?: SxProps; } // ─── Component ────────────────────────────────────────────────────────────── /** * Dropdown sort control — a trigger Button + anchored Menu. * * Tap the button → menu opens anchored to the button's bottom-right; pick * an option → menu closes and `onChange` fires with the new value. The * currently-selected option is visually marked in the menu (MUI's * `selected` state on MenuItem). * * **Accessibility:** trigger button has `aria-haspopup="listbox"` and an * `aria-label` that spells out the current sort ("Sort by Recommended"), * so screen-reader users get the state regardless of which label variant * is rendered. Selected MenuItem has `aria-selected="true"` via MUI. * * Originally extracted from ProvidersStep (which had the same Button + * Menu pattern inline in two places with a minor "Sort by" vs * "Sort: