import Language from "@/components/bazarr/Language"; import SubtitleToolsMenu from "@/components/SubtitleToolsMenu"; import { SimpleTable } from "@/components/tables"; import { useCustomSelection } from "@/components/tables/plugins"; import { withModal } from "@/modules/modals"; import { isMovie } from "@/utilities"; import { Badge, Button, Divider, Group, Stack } from "@mantine/core"; import { FunctionComponent, useMemo, useState } from "react"; import { Column, useRowSelect } from "react-table"; type SupportType = Item.Episode | Item.Movie; type TableColumnType = FormType.ModifySubtitle & { raw_language: Language.Info; }; function getIdAndType(item: SupportType): [number, "episode" | "movie"] { if (isMovie(item)) { return [item.radarrId, "movie"]; } else { return [item.sonarrEpisodeId, "episode"]; } } const CanSelectSubtitle = (item: TableColumnType) => { return item.path.endsWith(".srt"); }; interface SubtitleToolViewProps { payload: SupportType[]; } const SubtitleToolView: FunctionComponent = ({ payload, }) => { const [selections, setSelections] = useState([]); const columns: Column[] = useMemo[]>( () => [ { Header: "Language", accessor: "raw_language", Cell: ({ value }) => ( ), }, { id: "file", Header: "File", accessor: "path", Cell: ({ value }) => { const path = value; let idx = path.lastIndexOf("/"); if (idx === -1) { idx = path.lastIndexOf("\\"); } if (idx !== -1) { return path.slice(idx + 1); } else { return path; } }, }, ], [] ); const data = useMemo( () => payload.flatMap((item) => { const [id, type] = getIdAndType(item); return item.subtitles.flatMap((v) => { if (v.path) { return [ { id, type, language: v.code2, path: v.path, raw_language: v, }, ]; } else { return []; } }); }), [payload] ); const plugins = [useRowSelect, useCustomSelection]; return ( ); }; export default withModal(SubtitleToolView, "subtitle-tools", { title: "Subtitle Tools", size: "xl", });