import { tc } from "@/utils/textTools"; import type { MediaSourceInfo } from "@jellyfin/sdk/lib/generated-client/models"; import { useMemo } from "react"; import { Platform, TouchableOpacity, View } from "react-native"; const DropdownMenu = !Platform.isTV ? require("zeego/dropdown-menu") : null; import { useTranslation } from "react-i18next"; import { Text } from "./common/Text"; interface Props extends React.ComponentProps { source?: MediaSourceInfo; onChange: (value: number) => void; selected?: number | undefined; } export const SubtitleTrackSelector: React.FC = ({ source, onChange, selected, ...props }) => { if (Platform.isTV) return null; const subtitleStreams = useMemo(() => { return source?.MediaStreams?.filter((x) => x.Type === "Subtitle"); }, [source]); const selectedSubtitleSteam = useMemo( () => subtitleStreams?.find((x) => x.Index === selected), [subtitleStreams, selected], ); if (subtitleStreams?.length === 0) return null; const { t } = useTranslation(); return ( {t("item_card.subtitles")} {selectedSubtitleSteam ? tc(selectedSubtitleSteam?.DisplayTitle, 7) : t("item_card.none")} Subtitle tracks { onChange(-1); }} > None {subtitleStreams?.map((subtitle, idx: number) => ( { if (subtitle.Index !== undefined && subtitle.Index !== null) onChange(subtitle.Index); }} > {subtitle.DisplayTitle} ))} ); };