'use client' import { useCampaignListFilterNavigation } from '@/components/campaign/shared/useCampaignListFilterNavigation' import { ACERVO_SORT_OPTIONS, ACERVO_THEME_SORT_OPTIONS, acervoSortIsDuration, type AcervoThemeSortKey, } from '@/lib/acervoListSort' import { cn } from '@/lib/utils' import { buildRecordingListHref, type RecordingListState, } from '@/utilities/recordings/recordingListUrl' import { buildSpeechListHref, type SpeechListState } from '@/utilities/speech/speechListUrl' /** * C216 — the shared acervo ordering control (design scene 01): "Mais recentes" * (the default, never serialized) plus the two duration orders. The list state * of one source carries the `source` discriminator that picks the canonical * serializer here: a server component can never hand a function prop across * the boundary, so the client-safe domain contracts are imported inside this * component and the page passes only the serializable state and the honest * line shown while a duration order is active (it lists measured rows only). * * C229 — the web theme mode opens with "Mais relevantes" (the semantic default, * never serialized) and keeps "Mais recentes" as a real, serializable state; * recordings (and the exact mode) keep the C216 vocabulary untouched. */ type AcervoSortState = RecordingListState | SpeechListState export const AcervoSortSelect = ({ state, hint, themeUnavailable = false, }: { state: AcervoSortState hint: string /** C229 — the engine is down: the list is literal, so show the exact-mode order. */ themeUnavailable?: boolean }) => { const { navigate, isPending } = useCampaignListFilterNavigation({ state, toHref: (next) => next.source === 'enviadas' ? buildRecordingListHref(next, 1) : buildSpeechListHref(next, 1), }) const isWebTheme = state.source === 'internet' && state.mode === 'tema' const isSpeechTheme = isWebTheme && !themeUnavailable const options = isSpeechTheme ? ACERVO_THEME_SORT_OPTIONS : ACERVO_SORT_OPTIONS const selected: AcervoThemeSortKey = state.sort ?? (isSpeechTheme ? 'relevancia' : 'recentes') const change = (value: AcervoThemeSortKey) => { // Relevance means "no sort" in the theme mode; "recentes" does so in every // other path (each mode's never-serialized default). if (value === 'relevancia' || (value === 'recentes' && !isSpeechTheme)) { navigate({ ...state, page: 1, sort: undefined }) return } navigate({ ...state, page: 1, sort: value }) } return (
{acervoSortIsDuration(state.sort) ? (

{hint}

) : null}
) }