'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var dateUtils = require('../../dateUtils.js');

function getPrevMonth(month) {
    return month === 0 ? 11 : month - 1;
}
function getNextMonth(month) {
    return month === 11 ? 0 : month + 1;
}
function getPrevYear(month, year) {
    return month === 0 ? year - 1 : year;
}
function getNextYear(month, year) {
    return month === 11 ? year + 1 : year;
}
function getSliceNum(startColumn, startingDay) {
    if (startingDay === 'sunday') {
        return startColumn;
    }
    else if (startColumn === 0) {
        return 6;
    }
    return startColumn - 1;
}
function getPrevDays(month, year, startColumn, startingDay) {
    const prevMonth = getPrevMonth(month);
    const prevYear = getPrevYear(month, year);
    const sliceNum = getSliceNum(startColumn, startingDay);
    return sliceNum !== 0 ? dateUtils.getDays(prevMonth, prevYear).slice(-sliceNum) : [];
}
function getNextDays(month, year, temp) {
    const nextMonth = getNextMonth(month);
    const nextYear = getNextYear(month, year);
    return dateUtils.getDays(nextMonth, nextYear).slice(0, temp !== 7 ? temp : 0);
}
function getAllDays(startColumn, month, year, startingDay) {
    const days = dateUtils.getDays(month, year);
    const prevDays = getPrevDays(month, year, startColumn, startingDay);
    const numNextDays = 7 - ((prevDays.length + days.length) % 7);
    const nextDays = getNextDays(month, year, numNextDays);
    if (startingDay === 'monday') {
        return [...prevDays, ...days, ...nextDays];
    }
    else if (startColumn > 0) {
        return [...prevDays, ...days, ...nextDays];
    }
    else {
        return [...days, ...nextDays];
    }
}
function getStartColumn(startingDay, startDay, selection) {
    if (selection === 'single-date' || startingDay === 'none') {
        return 0;
    }
    switch (startingDay) {
        case 'monday':
            return startDay === 0 ? 7 : startDay;
        case 'sunday':
        default:
            return startDay > 0 ? startDay + 1 : startDay;
    }
}
function isDisabled(day, minDate, maxDate) {
    if (minDate) {
        if (day < minDate) {
            return true;
        }
    }
    if (maxDate) {
        if (day > maxDate)
            return true;
    }
    return false;
}
function hasEndRange(day, selectedRange) {
    if (selectedRange) {
        if (selectedRange.end) {
            return dateUtils.getIsSameDay(day, selectedRange.end);
        }
    }
    return false;
}
function getDayWidth(calendarRef) {
    if (calendarRef && calendarRef.current) {
        const calendarWidth = calendarRef.current.getBoundingClientRect().width - 32;
        if (calendarWidth / 7 < 40) {
            return calendarWidth / 7;
        }
    }
    return 40;
}
function getGridPosition(index, gridRef) {
    if (gridRef.current) {
        const offset = window.getComputedStyle(gridRef.current).gridColumnStart.split(' ')
            .length - 1 || 0;
        const colCount = 7;
        const rowPosition = Math.floor((index + offset) / colCount);
        const colPosition = (index + offset) % colCount;
        return { row: rowPosition, col: colPosition };
    }
}
function getIndexFromGridPosition(gridPosition) {
    return gridPosition.row * 7 + gridPosition.col;
}

exports.getAllDays = getAllDays;
exports.getDayWidth = getDayWidth;
exports.getGridPosition = getGridPosition;
exports.getIndexFromGridPosition = getIndexFromGridPosition;
exports.getNextDays = getNextDays;
exports.getNextMonth = getNextMonth;
exports.getNextYear = getNextYear;
exports.getPrevDays = getPrevDays;
exports.getPrevMonth = getPrevMonth;
exports.getPrevYear = getPrevYear;
exports.getSliceNum = getSliceNum;
exports.getStartColumn = getStartColumn;
exports.hasEndRange = hasEndRange;
exports.isDisabled = isDisabled;
