import { ReactNode } from "react";
import { TeamId } from "../../../../types/state";
import { Px } from "../../../../types/style";
import { getTeamFlagStyle } from "../../../../utils/dataLookup";
import { resolveCountryFlag, resolveTeamLogo } from "../../../../domain/data/assets";
import {
Container,
Slant,
Sheen,
FlagEdge,
CountryFlagDiv,
FlagContainer,
TeamFlagDiv,
} from "./styles";
const FLAG_WIDTH_TEAM = 2.4;
const FLAG_WIDTH_COUNTRY = 2;
/**
* To look right, country flags need to be 2:1. Additional editing will be
* necessary for some flags to not cut off prominent elements. Ex: China's flag
* would have its stars mostly cut out without edits to place them closer to the
* center.
*/
type AngledFlagProps = {
flagHeight: Px,
flagProps: {
flagMode: "country",
flag: string,
} | {
flagMode: "team",
flag: TeamId,
},
};
export function AngledFlag(props: AngledFlagProps) {
const { flagProps, flagHeight } = props;
let topFlag: ReactNode = null;
let bottomFlag: ReactNode = null;
if (flagProps.flagMode === "country") {
// The roster editor only offers bundled flags, but an imported roster can
// name anything - fall through to an empty flag instead of crashing.
const flagSrc = resolveCountryFlag(flagProps.flag);
if (flagSrc != null) {
topFlag = (
);
bottomFlag = (
);
}
} else if (flagProps.flagMode === "team") {
const logoSrc = resolveTeamLogo(flagProps.flag);
if (logoSrc != null) {
topFlag = (
);
bottomFlag = (
);
}
}
const flagModeWidth = flagProps.flagMode === "team" ? FLAG_WIDTH_TEAM : FLAG_WIDTH_COUNTRY;
return (
{topFlag}
{bottomFlag}
);
}