"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "renderTimeColumn", {
    enumerable: true,
    get: function() {
        return renderTimeColumn;
    }
});
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
const _classnames = /*#__PURE__*/ _interop_require_default(require("classnames"));
const _TimePickerGridtokens = require("../../TimePickerGrid.tokens");
const _TimeColumnstyles = require("./TimeColumn.styles");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const renderTimeColumn = ({ values, disabledValues, dropdownHeight, column, activeTime, currentColumn, handleTimeItemClick, handleTimeItemKeyDown, createScrollbarDragHandler, setScrollbar, columnRef, scrollbarState, scrollbarRef, thumbRef, timeoutRef, timeItemRefs })=>{
    const handleKeyDown = (e, columnType, value)=>{
        handleTimeItemKeyDown(e, columnType, value);
    };
    const handleClick = (value, columnType)=>{
        const isDisabled = disabledValues?.some((disabledValue)=>parseInt(disabledValue.toString(), 10) === parseInt(value, 10));
        if (!isDisabled) {
            handleTimeItemClick(value, columnType);
        }
    };
    const minDisableIndex = ()=>{
        if (!disabledValues || disabledValues.length === 0) {
            return 0;
        }
        const disabledNumbers = disabledValues.map((val)=>parseInt(val.toString(), 10));
        for(let i = 0; i < values.length; i++){
            const currentValue = parseInt(values[i], 10);
            if (!disabledNumbers.includes(currentValue)) {
                return i;
            }
        }
        return 0;
    };
    const isColumnActive = currentColumn === column;
    const minAvailableIndex = minDisableIndex();
    return /*#__PURE__*/ _react.default.createElement(_TimeColumnstyles.StyledRoot, null, /*#__PURE__*/ _react.default.createElement(_TimeColumnstyles.StyledTimeColumn, {
        key: column,
        ref: columnRef,
        height: dropdownHeight,
        className: _TimePickerGridtokens.classes.timeColumn,
        tabIndex: -1
    }, values.map((value, index)=>{
        const isDisabled = disabledValues?.some((disabledValue)=>parseInt(disabledValue.toString(), 10) === parseInt(value, 10));
        const isActive = activeTime[column] === parseInt(value, 10);
        const getTabIndex = ()=>{
            if (isDisabled) return -1;
            const isValueActive = activeTime[column] === parseInt(value, 10);
            if (isColumnActive && isValueActive) {
                return 0;
            }
            if (index === minAvailableIndex) {
                return 0;
            }
            return -1;
        };
        const tabIndex = getTabIndex();
        return /*#__PURE__*/ _react.default.createElement(_TimeColumnstyles.StyledTimeItem, {
            key: column + value,
            ref: (el)=>{
                timeItemRefs.current[`${column}-${value}`] = el;
            },
            className: (0, _classnames.default)({
                [_TimePickerGridtokens.classes.timeItemActive]: isActive,
                [_TimePickerGridtokens.classes.itemDisabled]: isDisabled
            }),
            onClick: ()=>handleClick(value, column),
            onKeyDown: (e)=>handleKeyDown(e, column, value),
            "aria-disabled": isDisabled,
            tabIndex: tabIndex,
            "data-value": value,
            "data-column": column,
            "data-active": isActive
        }, value);
    }), /*#__PURE__*/ _react.default.createElement(_TimeColumnstyles.StyledEmpty, null)), /*#__PURE__*/ _react.default.createElement(_TimeColumnstyles.CustomScrollbar, {
        ref: scrollbarRef,
        className: (0, _classnames.default)({
            [_TimePickerGridtokens.classes.scrollbarVisible]: scrollbarState?.isVisible
        }),
        tabIndex: -1
    }, /*#__PURE__*/ _react.default.createElement(_TimeColumnstyles.ScrollbarTrack, null, /*#__PURE__*/ _react.default.createElement(_TimeColumnstyles.ScrollbarThumb, {
        ref: thumbRef,
        style: {
            height: `${scrollbarState?.thumbHeight}px`,
            top: `${scrollbarState?.thumbPosition}px`
        },
        onMouseDown: columnRef && setScrollbar && timeoutRef ? createScrollbarDragHandler(columnRef, setScrollbar, timeoutRef) : undefined,
        tabIndex: -1
    }))));
};
