import { Badge, Center, Group, Stack, Text } from "@mantine/core";
import dayjs from "dayjs";
import { clientApi } from "@homarr/api/client";
import { useScopedI18n } from "@homarr/translation/client";
import type { DynamicSelectOption } from "../_inputs/widget-dynamic-select-input";
import type { WidgetComponentProps } from "../definition";
export default function TimetableWidget({ options }: WidgetComponentProps<"timetable">) {
const t = useScopedI18n("widget.timetable");
if (!options.station) {
return
{t("noStation")};
}
return ;
}
interface TimetableWidgetInnerProps {
station: DynamicSelectOption;
baseUrl: string;
}
const TimetableWidgetInner = ({ station, baseUrl }: TimetableWidgetInnerProps) => {
const { data: timetable } = clientApi.widget.timetable.getTimetable.useQuery({
baseUrl,
stationId: station.value,
limit: 10,
});
const t = useScopedI18n("widget.timetable");
return (
{t("title", { station: station.label })}
{(timetable?.entries ?? []).map((entry) => (
{entry.line && (
{entry.line.name}
)}
{dayjs(entry.timestamp).format("HH:mm")}{" "}
{entry.delay >= 1 && (
+{entry.delay}'
)}
{entry.location}
{entry.platform && (
{entry.platform.name}
)}
))}
);
};