"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 timePickerGridConfig () {
        return timePickerGridConfig;
    },
    get timePickerGridRoot () {
        return timePickerGridRoot;
    }
});
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _utils = require("./utils");
const _TimePickerGridstyles = require("./TimePickerGrid.styles");
const _base = require("./variations/_size/base");
const _base1 = require("./variations/_view/base");
const _base2 = require("./variations/_disabled/base");
const _TimeColumn = require("./ui/TimeColumn/TimeColumn");
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {
        __proto__: null
    };
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
const timePickerGridRoot = (Root)=>/*#__PURE__*/ (0, _react.forwardRef)(({ value: outerValue, view, size, disabled = false, dropdownWidth, dropdownHeight, format = 'HH:mm', min, max, columnsQuantity, disabledValues, multiplicityMinutes, multiplicitySeconds, onChange, ...rest }, ref)=>{
        const actualFormat = format || (columnsQuantity === 3 ? 'HH:mm:ss' : 'HH:mm');
        const columnsConfig = (0, _react.useMemo)(()=>(0, _utils.getColumnsFromFormat)(actualFormat, multiplicityMinutes, multiplicitySeconds), [
            actualFormat,
            multiplicityMinutes,
            multiplicitySeconds
        ]);
        const hoursColumnRef = (0, _react.useRef)(null);
        const minutesColumnRef = (0, _react.useRef)(null);
        const secondsColumnRef = (0, _react.useRef)(null);
        const timeItemRefs = (0, _react.useRef)({});
        const itemHeight = Object.values(timeItemRefs.current)[0]?.offsetHeight || 0;
        const hoursScrollbarRef = (0, _react.useRef)(null);
        const minutesScrollbarRef = (0, _react.useRef)(null);
        const secondsScrollbarRef = (0, _react.useRef)(null);
        const hoursThumbRef = (0, _react.useRef)(null);
        const minutesThumbRef = (0, _react.useRef)(null);
        const secondsThumbRef = (0, _react.useRef)(null);
        const hoursHideTimeoutRef = (0, _react.useRef)(null);
        const minutesHideTimeoutRef = (0, _react.useRef)(null);
        const secondsHideTimeoutRef = (0, _react.useRef)(null);
        const [innerTime, setInnerTime] = (0, _react.useState)(outerValue || '');
        const [gap, setGap] = (0, _react.useState)(0);
        const [hoursScrollbar, setHoursScrollbar] = (0, _react.useState)({
            isVisible: false,
            thumbHeight: 0,
            thumbPosition: 0,
            isDragging: false
        });
        const [minutesScrollbar, setMinutesScrollbar] = (0, _react.useState)({
            isVisible: false,
            thumbHeight: 0,
            thumbPosition: 0,
            isDragging: false
        });
        const [secondsScrollbar, setSecondsScrollbar] = (0, _react.useState)({
            isVisible: false,
            thumbHeight: 0,
            thumbPosition: 0,
            isDragging: false
        });
        const viewValue = outerValue ?? innerTime;
        const getActiveTime = ()=>{
            if (viewValue && columnsConfig.length > 0) {
                const timeValues = (0, _utils.parseTimeString)(viewValue, actualFormat);
                return {
                    hours: timeValues.hh,
                    minutes: timeValues.mm !== null ? (0, _utils.roundToMultiplicity)(timeValues.mm, multiplicityMinutes) : null,
                    seconds: timeValues.ss !== null ? (0, _utils.roundToMultiplicity)(timeValues.ss, multiplicitySeconds) : null
                };
            }
            return {
                hours: null,
                minutes: null,
                seconds: null
            };
        };
        const activeTime = getActiveTime();
        const [currentColumn, setCurrentColumn] = (0, _react.useState)(null);
        const getDisabledValuesForColumn = (0, _react.useCallback)((columnType)=>{
            let disabledFromProps;
            if (columnType === 'hours') {
                disabledFromProps = disabledValues?.hour || [];
            } else if (columnType === 'minutes') {
                disabledFromProps = disabledValues?.minute || [];
            } else {
                disabledFromProps = disabledValues?.second || [];
            }
            const disabledFromMinMax = [];
            if (min || max) {
                const timeValues = (0, _utils.parseTimeString)(viewValue || '00:00:00', actualFormat);
                for(let i = 0; i < (columnType === 'hours' ? 24 : 60); i++){
                    let isItemDisabled = false;
                    // last valid multiple for boundary checks (e.g. step=10 → 50, not 59)
                    const ssStep = multiplicitySeconds ?? 1;
                    const mmStep = multiplicityMinutes ?? 1;
                    const lastValidSS = Math.floor(59 / ssStep) * ssStep;
                    const lastValidMM = Math.floor(59 / mmStep) * mmStep;
                    if (columnType === 'hours') {
                        // hour i is disabled only if no selectable (i:mm:ss) exists in [min, max]
                        const latestInHour = getCompleteTimeValues({
                            hh: i,
                            mm: lastValidMM,
                            ss: lastValidSS
                        }, actualFormat);
                        const earliestInHour = getCompleteTimeValues({
                            hh: i,
                            mm: 0,
                            ss: 0
                        }, actualFormat);
                        if ((0, _utils.isTimeDisabled)(latestInHour, min, undefined, format)) {
                            isItemDisabled = true;
                        } else if ((0, _utils.isTimeDisabled)(earliestInHour, undefined, max, format)) {
                            isItemDisabled = true;
                        }
                    } else if (columnType === 'minutes') {
                        // minute i is disabled only if no selectable (hh:i:ss) exists in [min, max]
                        const currentHH = timeValues.hh ?? 0;
                        const latestInMinute = getCompleteTimeValues({
                            hh: currentHH,
                            mm: i,
                            ss: lastValidSS
                        }, actualFormat);
                        const earliestInMinute = getCompleteTimeValues({
                            hh: currentHH,
                            mm: i,
                            ss: 0
                        }, actualFormat);
                        if ((0, _utils.isTimeDisabled)(latestInMinute, min, undefined, format)) {
                            isItemDisabled = true;
                        } else if ((0, _utils.isTimeDisabled)(earliestInMinute, undefined, max, format)) {
                            isItemDisabled = true;
                        }
                    } else {
                        // seconds: exact check against current hh:mm
                        const testValues = {
                            ...timeValues,
                            ss: i
                        };
                        const completeTimeValues = getCompleteTimeValues(testValues, actualFormat);
                        isItemDisabled = (0, _utils.isTimeDisabled)(completeTimeValues, min, max, format);
                    }
                    if (isItemDisabled) {
                        disabledFromMinMax.push(i);
                    }
                }
            }
            const normalizedDisabledFromProps = disabledFromProps.map((val)=>typeof val === 'string' ? parseInt(val, 10) : val);
            return [
                ...new Set([
                    ...normalizedDisabledFromProps,
                    ...disabledFromMinMax
                ])
            ];
        }, [
            disabledValues,
            min,
            max,
            viewValue,
            actualFormat,
            multiplicityMinutes,
            multiplicitySeconds
        ]);
        const getCompleteTimeValues = (0, _react.useCallback)((timeValues, fmt)=>{
            const completeValues = {
                hh: 0,
                mm: 0,
                ss: 0
            };
            if (fmt.includes('HH')) {
                completeValues.hh = timeValues.hh !== null ? timeValues.hh : 0;
            }
            if (fmt.includes('mm')) {
                completeValues.mm = timeValues.mm !== null ? timeValues.mm : 0;
            }
            if (fmt.includes('ss')) {
                completeValues.ss = timeValues.ss !== null ? timeValues.ss : 0;
            }
            return completeValues;
        }, []);
        const getNextAvailableValue = (0, _react.useCallback)((currentIndex, values, disabledValuesForColumn, direction)=>{
            let newIndex = currentIndex;
            let iterations = 0;
            const maxIterations = values.length;
            do {
                newIndex = direction === 'up' ? (newIndex - 1 + values.length) % values.length : (newIndex + 1) % values.length;
                iterations++;
            }while (iterations < maxIterations && disabledValuesForColumn.includes(parseInt(values[newIndex], 10)) && newIndex !== currentIndex)
            return iterations < maxIterations && !disabledValuesForColumn.includes(parseInt(values[newIndex], 10)) ? newIndex : currentIndex;
        }, []);
        const minScrollbarTrackHeight = 20;
        const calculateScrollbar = (0, _react.useCallback)((columnRef)=>{
            if (!columnRef.current) return {
                thumbHeight: 0,
                thumbPosition: 0
            };
            const { scrollTop, scrollHeight, clientHeight } = columnRef.current;
            const trackHeight = clientHeight;
            const thumbHeight = Math.max(trackHeight / scrollHeight * trackHeight, minScrollbarTrackHeight);
            const maxScroll = scrollHeight - clientHeight;
            const thumbPosition = maxScroll > 0 ? scrollTop / maxScroll * (trackHeight - thumbHeight) : 0;
            return {
                thumbHeight,
                thumbPosition
            };
        }, []);
        const showScrollbarWithDelay = (0, _react.useCallback)((setScrollbar, timeoutRef, columnRef)=>{
            if (timeoutRef.current) {
                clearTimeout(timeoutRef.current);
            }
            updateScrollbar(columnRef, setScrollbar, true);
            timeoutRef.current = setTimeout(()=>{
                setScrollbar((prev)=>({
                        ...prev,
                        isVisible: false
                    }));
                timeoutRef.current = null;
            }, 2000);
        }, []);
        const updateScrollbar = (0, _react.useCallback)((columnRef, setScrollbar, show = false)=>{
            if (!columnRef.current) return;
            const { thumbHeight, thumbPosition } = calculateScrollbar(columnRef);
            setScrollbar((prev)=>({
                    ...prev,
                    thumbHeight,
                    thumbPosition,
                    isVisible: show || prev.isVisible
                }));
        }, [
            calculateScrollbar
        ]);
        const handleColumnScroll = (0, _react.useCallback)((columnRef, setScrollbar, timeoutRef)=>{
            showScrollbarWithDelay(setScrollbar, timeoutRef, columnRef);
        }, [
            showScrollbarWithDelay
        ]);
        const createScrollbarDragHandler = (0, _react.useCallback)((columnRef, setScrollbar, timeoutRef)=>(e)=>{
                e.preventDefault();
                const thumb = e.currentTarget;
                const track = thumb.parentElement;
                if (!columnRef.current || !track) return;
                if (timeoutRef.current) {
                    clearTimeout(timeoutRef.current);
                    timeoutRef.current = null;
                }
                const startY = e.clientY;
                const startThumbPosition = parseFloat(thumb.style.top || '0');
                const trackRect = track.getBoundingClientRect();
                const trackHeight = trackRect.height;
                const thumbHeight = thumb.offsetHeight;
                const { scrollHeight, clientHeight } = columnRef.current;
                const maxScroll = scrollHeight - clientHeight;
                const handleMouseMove = (moveEvent)=>{
                    const deltaY = moveEvent.clientY - startY;
                    const newThumbPosition = Math.max(0, Math.min(trackHeight - thumbHeight, startThumbPosition + deltaY));
                    const scrollPercentage = newThumbPosition / (trackHeight - thumbHeight);
                    const newScrollTop = scrollPercentage * maxScroll;
                    if (columnRef.current) {
                        columnRef.current.scrollTop = newScrollTop;
                    }
                    setScrollbar((prev)=>({
                            ...prev,
                            thumbPosition: newThumbPosition,
                            isDragging: true,
                            isVisible: true
                        }));
                };
                const handleMouseUp = ()=>{
                    document.removeEventListener('mousemove', handleMouseMove);
                    document.removeEventListener('mouseup', handleMouseUp);
                    setScrollbar((prev)=>({
                            ...prev,
                            isDragging: false
                        }));
                    showScrollbarWithDelay(setScrollbar, timeoutRef, columnRef);
                };
                document.addEventListener('mousemove', handleMouseMove);
                document.addEventListener('mouseup', handleMouseUp);
            }, [
            showScrollbarWithDelay
        ]);
        const handleContainerFocus = (0, _react.useCallback)(()=>{
            if (currentColumn === null && columnsConfig.length > 0) {
                const firstColumn = columnsConfig[0].type;
                setCurrentColumn((prev)=>prev !== currentColumn ? firstColumn : currentColumn);
            }
        }, [
            currentColumn,
            columnsConfig
        ]);
        /**
             * Возвращает первое не отключённое значение из колонки с учётом кратности.
             * Итерируем по фактическим значениям колонки (columnsConfig), а не по 0..23/59.
             */ const getFirstAvailableValue = (0, _react.useCallback)((columnType)=>{
            const disabledForColumn = getDisabledValuesForColumn(columnType);
            const columnValues = columnsConfig.find((c)=>c.type === columnType)?.values ?? [];
            for (const val of columnValues){
                const num = parseInt(val, 10);
                if (!disabledForColumn.includes(num)) {
                    return num;
                }
            }
            return 0;
        }, [
            getDisabledValuesForColumn,
            columnsConfig
        ]);
        const handleTimeItemClick = (value, column)=>{
            /**
                 * Применяем выбранное значение к соответствующей колонке
                 */ const newTimeValues = {
                ...(0, _utils.parseTimeString)(viewValue, actualFormat)
            };
            switch(column){
                case 'hours':
                    newTimeValues.hh = parseInt(value, 10);
                    break;
                case 'minutes':
                    newTimeValues.mm = parseInt(value, 10);
                    break;
                case 'seconds':
                    newTimeValues.ss = parseInt(value, 10);
                    break;
                default:
            }
            /**
                 * Незаполненные колонки получают первое доступное значение с учётом кратности
                 */ if (newTimeValues.hh === null && actualFormat.includes('HH')) {
                newTimeValues.hh = getFirstAvailableValue('hours');
            }
            if (newTimeValues.mm === null && actualFormat.includes('mm')) {
                newTimeValues.mm = getFirstAvailableValue('minutes');
            }
            if (newTimeValues.ss === null && actualFormat.includes('ss')) {
                newTimeValues.ss = getFirstAvailableValue('seconds');
            }
            /**
                 * Автокоррекция зависимых колонок при выходе за границы min/max.
                 * Секунды не требуют коррекции — пользователь выбрал точное значение.
                 */ if ((min || max) && column !== 'seconds') {
                const minParsed = (0, _utils.parseTimeBoundary)(min, format || 'HH:mm:ss');
                const maxParsed = (0, _utils.parseTimeBoundary)(max, format || 'HH:mm:ss');
                const total = (0, _utils.toTotalSeconds)(newTimeValues);
                if (minParsed && total < (0, _utils.toTotalSeconds)(minParsed)) {
                    Object.assign(newTimeValues, (0, _utils.clampTimeToMin)(newTimeValues, minParsed, column, actualFormat, multiplicityMinutes ?? 1, multiplicitySeconds ?? 1));
                } else if (maxParsed && total > (0, _utils.toTotalSeconds)(maxParsed)) {
                    Object.assign(newTimeValues, (0, _utils.clampTimeToMax)(newTimeValues, maxParsed, column, actualFormat, multiplicityMinutes ?? 1, multiplicitySeconds ?? 1));
                }
            }
            /**
                 * Если время всё равно вне диапазона — отклоняем клик
                 */ if ((0, _utils.isTimeDisabled)(getCompleteTimeValues(newTimeValues, actualFormat), min, max)) {
                return;
            }
            /**
                 * Фиксируем новое время
                 */ const newTimeString = (0, _utils.buildTimeString)(newTimeValues, actualFormat);
            setInnerTime(newTimeString);
            onChange?.({
                value: newTimeString,
                timeValues: {
                    hour: newTimeValues.hh || undefined,
                    minute: newTimeValues.mm || undefined,
                    second: newTimeValues.ss || undefined
                }
            });
        };
        const handleTimeItemKeyDown = (event, column, value)=>{
            const disabledValuesForColumn = getDisabledValuesForColumn(column);
            const currentIndex = parseInt(value, 10);
            let newIndex = null;
            let newColumn = column;
            switch(event.key){
                case 'ArrowUp':
                    event.preventDefault();
                    newIndex = getNextAvailableValue(currentIndex, column === 'hours' ? Array.from({
                        length: 24
                    }, (_, i)=>i.toString().padStart(2, '0')) : Array.from({
                        length: 60
                    }, (_, i)=>i.toString().padStart(2, '0')), disabledValuesForColumn, 'up');
                    if (newIndex !== null) {
                        const newValue = newIndex.toString().padStart(2, '0');
                        const element = timeItemRefs.current[`${column}-${newValue}`];
                        setTimeout(()=>{
                            if (element) {
                                element.focus();
                            }
                        }, 0);
                    }
                    break;
                case 'ArrowDown':
                    event.preventDefault();
                    newIndex = getNextAvailableValue(currentIndex, column === 'hours' ? Array.from({
                        length: 24
                    }, (_, i)=>i.toString().padStart(2, '0')) : Array.from({
                        length: 60
                    }, (_, i)=>i.toString().padStart(2, '0')), disabledValuesForColumn, 'down');
                    if (newIndex !== null) {
                        const newValue = newIndex.toString().padStart(2, '0');
                        const element = timeItemRefs.current[`${column}-${newValue}`];
                        setTimeout(()=>{
                            if (element) {
                                element.focus();
                            }
                        }, 0);
                    }
                    break;
                case 'ArrowRight':
                    event.preventDefault();
                    if (column === 'hours') {
                        newColumn = 'minutes';
                    } else if (column === 'minutes' && actualFormat.includes('ss')) {
                        newColumn = 'seconds';
                    }
                    if (newColumn !== column) {
                        setCurrentColumn(newColumn);
                        const newValue = (activeTime[column]?.toString() || '0').padStart(2, '0');
                        const element = timeItemRefs.current[`${newColumn}-${newValue}`];
                        setTimeout(()=>{
                            if (element) {
                                element.focus();
                            }
                        }, 0);
                    }
                    break;
                case 'ArrowLeft':
                    event.preventDefault();
                    if (column === 'minutes') {
                        newColumn = 'hours';
                    } else if (column === 'seconds') {
                        newColumn = 'minutes';
                    }
                    if (newColumn !== column) {
                        setCurrentColumn(newColumn);
                        const newValue = (activeTime[column]?.toString() || '0').padStart(2, '0');
                        const element = timeItemRefs.current[`${newColumn}-${newValue}`];
                        setTimeout(()=>{
                            if (element) {
                                element.focus();
                            }
                        }, 0);
                    }
                    break;
                case 'Enter':
                case ' ':
                    event.preventDefault();
                    handleTimeItemClick(value, column);
                    break;
                case 'Home':
                    event.preventDefault();
                    newIndex = 0;
                    while(disabledValuesForColumn.includes(newIndex) && newIndex < (column === 'hours' ? 24 : 60)){
                        newIndex++;
                    }
                    if (newIndex < (column === 'hours' ? 24 : 60)) {
                        const newValue = newIndex.toString().padStart(2, '0');
                        const element = timeItemRefs.current[`${column}-${newValue}`];
                        setTimeout(()=>{
                            if (element) {
                                element.focus();
                            }
                        }, 0);
                    }
                    break;
                case 'End':
                    event.preventDefault();
                    newIndex = column === 'hours' ? 23 : 59;
                    while(disabledValuesForColumn.includes(newIndex) && newIndex >= 0){
                        newIndex--;
                    }
                    if (newIndex >= 0) {
                        const newValue = newIndex.toString().padStart(2, '0');
                        const element = timeItemRefs.current[`${column}-${newValue}`];
                        setTimeout(()=>{
                            if (element) {
                                element.focus();
                            }
                        }, 0);
                    }
                    break;
                default:
                    break;
            }
        };
        (0, _react.useEffect)(()=>{
            if (currentColumn && currentColumn !== null) {
                const column = currentColumn;
                const value = activeTime[currentColumn]?.toString().padStart(2, '0');
                const element = timeItemRefs.current[`${column}-${value}`];
                setTimeout(()=>{
                    if (element) {
                        element.focus();
                    }
                }, 0);
            }
        }, [
            currentColumn
        ]);
        (0, _react.useEffect)(()=>{
            return ()=>{
                [
                    hoursHideTimeoutRef,
                    minutesHideTimeoutRef,
                    secondsHideTimeoutRef
                ].forEach((timeoutRef)=>{
                    if (timeoutRef.current) {
                        clearTimeout(timeoutRef.current);
                    }
                });
            };
        }, []);
        (0, _react.useEffect)(()=>{
            if (hoursColumnRef.current) {
                const computedStyle = getComputedStyle(hoursColumnRef.current);
                const gapValue = parseFloat(computedStyle.gap || '0');
                setGap(gapValue);
            }
        }, [
            hoursColumnRef.current
        ]);
        (0, _react.useEffect)(()=>{
            setTimeout(()=>{
                updateScrollbar(hoursColumnRef, setHoursScrollbar);
                updateScrollbar(minutesColumnRef, setMinutesScrollbar);
                if (columnsQuantity === 3) {
                    updateScrollbar(secondsColumnRef, setSecondsScrollbar);
                }
            }, 100);
        }, [
            columnsQuantity
        ]);
        (0, _react.useEffect)(()=>{
            if (itemHeight === 0) return;
            const scrollToActiveItem = (columnRef, index)=>{
                if (columnRef.current && index !== null) {
                    const scrollPosition = index * (itemHeight + gap);
                    (0, _utils.animateScrollTo)(columnRef.current, scrollPosition);
                    setTimeout(()=>{
                        updateScrollbar(columnRef, setHoursScrollbar);
                    }, 300);
                }
            };
            const minutesIndex = activeTime.minutes !== null ? activeTime.minutes / (multiplicityMinutes ?? 1) : null;
            const secondsIndex = activeTime.seconds !== null ? activeTime.seconds / (multiplicitySeconds ?? 1) : null;
            scrollToActiveItem(hoursColumnRef, activeTime.hours);
            scrollToActiveItem(minutesColumnRef, minutesIndex);
            scrollToActiveItem(secondsColumnRef, secondsIndex);
        }, [
            activeTime.hours,
            activeTime.minutes,
            activeTime.seconds,
            itemHeight,
            gap,
            multiplicityMinutes,
            multiplicitySeconds
        ]);
        (0, _react.useEffect)(()=>{
            const hoursColumn = hoursColumnRef.current;
            const minutesColumn = minutesColumnRef.current;
            const secondsColumn = secondsColumnRef.current;
            const handleHoursScroll = ()=>handleColumnScroll(hoursColumnRef, setHoursScrollbar, hoursHideTimeoutRef);
            const handleMinutesScroll = ()=>handleColumnScroll(minutesColumnRef, setMinutesScrollbar, minutesHideTimeoutRef);
            const handleSecondsScroll = ()=>handleColumnScroll(secondsColumnRef, setSecondsScrollbar, secondsHideTimeoutRef);
            if (hoursColumn) {
                hoursColumn.addEventListener('scroll', handleHoursScroll);
            }
            if (minutesColumn) {
                minutesColumn.addEventListener('scroll', handleMinutesScroll);
            }
            if (secondsColumn) {
                secondsColumn.addEventListener('scroll', handleSecondsScroll);
            }
            return ()=>{
                if (hoursColumn) {
                    hoursColumn.removeEventListener('scroll', handleHoursScroll);
                }
                if (minutesColumn) {
                    minutesColumn.removeEventListener('scroll', handleMinutesScroll);
                }
                if (secondsColumn) {
                    secondsColumn.removeEventListener('scroll', handleSecondsScroll);
                }
            };
        }, []);
        (0, _react.useEffect)(()=>{
            const hoursColumn = hoursColumnRef.current;
            const minutesColumn = minutesColumnRef.current;
            const secondsColumn = secondsColumnRef.current;
            const handleHoursMouseEnter = ()=>showScrollbarWithDelay(setHoursScrollbar, hoursHideTimeoutRef, hoursColumnRef);
            const handleMinutesMouseEnter = ()=>showScrollbarWithDelay(setMinutesScrollbar, minutesHideTimeoutRef, minutesColumnRef);
            const handleSecondsMouseEnter = ()=>showScrollbarWithDelay(setSecondsScrollbar, secondsHideTimeoutRef, secondsColumnRef);
            if (hoursColumn) {
                hoursColumn.addEventListener('mouseenter', handleHoursMouseEnter);
            }
            if (minutesColumn) {
                minutesColumn.addEventListener('mouseenter', handleMinutesMouseEnter);
            }
            if (secondsColumn) {
                secondsColumn.addEventListener('mouseenter', handleSecondsMouseEnter);
            }
            return ()=>{
                if (hoursColumn) {
                    hoursColumn.removeEventListener('mouseenter', handleHoursMouseEnter);
                }
                if (minutesColumn) {
                    minutesColumn.removeEventListener('mouseenter', handleMinutesMouseEnter);
                }
                if (secondsColumn) {
                    secondsColumn.removeEventListener('mouseenter', handleSecondsMouseEnter);
                }
            };
        }, []);
        return /*#__PURE__*/ _react.default.createElement(Root, {
            ref: ref,
            view: view,
            size: size,
            disabled: disabled,
            onFocus: handleContainerFocus,
            ...rest
        }, /*#__PURE__*/ _react.default.createElement(_TimePickerGridstyles.StyledTimePicker, {
            width: dropdownWidth,
            tabIndex: -1
        }, columnsConfig.map((columnConfig)=>{
            const { type, values } = columnConfig;
            let columnRef;
            let scrollbarState;
            let setScrollbar;
            let scrollbarRef;
            let thumbRef;
            let timeoutRef;
            switch(type){
                case 'hours':
                    columnRef = hoursColumnRef;
                    scrollbarState = hoursScrollbar;
                    setScrollbar = setHoursScrollbar;
                    scrollbarRef = hoursScrollbarRef;
                    thumbRef = hoursThumbRef;
                    timeoutRef = hoursHideTimeoutRef;
                    break;
                case 'minutes':
                    columnRef = minutesColumnRef;
                    scrollbarState = minutesScrollbar;
                    setScrollbar = setMinutesScrollbar;
                    scrollbarRef = minutesScrollbarRef;
                    thumbRef = minutesThumbRef;
                    timeoutRef = minutesHideTimeoutRef;
                    break;
                case 'seconds':
                    columnRef = secondsColumnRef;
                    scrollbarState = secondsScrollbar;
                    setScrollbar = setSecondsScrollbar;
                    scrollbarRef = secondsScrollbarRef;
                    thumbRef = secondsThumbRef;
                    timeoutRef = secondsHideTimeoutRef;
                    break;
                default:
                    return null;
            }
            return (0, _TimeColumn.renderTimeColumn)({
                values,
                disabledValues: getDisabledValuesForColumn(type),
                dropdownHeight,
                column: type,
                activeTime,
                currentColumn,
                handleTimeItemClick,
                handleTimeItemKeyDown,
                createScrollbarDragHandler,
                setScrollbar,
                columnRef,
                scrollbarState,
                scrollbarRef,
                thumbRef,
                timeoutRef,
                timeItemRefs
            });
        })));
    });
const timePickerGridConfig = {
    name: 'TimePickerGrid',
    tag: 'div',
    layout: timePickerGridRoot,
    base: _TimePickerGridstyles.base,
    variations: {
        view: {
            css: _base1.base
        },
        size: {
            css: _base.base
        },
        disabled: {
            css: _base2.base,
            attrs: true
        }
    },
    defaults: {
        size: 'm',
        view: 'default'
    }
};
