{"size": 1680, "ext": "js", "max_stars_repo_path": "js/views/Timer.js", "max_stars_repo_name": "perlexed/countries4", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "js/views/Timer.js", "max_issues_repo_name": "perlexed/countries4", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "js/views/Timer.js", "max_forks_repo_name": "perlexed/countries4", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.0, "max_line_length": 114, "alphanum_fraction": 0.5416666667}

import React from 'react';
import PropTypes from 'prop-types';

import Runner from "../components/Runner";
import TimeHelper from "../helpers/TimeHelper";

export default class Timer extends React.Component {

    static propTypes = {
        runnerStatus: PropTypes.string,
        runner: PropTypes.instanceOf(Runner),
        elapsedTime: PropTypes.number,
    };

    render() {
        if (this.props.runnerStatus === Runner.STATUS_IDLE) {
            return null;
        }

        if (this.props.runnerStatus === Runner.STATUS_FINISHED) {
            return (
                <div className='timer-block'>
                    <h4>Время вышло</h4>
                </div>
            );
        }

        const getEnumerableEnding = number => {
            const digit = number.toString()[number.toString().length - 1];

            if (digit === '1') {
                return 'а';
            }

            if (['0', '5', '6', '7', '8', '9'].indexOf(digit) !== -1) {
                return '';
            }

            return 'ы';
        };

        const timeObject = TimeHelper.getFormattedTime(this.props.runner.getTimeLimit() - this.props.elapsedTime);
        const minutesString = timeObject.minutes
            ? ' ' + timeObject.minutes + ' минут' + getEnumerableEnding(timeObject.minutes)
            : '';
        const secondsString = timeObject.seconds + ' секунд' + getEnumerableEnding(timeObject.seconds);

        return (
            <div className='timer'>
                <div className='timer__label'>Осталось времени:</div>
                <div className='timer__numbers'>{minutesString} {secondsString}</div>
            </div>
        );
    }
}