{"size": 2266, "ext": "js", "max_stars_repo_path": "src/deion/ui/components/PlayerNameLabels.js", "max_stars_repo_name": "mattthehearn/gm-games", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/deion/ui/components/PlayerNameLabels.js", "max_issues_repo_name": "mattthehearn/gm-games", "max_issues_repo_issues_event_min_datetime": "2018-02-21T01:05:58.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-21T02:24:31.000Z", "max_forks_repo_path": "src/deion/ui/components/PlayerNameLabels.js", "max_forks_repo_name": "mattthehearn/gm-games", "max_forks_repo_forks_event_min_datetime": "2019-03-20T03:04:29.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-20T03:04:29.000Z"}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 29.0512820513, "max_line_length": 118, "alphanum_fraction": 0.5450132392}
// @flow

import PropTypes from "prop-types";
import React from "react";
import RatingsStatsPopover from "./RatingsStatsPopover";
import SkillsBlock from "./SkillsBlock";
import { helpers } from "../util";
import type { PlayerInjury } from "../../common/types";

const PlayerNameLabels = ({
    children,
    injury,
    pid,
    pos,
    skills,
    style,
    watch,
}: {
    children: string,
    injury?: PlayerInjury,
    pos?: string,
    pid: number,
    skills?: string[],
    style?: { [key: string]: string },
    watch?: boolean,
}) => {
    let injuryIcon = null;
    if (injury !== undefined) {
        if (injury.gamesRemaining > 0) {
            const gameOrWeek =
                process.env.SPORT === "basketball" ? "game" : "week";

            const title = `${injury.type} (out ${injury.gamesRemaining} more ${
                injury.gamesRemaining === 1 ? gameOrWeek : `${gameOrWeek}s`
            })`;
            injuryIcon = (
                <span className="badge badge-danger badge-injury" title={title}>
                    {injury.gamesRemaining}
                </span>
            );
        } else if (injury.gamesRemaining === -1) {
            // This is used in box scores, where it would be confusing to display "out X more games" in old box scores
            injuryIcon = (
                <span
                    className="badge badge-danger badge-injury"
                    title={injury.type}
                >
                    &nbsp;
                </span>
            );
        }
    }

    return (
        <span style={style}>
            {typeof pos === "string" ? `${pos} ` : null}
            <a href={helpers.leagueUrl(["player", pid])}>{children}</a>
            {injuryIcon}
            <SkillsBlock skills={skills} />
            <RatingsStatsPopover pid={pid} watch={watch} />
        </span>
    );
};
PlayerNameLabels.propTypes = {
    children: PropTypes.any,
    injury: PropTypes.shape({
        gamesRemaining: PropTypes.number.isRequired,
        type: PropTypes.string.isRequired,
    }),
    pos: PropTypes.string,
    pid: PropTypes.number.isRequired,
    skills: PropTypes.arrayOf(PropTypes.string),
    style: PropTypes.object,
    watch: PropTypes.bool,
};

export default PlayerNameLabels;
