// The search-box scope-pill (S2): one field-scope active at a time, narrowing the Plex full-text // search to a single facet of the row. Kept in one module so the provider (state), the header // SearchBar (the pill UI), and the api layer (the `field` query param) share one source of truth. export type PlexSearchField = "all" | "title" | "people" | "summary" | "episode"; const PLEX_SEARCH_FIELDS: PlexSearchField[] = ["all", "title", "people", "summary", "episode"]; // i18n label key per scope (see plex.searchField.* in the locale files). export const plexFieldLabelKey = (f: PlexSearchField): string => `plex.searchField.${f}`; // Episodes only exist under show libraries, so the Episode scope is offered only when shows are in // scope (show | both) — mirroring the backend, which returns nothing for episode+movie-only. export function availablePlexFields(scope: string): PlexSearchField[] { return scope === "movie" ? PLEX_SEARCH_FIELDS.filter((f) => f !== "episode") : PLEX_SEARCH_FIELDS; } // Heal a stored/selected field against the current scope: a movie-only scope can't hold Episode, so // it falls back to Everywhere (analogous to healPlexSort). Applied at the point of use. export function healPlexField(field: PlexSearchField, scope: string): PlexSearchField { return availablePlexFields(scope).includes(field) ? field : "all"; } export function parsePlexField(v: string | null | undefined): PlexSearchField { return v && (PLEX_SEARCH_FIELDS as string[]).includes(v) ? (v as PlexSearchField) : "all"; }