{"size": 1251, "ext": "js", "max_stars_repo_path": "src/components/VideoTile/VideoTile.js", "max_stars_repo_name": "gorillalogic/nbc-test", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/VideoTile/VideoTile.js", "max_issues_repo_name": "gorillalogic/nbc-test", "max_issues_repo_issues_event_min_datetime": "2021-03-10T04:44:51.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T10:26:17.000Z", "max_forks_repo_path": "src/components/VideoTile/VideoTile.js", "max_forks_repo_name": "gorillalogic/nbc-test", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 35.7428571429, "max_line_length": 223, "alphanum_fraction": 0.6019184652}
import React from 'react';

const getBadge = (date, episodeNumber) => {
    const releaseDate = new Date(date);
    const today = new Date();
    //This should/could be in an util file.
    const differenceBetweenDates = Math.floor((Date.UTC(today.getFullYear(), today.getMonth(), today.getDate()) - Date.UTC(releaseDate.getFullYear(), releaseDate.getMonth(), releaseDate.getDate()) ) /(1000 * 60 * 60 * 24));
    const isNew = (Math.floor(differenceBetweenDates) < 7)

    if(episodeNumber === "1") {
        return "PREMIERE";
    } else if(isNew) {
        return "NEW";
    }

    return false;
}

const VideoTile = ({airDate, episodeNumber, image, secondaryTitle, title}) => {
    let badge = getBadge(airDate,episodeNumber);
    return (
        <section className="tile">
            <div className="tile__image">
                {badge && <span className="tile__badge">{ badge }</span>}
                <img loading="lazy" alt={title} src={process.env.PUBLIC_URL + image} />
            </div>
            <div className="tile__content">
                <span className="tile__title">{title}</span>
                <span className="tile__detail">{secondaryTitle}</span>
            </div>
        </section>
    )
}
 
export default VideoTile;