import { InternalDateGetter } from './InternalDateGetter.js';
import { InternalDateComponentType } from './types.js';
import { InternalDateTransformer } from './InternalDateTransformer.js';
var calculateStartDate = function (startDate) {
    if (startDate) {
        return startDate;
    }
    return -Infinity;
};
var calculateEndDate = function (endDate) {
    if (endDate) {
        return endDate;
    }
    return Infinity;
};
var getValue = function (type, _a) {
    var year = _a.year, month = _a.month, date = _a.date;
    if (type === InternalDateComponentType.Year) {
        return year;
    }
    if (type === InternalDateComponentType.Month) {
        return month;
    }
    return date;
};
var InternalDateValidator = /** @class */ (function () {
    function InternalDateValidator() {
    }
    InternalDateValidator.checkForNull = function (_a, type) {
        var year = _a.year, month = _a.month, date = _a.date;
        if (type !== undefined) {
            if (type === InternalDateComponentType.Year) {
                return year !== null;
            }
            if (type === InternalDateComponentType.Month) {
                return month !== null;
            }
            if (type === InternalDateComponentType.All) {
                return year !== null && month !== null && date !== null;
            }
            return date !== null;
        }
        return !(year === null || month === null || date === null);
    };
    InternalDateValidator.checkLimits = function (_a, type) {
        var year = _a.year, month = _a.month, date = _a.date;
        if (type !== undefined) {
            var value = getValue(type, { date: date, month: month, year: year });
            return value >= InternalDateGetter.getDefaultMin(type) && value <= InternalDateGetter.getDefaultMax(type);
        }
        return (year >= InternalDateGetter.getDefaultMin(InternalDateComponentType.Year) &&
            year <= InternalDateGetter.getDefaultMax(InternalDateComponentType.Year) &&
            month >= InternalDateGetter.getDefaultMin(InternalDateComponentType.Month) &&
            month <= InternalDateGetter.getDefaultMax(InternalDateComponentType.Month) &&
            date >= InternalDateGetter.getDefaultMin(InternalDateComponentType.Date) &&
            date <= InternalDateGetter.getDefaultMax(InternalDateComponentType.Date));
    };
    InternalDateValidator.compareWithNativeDate = function (_a) {
        var year = _a.year, month = _a.month, date = _a.date;
        var nativeDate = InternalDateTransformer.componentsToNativeDate({ year: year, month: month, date: date });
        return (nativeDate.getUTCFullYear() === year && nativeDate.getUTCMonth() + 1 === month && nativeDate.getUTCDate() === date);
    };
    InternalDateValidator.checkRangeFully = function (date, startDate, endDate) {
        if (startDate === null && endDate === null) {
            return true;
        }
        var calculatedEndDate = calculateEndDate(endDate);
        var calculatedStartDate = calculateStartDate(startDate);
        return date >= calculatedStartDate && date <= calculatedEndDate;
    };
    InternalDateValidator.checkRangePiecemeal = function (type, _a, startComponents, endComponents) {
        var year = _a.year, month = _a.month, date = _a.date;
        if (startComponents === null && endComponents === null) {
            return true;
        }
        var _b = startComponents || {}, _c = _b.year, startYear = _c === void 0 ? -Infinity : _c, _d = _b.month, startMonth = _d === void 0 ? -Infinity : _d, _e = _b.date, startDate = _e === void 0 ? -Infinity : _e;
        var _f = endComponents || {}, _g = _f.year, endYear = _g === void 0 ? Infinity : _g, _h = _f.month, endMonth = _h === void 0 ? Infinity : _h, _j = _f.date, endDate = _j === void 0 ? Infinity : _j;
        if (type === InternalDateComponentType.Year) {
            return !(year < startYear || year > endYear);
        }
        else if (type === InternalDateComponentType.Month) {
            return !((year === startYear && month < startMonth) || (year === endYear && month > endMonth));
        }
        else if (type === InternalDateComponentType.Date) {
            return !((year === startYear && month === startMonth && date < startDate) ||
                (year === endYear && month === endMonth && date > endDate));
        }
        return true;
    };
    InternalDateValidator.testParseToNumber = function (value) {
        if (value !== null) {
            return typeof value === 'number' || !Number.isNaN(parseInt(value, 10));
        }
        return false;
    };
    InternalDateValidator.isEqualDateValues = function (a, b) {
        return a.toInternalString() === b.toInternalString();
    };
    InternalDateValidator.isEqualDateFormats = function (a, b) {
        var areOrdersEqual = a.getOrder() === b.getOrder();
        var areSeparatorsEqual = a.getSeparator() === b.getSeparator();
        return areOrdersEqual && areSeparatorsEqual;
    };
    return InternalDateValidator;
}());
export { InternalDateValidator };
//# sourceMappingURL=InternalDateValidator.js.map