"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;
    }
});
function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
function _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
var getSortedValues = function getSortedValues(values) {
    return values.sort(function(start, end) {
        if (!start || !end) {
            return -1;
        }
        return start.getTime() - end.getTime();
    });
};
var isDateInRange = function isDateInRange(year, monthIndex, currentDay, values) {
    var _getSortedValues = _sliced_to_array(getSortedValues(values), 2), startValue = _getSortedValues[0], endValue = _getSortedValues[1];
    if (!endValue || !startValue) {
        return false;
    }
    var day = new Date(year, monthIndex, currentDay);
    return startValue < day && day <= endValue;
};
var isSameDay = function isSameDay(firstDate, secondDate) {
    return secondDate && firstDate.day === secondDate.day && firstDate.monthIndex === secondDate.monthIndex && firstDate.year === secondDate.year;
};
var isValueUpdate = function isValueUpdate(value, prevValue) {
    if (!Array.isArray(value) && !Array.isArray(prevValue)) {
        return (prevValue === null || prevValue === void 0 ? void 0 : prevValue.getTime()) !== (value === null || value === void 0 ? void 0 : value.getTime());
    }
    if (Array.isArray(value) && Array.isArray(prevValue)) {
        var _prevValue_, _value_, _prevValue_1, _value_1;
        return ((_prevValue_ = prevValue[0]) === null || _prevValue_ === void 0 ? void 0 : _prevValue_.getTime()) !== ((_value_ = value[0]) === null || _value_ === void 0 ? void 0 : _value_.getTime()) || ((_prevValue_1 = prevValue[1]) === null || _prevValue_1 === void 0 ? void 0 : _prevValue_1.getTime()) !== ((_value_1 = value[1]) === null || _value_1 === void 0 ? void 0 : _value_1.getTime());
    }
    return false;
};
var isSelectProcess = function isSelectProcess(array) {
    return Array.isArray(array) && !array[1];
};
var getSideForSelected = function getSideForSelected(date, startValue, endValue) {
    var currentDateTime = new Date(date.year, date.monthIndex, date.day).getTime();
    var startValueTime = startValue.getTime();
    var endValueTime = endValue.getTime();
    if (currentDateTime === startValueTime) {
        return 'right';
    }
    if (currentDateTime === endValueTime) {
        return 'left';
    }
    return undefined;
};
var getSideForHovered = function getSideForHovered(date, hoveredDay, startValue, isSelected) {
    var dateHover = new Date(hoveredDay.year, hoveredDay.monthIndex, hoveredDay.day);
    var isHovered = isSameDay(date, hoveredDay);
    if (isSelected && startValue > dateHover || isHovered && startValue < dateHover) {
        return 'left';
    }
    if (isSelected && startValue < dateHover || isHovered && startValue > dateHover) {
        return 'right';
    }
    return undefined;
};
var getSideInRange = function getSideInRange(value, date, hoveredDay, isSelected) {
    if (!Array.isArray(value)) {
        return undefined;
    }
    var _value = _sliced_to_array(value, 2), startValue = _value[0], endValue = _value[1];
    if (startValue && isSelected && endValue) {
        return getSideForSelected(date, startValue, endValue);
    }
    if (startValue && hoveredDay) {
        return getSideForHovered(date, hoveredDay, startValue, isSelected);
    }
    return undefined;
};
var getInRange = function getInRange(value, date, hoveredDay, inRange) {
    if (!isSelectProcess(value) || !hoveredDay) {
        return inRange;
    }
    var dateSelected = value[0];
    var dateHover = new Date(hoveredDay.year, hoveredDay.monthIndex, hoveredDay.day);
    var dateCurrent = new Date(date.year, date.monthIndex, date.day);
    if (dateSelected < dateCurrent && dateCurrent < dateHover || dateSelected > dateCurrent && dateCurrent > dateHover) {
        return true;
    }
    return inRange;
};
