function _instanceof(left, right) {
    if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
        return !!right[Symbol.hasInstance](left);
    } else {
        return left instanceof right;
    }
}
export var getColumnsFromFormat = function getColumnsFromFormat(format) {
    var parts = format.split(':');
    var columns = [];
    parts.forEach(function(part) {
        switch(part){
            case 'HH':
                columns.push({
                    type: 'hours',
                    values: range(24),
                    format: 'HH'
                });
                break;
            case 'mm':
                columns.push({
                    type: 'minutes',
                    values: range(60),
                    format: 'mm'
                });
                break;
            case 'ss':
                columns.push({
                    type: 'seconds',
                    values: range(60),
                    format: 'ss'
                });
                break;
            default:
        }
    });
    return columns;
};
export var parseTimeString = function parseTimeString(timeString, format) {
    var timeParts = timeString.split(':');
    var formatParts = format.split(':');
    var result = {
        hh: null,
        mm: null,
        ss: null
    };
    formatParts.forEach(function(part, index) {
        var value = timeParts[index] ? parseInt(timeParts[index], 10) : null;
        switch(part){
            case 'HH':
                result.hh = value;
                break;
            case 'mm':
                result.mm = value;
                break;
            case 'ss':
                result.ss = value;
                break;
            default:
        }
    });
    return result;
};
export var buildTimeString = function buildTimeString(timeValues, format) {
    var formatParts = format.split(':');
    return formatParts.map(function(part) {
        switch(part){
            case 'HH':
                return timeValues.hh !== null ? timeValues.hh.toString().padStart(2, '0') : '00';
            case 'mm':
                return timeValues.mm !== null ? timeValues.mm.toString().padStart(2, '0') : '00';
            case 'ss':
                return timeValues.ss !== null ? timeValues.ss.toString().padStart(2, '0') : '00';
            default:
                return '00';
        }
    }).join(':');
};
export var isTimeDisabled = function isTimeDisabled(timeValues, min, max, format) {
    if (!min && !max) return false;
    if (timeValues.hh === null || timeValues.mm === null || timeValues.ss === null) {
        return false;
    }
    var totalSeconds = timeValues.hh * 3600 + timeValues.mm * 60 + timeValues.ss;
    var minSeconds = 0;
    var maxSeconds = 23 * 3600 + 59 * 60 + 59;
    if (min) {
        if (_instanceof(min, Date)) {
            minSeconds = min.getHours() * 3600 + min.getMinutes() * 60 + min.getSeconds();
        } else {
            var minTime = parseTimeString(min, format !== null && format !== void 0 ? format : 'HH:mm:ss');
            minSeconds = (minTime.hh || 0) * 3600 + (minTime.mm || 0) * 60 + (minTime.ss || 0);
        }
    }
    if (max) {
        if (_instanceof(max, Date)) {
            maxSeconds = max.getHours() * 3600 + max.getMinutes() * 60 + max.getSeconds();
        } else {
            var maxTime = parseTimeString(max, format !== null && format !== void 0 ? format : 'HH:mm:ss');
            maxSeconds = (maxTime.hh || 0) * 3600 + (maxTime.mm || 0) * 60 + (maxTime.ss || 0);
        }
    }
    return totalSeconds < minSeconds || totalSeconds > maxSeconds;
};
export var delimiter = ':';
export var range = function range(number) {
    var padLength = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 2;
    return Array.from({
        length: number
    }, function(_, i) {
        return i.toString().padStart(padLength, '0');
    });
};
export var animateScrollTo = function animateScrollTo(element, targetScrollTop) {
    var duration = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 300;
    var startScrollTop = element.scrollTop;
    var distance = targetScrollTop - startScrollTop;
    var startTime = null;
    var animate = function animate1(currentTime) {
        if (!startTime) startTime = currentTime;
        var timeElapsed = currentTime - startTime;
        var progress = Math.min(timeElapsed / duration, 1);
        var easeOut = function easeOut(t) {
            return 1 - Math.pow(1 - t, 3);
        };
        var scrollPosition = startScrollTop + distance * easeOut(progress);
        element.scrollTop = scrollPosition;
        if (timeElapsed < duration) {
            requestAnimationFrame(animate);
        }
    };
    requestAnimationFrame(animate);
};
