"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get getInRange () {
        return getInRange;
    },
    get getSideForHovered () {
        return getSideForHovered;
    },
    get getSideForSelected () {
        return getSideForSelected;
    },
    get getSideInRange () {
        return getSideInRange;
    },
    get getSortedValues () {
        return getSortedValues;
    },
    get isDateInRange () {
        return isDateInRange;
    },
    get isSameDay () {
        return isSameDay;
    },
    get isSelectProcess () {
        return isSelectProcess;
    },
    get isValueUpdate () {
        return isValueUpdate;
    }
});
const getSortedValues = (values)=>values.sort((start, end)=>{
        if (!start || !end) {
            return -1;
        }
        return start.getTime() - end.getTime();
    });
const isDateInRange = (year, monthIndex, currentDay, values)=>{
    const [startValue, endValue] = getSortedValues(values);
    if (!endValue || !startValue) {
        return false;
    }
    const day = new Date(year, monthIndex, currentDay);
    return startValue < day && day <= endValue;
};
const isSameDay = (firstDate, secondDate)=>secondDate && firstDate.day === secondDate.day && firstDate.monthIndex === secondDate.monthIndex && firstDate.year === secondDate.year;
const isValueUpdate = (value, prevValue)=>{
    if (!Array.isArray(value) && !Array.isArray(prevValue)) {
        return prevValue?.getTime() !== value?.getTime();
    }
    if (Array.isArray(value) && Array.isArray(prevValue)) {
        return prevValue[0]?.getTime() !== value[0]?.getTime() || prevValue[1]?.getTime() !== value[1]?.getTime();
    }
    return false;
};
const isSelectProcess = (array)=>Array.isArray(array) && !array[1];
const getSideForSelected = (date, startValue, endValue)=>{
    const currentDateTime = new Date(date.year, date.monthIndex, date.day).getTime();
    const startValueTime = startValue.getTime();
    const endValueTime = endValue.getTime();
    if (currentDateTime === startValueTime) {
        return 'right';
    }
    if (currentDateTime === endValueTime) {
        return 'left';
    }
    return undefined;
};
const getSideForHovered = (date, hoveredDay, startValue, isSelected)=>{
    const dateHover = new Date(hoveredDay.year, hoveredDay.monthIndex, hoveredDay.day);
    const isHovered = isSameDay(date, hoveredDay);
    if (isSelected && startValue > dateHover || isHovered && startValue < dateHover) {
        return 'left';
    }
    if (isSelected && startValue < dateHover || isHovered && startValue > dateHover) {
        return 'right';
    }
    return undefined;
};
const getSideInRange = (value, date, hoveredDay, isSelected)=>{
    if (!Array.isArray(value)) {
        return undefined;
    }
    const [startValue, endValue] = value;
    if (startValue && isSelected && endValue) {
        return getSideForSelected(date, startValue, endValue);
    }
    if (startValue && hoveredDay) {
        return getSideForHovered(date, hoveredDay, startValue, isSelected);
    }
    return undefined;
};
const getInRange = (value, date, hoveredDay, inRange)=>{
    if (!isSelectProcess(value) || !hoveredDay) {
        return inRange;
    }
    const dateSelected = value[0];
    const dateHover = new Date(hoveredDay.year, hoveredDay.monthIndex, hoveredDay.day);
    const dateCurrent = new Date(date.year, date.monthIndex, date.day);
    if (dateSelected < dateCurrent && dateCurrent < dateHover || dateSelected > dateCurrent && dateCurrent > dateHover) {
        return true;
    }
    return inRange;
};
