import coreUtils from "@opentripplanner/core-utils";
import { Defaults } from "@opentripplanner/itinerary-body";
import {
GradationMap,
Leg,
LegIconComponent,
LegHeadingProp
} from "@opentripplanner/types";
import React, { ReactElement } from "react";
import { FormattedMessage } from "react-intl";
import AccessibilityAnnotation from "./accessibility-annotation";
import * as S from "./styled";
import { defaultMessages, strongText } from "./util";
const { getDisplayedStopCode, getLegRouteShortName } = coreUtils.itinerary;
interface Props extends LegHeadingProp {
accessibilityScoreGradationMap?: GradationMap;
interlineFollows?: boolean;
leg: Leg;
LegIcon: LegIconComponent;
}
export default function TransitLeg({
accessibilityScoreGradationMap,
leg,
LegIcon,
interlineFollows,
headingAs
}: Props): ReactElement {
// TODO: some mocks in itinerary-body have legs with null values for from/to.stop
const stopCodeFrom = getDisplayedStopCode(leg.from.stop ?? leg.from);
const stopCodeTo = getDisplayedStopCode(leg.to.stop ?? leg.to);
// TODO: core-utils needs some larger-scale type fixes
// null is an object, so we need to redefine it as undefined to prevent
// it from being read as an object. The long term solution is to avoid
// using type checks for this purpose
if (leg.route === null) leg.route = undefined;
const routeDescription = (
<>
{getLegRouteShortName(leg)}
>
);
const alightMessage = (
);
// Handle case of transit leg interlined w/ previous.
if (leg.interlineWithPreviousLeg) {
return (
{alightMessage}
);
}
return (
{routeDescription}
{interlineFollows ? (
) : (
alightMessage
)}
);
}