import { formatDistanceToNowStrict } from 'date-fns';
import styled from '@emotion/styled';
import {
Backup,
CheckBox,
HourglassTop,
NotificationsActive,
Tv,
} from '@mui/icons-material';
import { Box, Stack, Tooltip, Typography } from '@mui/material';
import { useState } from 'react';
import { NameWithHighlight, State, Station, Stream } from '../common/types';
import { calledColor, highlightColor, startedColor } from '../common/constants';
const EntrantNames = styled(Stack)`
width: calc(100% - 22px);
`;
const EntrantSection = styled(Stack)`
align-items: center;
box-sizing: border-box;
width: 50%;
`;
const EntrantScore = styled(Box)`
overflow-x: hidden;
margin: 0 4px;
text-overflow: ellipsis;
width: 14px;
`;
const Name = styled.div`
overflow-x: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`;
function EntrantName({ entrantName }: { entrantName: NameWithHighlight }) {
if (!entrantName.highlight) {
return {entrantName.name};
}
return (
{entrantName.name.substring(0, entrantName.highlight.start)}
{entrantName.name.substring(
entrantName.highlight.start,
entrantName.highlight.end,
)}
{entrantName.name.substring(entrantName.highlight.end)}
);
}
function CallTimer({
updatedAtMs,
matchState,
}: {
updatedAtMs: number;
matchState: number;
}) {
const [timeAgo, setTimeAgo] = useState(
formatDistanceToNowStrict(updatedAtMs, { addSuffix: true }),
);
const handleOpen = () => {
setTimeAgo(formatDistanceToNowStrict(updatedAtMs, { addSuffix: true }));
};
if (matchState === State.STARTED) {
return (
);
}
if (matchState === State.CALLED) {
return (
);
}
return null;
}
export default function SetView({
entrant1Names,
entrant1Score,
entrant1Win,
entrant2Names,
entrant2Score,
fullRoundText,
showScores,
state,
stream,
station,
wasReported,
updatedAtMs,
}: {
entrant1Names: NameWithHighlight[];
entrant1Score: number | null;
entrant1Win: boolean;
entrant2Names: NameWithHighlight[];
entrant2Score: number | null;
fullRoundText: string;
showScores: boolean;
state: number;
stream: Stream | null;
station: Station | null;
wasReported: boolean;
updatedAtMs: number;
}) {
let leftScore = '\u00A0';
let rightScore = '\u00A0';
if (showScores) {
if (entrant1Score || entrant2Score) {
leftScore = entrant1Score ? entrant1Score.toString(10) : '0';
rightScore = entrant2Score ? entrant2Score.toString(10) : '0';
} else if (entrant1Win) {
leftScore = 'W';
rightScore = 'L';
} else {
leftScore = 'L';
rightScore = 'W';
}
}
let streamVerb = 'Queued';
if (state === State.STARTED) {
streamVerb = 'Streaming';
} else if (state === State.COMPLETED) {
streamVerb = 'Streamed';
}
let stationVerb = 'Queued';
if (state === State.STARTED) {
stationVerb = 'Playing';
} else if (state === State.COMPLETED) {
stationVerb = 'Played';
}
return (
{wasReported && (
)}
{!wasReported && stream && (
)}
{!wasReported && !stream && station && (
{station.number}
)}
{fullRoundText}
{leftScore}
{entrant1Names.length > 1 && (
)}
{rightScore}
{entrant2Names.length > 1 && (
)}
{(state === State.CALLED || state === State.STARTED) && (
)}
{state === State.COMPLETED && (
)}
);
}