import { Box, Divider, Typography, Button, Menu, Fade, Radio, RadioGroup, FormControlLabel, FormControl, IconButton, } from "@mui/material"; import { useEffect, useState } from "react"; import React from "react"; import { useSearchParams } from "react-router-dom"; import { GOVERNANCE_ACTION_SORT_OPTIONS } from "../../consts/sort-options"; import { useTranslation } from "../../contexts/I18nContext"; import { theme } from "../../theme"; import { IconCheveronDown, IconCheveronUp, } from "@intersect.mbo/intersectmbo.org-icons-set"; export default function SortComponent() { const [isHovered, setIsHovered] = useState(false); const [anchorEl, setAnchorEl] = useState(null); const [sortParams, setSortParams] = useSearchParams(); const { t } = useTranslation(); const { palette: { badgeColors: { grey }, }, } = theme; useEffect(() => { const currentSort = sortParams.get("sort"); if (!currentSort) { const newParams = new URLSearchParams(sortParams); newParams.set("sort", "newestFirst"); setSortParams(newParams); } }, []); const handleShowOptions = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; const setSorts = (option: string) => { const newParams = new URLSearchParams(sortParams); if (option) { newParams.set("sort", option); } else { newParams.delete("sort"); } setSortParams(newParams); }; const sortValue = () => { return sortParams.get("sort")?.toString() || ""; }; const getDisplayLabel = (value: string) => { const option = GOVERNANCE_ACTION_SORT_OPTIONS.find( (opt) => opt.value === value ); return option?.displayLabel || value; }; const handleClose = () => { setAnchorEl(null); }; const open = Boolean(anchorEl); return ( {t("outcomesList.sort.fullTitle")} {GOVERNANCE_ACTION_SORT_OPTIONS.map((option, index) => ( setSorts(option.value)} > { e.stopPropagation(); setSorts(option.value); }} onClick={(e) => e.stopPropagation()} /> } label={option.label} onClick={(e) => e.stopPropagation()} /> ))} ); }