{"size": 2103, "ext": "js", "max_stars_repo_path": "homeworks/roman.vlasov_batteryfree/4-modules/app/app.js", "max_stars_repo_name": "LigthWarrior/frontend-course-2020", "max_stars_repo_stars_event_min_datetime": "2020-10-09T08:16:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-14T07:45:10.000Z", "max_issues_repo_path": "homeworks/roman.vlasov_batteryfree/4-modules/app/app.js", "max_issues_repo_name": "LigthWarrior/frontend-course-2020", "max_issues_repo_issues_event_min_datetime": "2020-10-20T19:29:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-19T08:21:07.000Z", "max_forks_repo_path": "homeworks/roman.vlasov_batteryfree/4-modules/app/app.js", "max_forks_repo_name": "LigthWarrior/frontend-course-2020", "max_forks_repo_forks_event_min_datetime": "2020-10-07T12:37:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T07:13:54.000Z"}
{"max_stars_count": 6, "max_issues_count": 131, "max_forks_count": 63, "avg_line_length": 36.2586206897, "max_line_length": 88, "alphanum_fraction": 0.6034236805}
import * as time from './time.js';

class App {
    constructor(el) {
        this.el = el;
        this.findElements();
        this.listenEvents();
    }

    findElements() {
        this.elements = {
            input: this.el.querySelector('[data-input]'),
            findFridays: this.el.querySelector('[data-get-fridays]'),
            monthLong: this.el.querySelector('[data-get-month-long]'),
            shortestWeek: this.el.querySelector('[data-get-shortest-week]'),
            fullWeeks: this.el.querySelector('[data-get-full-weeks]'),
            fridayText: this.el.querySelector('[data-fridays]'),
            monthLongText: this.el.querySelector('[ data-month-long]'),
            shortestWeekText: this.el.querySelector('[data-shortest-week]'),
            fullWeekText: this.el.querySelector('[data-full-week]'),
        };
    }

    listenEvents() {
        this.elements.fullWeeks.addEventListener('click', () => {
            const fullWeeks = time.fullWeeksNumberInMonth(this.elements.input.value);
            App.renderText(this.elements.fullWeekText, fullWeeks);
        });

        this.elements.shortestWeek.addEventListener('click', () => {
            const shortestWeek = time.shortestWeekDaysNumber(this.elements.input.value);
            App.renderText(this.elements.shortestWeekText, shortestWeek);
        });

        this.elements.monthLong.addEventListener('click', () => {
            const isMonthLong = time.isMonthLong(this.elements.input.value);
            App.renderText(this.elements.monthLongText, isMonthLong);
        });

        this.elements.findFridays.addEventListener('click', () => {
            const fridays = time.getFridaysOfMonth(this.elements.input.value);
            App.renderText(this.elements.fridayText, fridays);
        });
    }

    static renderText(element, data) {
        const el = element;
        if (data !== undefined) {
            el.innerHTML = data;
        } else {
            el.innerHTML = '';
        }
    }
}

// eslint-disable-next-line no-unused-vars
const app = new App(document.querySelector('#root'));
