"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 animateScrollTo () {
        return animateScrollTo;
    },
    get buildTimeString () {
        return buildTimeString;
    },
    get delimiter () {
        return delimiter;
    },
    get getColumnsFromFormat () {
        return getColumnsFromFormat;
    },
    get isTimeDisabled () {
        return isTimeDisabled;
    },
    get parseTimeString () {
        return parseTimeString;
    },
    get range () {
        return range;
    }
});
const getColumnsFromFormat = (format)=>{
    const parts = format.split(':');
    const columns = [];
    parts.forEach((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;
};
const parseTimeString = (timeString, format)=>{
    const timeParts = timeString.split(':');
    const formatParts = format.split(':');
    const result = {
        hh: null,
        mm: null,
        ss: null
    };
    formatParts.forEach((part, index)=>{
        const 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;
};
const buildTimeString = (timeValues, format)=>{
    const formatParts = format.split(':');
    return formatParts.map((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(':');
};
const isTimeDisabled = (timeValues, min, max, format)=>{
    if (!min && !max) return false;
    if (timeValues.hh === null || timeValues.mm === null || timeValues.ss === null) {
        return false;
    }
    const totalSeconds = timeValues.hh * 3600 + timeValues.mm * 60 + timeValues.ss;
    let minSeconds = 0;
    let maxSeconds = 23 * 3600 + 59 * 60 + 59;
    if (min) {
        if (min instanceof Date) {
            minSeconds = min.getHours() * 3600 + min.getMinutes() * 60 + min.getSeconds();
        } else {
            const minTime = parseTimeString(min, format ?? 'HH:mm:ss');
            minSeconds = (minTime.hh || 0) * 3600 + (minTime.mm || 0) * 60 + (minTime.ss || 0);
        }
    }
    if (max) {
        if (max instanceof Date) {
            maxSeconds = max.getHours() * 3600 + max.getMinutes() * 60 + max.getSeconds();
        } else {
            const maxTime = parseTimeString(max, format ?? 'HH:mm:ss');
            maxSeconds = (maxTime.hh || 0) * 3600 + (maxTime.mm || 0) * 60 + (maxTime.ss || 0);
        }
    }
    return totalSeconds < minSeconds || totalSeconds > maxSeconds;
};
const delimiter = ':';
const range = (number, padLength = 2)=>{
    return Array.from({
        length: number
    }, (_, i)=>i.toString().padStart(padLength, '0'));
};
const animateScrollTo = (element, targetScrollTop, duration = 300)=>{
    const startScrollTop = element.scrollTop;
    const distance = targetScrollTop - startScrollTop;
    let startTime = null;
    const animate = (currentTime)=>{
        if (!startTime) startTime = currentTime;
        const timeElapsed = currentTime - startTime;
        const progress = Math.min(timeElapsed / duration, 1);
        const easeOut = (t)=>1 - (1 - t) ** 3;
        const scrollPosition = startScrollTop + distance * easeOut(progress);
        element.scrollTop = scrollPosition;
        if (timeElapsed < duration) {
            requestAnimationFrame(animate);
        }
    };
    requestAnimationFrame(animate);
};
