"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 selectConfig () {
        return selectConfig;
    },
    get selectRoot () {
        return selectRoot;
    }
});
var _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
var _utils = require("../../utils");
var _hooks = require("../../hooks");
var _useKeyboardNavigation = require("./hooks/useKeyboardNavigation");
var _utils1 = require("./utils");
var _ui = require("./ui");
var _reducers = require("./reducers");
var _usePathMaps = require("./hooks/usePathMaps");
var _Selectstyles = require("./Select.styles");
var _Selecttokens = require("./Select.tokens");
var _FloatingPopover = require("./FloatingPopover");
var _SelectNative = require("./ui/SelectNative/SelectNative");
var _Selectcontext = require("./Select.context");
function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
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;
}
function _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function _object_without_properties(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys, key, i;
    if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
        sourceKeys = Reflect.ownKeys(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
        return target;
    }
    target = _object_without_properties_loose(source, excluded);
    if (Object.getOwnPropertySymbols) {
        sourceKeys = Object.getOwnPropertySymbols(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
    }
    return target;
}
function _object_without_properties_loose(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
    for(i = 0; i < sourceKeys.length; i++){
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) continue;
        if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
        target[key] = source[key];
    }
    return target;
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _type_of(obj) {
    "@swc/helpers - typeof";
    return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
var selectRoot = function selectRoot(Root) {
    return /*#__PURE__*/ (0, _react.forwardRef)(function(props, ref) {
        var _getItemByFocused;
        var // eslint-disable-block @typescript-eslint/ban-ts-comment
        id = props.id, outerValue = props.value, outerOnChange = props.onChange, _props_target = props.target, target = _props_target === void 0 ? 'textfield-like' : _props_target, items = props.items, _props_treeView = props.treeView, treeView = _props_treeView === void 0 ? false : _props_treeView, _props_arrowPlacement = props.arrowPlacement, arrowPlacement = _props_arrowPlacement === void 0 ? 'left' : _props_arrowPlacement, _props_placement = props.placement, placement = _props_placement === void 0 ? 'bottom' : _props_placement, label = props.label, labelPlacement = props.labelPlacement, placeholder = props.placeholder, helperText = props.helperText, _props_disabled = props.disabled, disabled = _props_disabled === void 0 ? false : _props_disabled, _props_readOnly = props.readOnly, readOnly = _props_readOnly === void 0 ? false : _props_readOnly, outerView = props.view, size = props.size, listOverflow = props.listOverflow, listHeight = props.listHeight, listMaxHeight = props.listMaxHeight, listWidth = props.listWidth, contentLeft = props.contentLeft, contentRight = props.contentRight, onScrollBottom = props.onScrollBottom, onScroll = props.onScroll, chipView = props.chipView, _props_variant = props.variant, variant = _props_variant === void 0 ? 'normal' : _props_variant, portal = props.portal, renderValue = props.renderValue, renderItem = props.renderItem, renderSelectionIcon = props.renderSelectionIcon, status = props.status, onItemSelect = props.onItemSelect, separator = props.separator, outerCloseAfterSelect = props.closeAfterSelect, isTargetAmount = props.isTargetAmount, beforeList = props.beforeList, afterList = props.afterList, zIndex = props.zIndex, name = props.name, defaultValue = props.defaultValue, _props_virtual = props.virtual, virtual = _props_virtual === void 0 ? false : _props_virtual, onToggle = props.onToggle, chipType = props.chipType, multiselect = props.multiselect, _props_mode = props.mode, mode = _props_mode === void 0 ? 'default' : _props_mode, shift = props.shift, flip = props.flip, chipClickArea = props.chipClickArea, singleLine = props.singleLine, emptyStateDescription = props.emptyStateDescription, // @ts-ignore
        _offset = props._offset, // Извлекаем пропсы для required и hint, чтобы они не попадали в DOM.
        // @ts-ignore
        required = props.required, // @ts-ignore
        requiredPlacement = props.requiredPlacement, // @ts-ignore
        hasRequiredIndicator = props.hasRequiredIndicator, // @ts-ignore
        optional = props.optional, // @ts-ignore
        hintText = props.hintText, // @ts-ignore
        hintTrigger = props.hintTrigger, // @ts-ignore
        hintView = props.hintView, // @ts-ignore
        hintSize = props.hintSize, // @ts-ignore
        hintTargetPlacement = props.hintTargetPlacement, // @ts-ignore
        hintPlacement = props.hintPlacement, // @ts-ignore
        hintWidth = props.hintWidth, // @ts-ignore
        hintHasArrow = props.hintHasArrow, // @ts-ignore
        hasHint = props.hasHint, rest = _object_without_properties(props, [
            "id",
            "value",
            "onChange",
            "target",
            "items",
            "treeView",
            "arrowPlacement",
            "placement",
            "label",
            "labelPlacement",
            "placeholder",
            "helperText",
            "disabled",
            "readOnly",
            "view",
            "size",
            "listOverflow",
            "listHeight",
            "listMaxHeight",
            "listWidth",
            "contentLeft",
            "contentRight",
            "onScrollBottom",
            "onScroll",
            "chipView",
            "variant",
            "portal",
            "renderValue",
            "renderItem",
            "renderSelectionIcon",
            "status",
            "onItemSelect",
            "separator",
            "closeAfterSelect",
            "isTargetAmount",
            "beforeList",
            "afterList",
            "zIndex",
            "name",
            "defaultValue",
            "virtual",
            "onToggle",
            "chipType",
            "multiselect",
            "mode",
            "shift",
            "flip",
            "chipClickArea",
            "singleLine",
            "emptyStateDescription",
            "_offset",
            "required",
            "requiredPlacement",
            "hasRequiredIndicator",
            "optional",
            "hintText",
            "hintTrigger",
            "hintView",
            "hintSize",
            "hintTargetPlacement",
            "hintPlacement",
            "hintWidth",
            "hintHasArrow",
            "hasHint"
        ]);
        var transformedItems = (0, _react.useMemo)(function() {
            return (0, _utils1.initialItemsTransform)(items || []);
        }, [
            items
        ]);
        // Создаем структуры для быстрой работы с деревом
        var _usePathMaps1 = _sliced_to_array((0, _usePathMaps.usePathMaps)(transformedItems), 5), pathMap = _usePathMaps1[0], focusedToValueMap = _usePathMaps1[1], valueToCheckedMap = _usePathMaps1[2], valueToItemMap = _usePathMaps1[3], valueToPathMap = _usePathMaps1[4];
        var _useState = _sliced_to_array((0, _react.useState)(props.multiselect ? [] : ''), 2), internalValue = _useState[0], setInternalValue = _useState[1];
        var value = outerValue !== null && outerValue !== undefined ? outerValue : internalValue;
        var floatingPopoverRef = (0, _react.useRef)(null);
        // Состояния дерева элементов
        var _useReducer = _sliced_to_array((0, _react.useReducer)(_reducers.pathReducer, []), 2), path = _useReducer[0], dispatchPath = _useReducer[1];
        var _useReducer1 = _sliced_to_array((0, _react.useReducer)(_reducers.treePathReducer, {}), 2), treePath = _useReducer1[0], dispatchTreePath = _useReducer1[1];
        var _useReducer2 = _sliced_to_array((0, _react.useReducer)(_reducers.focusedPathReducer, []), 2), focusedPath = _useReducer2[0], dispatchFocusedPath = _useReducer2[1];
        var _useState1 = _sliced_to_array((0, _react.useState)(valueToCheckedMap), 2), checked = _useState1[0], setChecked = _useState1[1];
        var isCurrentListOpen = Boolean(path[0]);
        var activeDescendantItemValue = ((_getItemByFocused = (0, _useKeyboardNavigation.getItemByFocused)(focusedPath, focusedToValueMap)) === null || _getItemByFocused === void 0 ? void 0 : _getItemByFocused.value.toString()) || '';
        var closeAfterSelect = outerCloseAfterSelect !== null && outerCloseAfterSelect !== void 0 ? outerCloseAfterSelect : !props.multiselect;
        var treeId = (0, _utils.safeUseId)();
        var listWrapperRef = (0, _react.useRef)(null);
        var view = target === 'textfield-like' && (disabled || readOnly) ? 'default' : (0, _utils1.getView)(status, outerView);
        var rootRef = (0, _react.useRef)(null);
        // Собираем объект с пропсами для required и прокидываем их напрямую в компонент Textfield.
        var requiredProps = props.target === 'button-like' ? undefined : {
            required: required,
            requiredPlacement: requiredPlacement,
            hasRequiredIndicator: hasRequiredIndicator,
            optional: optional
        };
        // Собираем объект с пропсами для hint и прокидываем их напрямую в компонент Textfield.
        var hintProps = props.target === 'button-like' ? undefined : {
            hintText: hintText,
            hintTrigger: hintTrigger,
            hintView: hintView,
            hintSize: hintSize,
            hintTargetPlacement: hintTargetPlacement,
            hintPlacement: hintPlacement,
            hintWidth: hintWidth,
            hintHasArrow: hintHasArrow
        };
        /* Логика работы при клике за пределами выпадающего списка */ (0, _hooks.useOutsideClick)(function() {
            if (!isCurrentListOpen) {
                return;
            }
            handleListToggle(false);
        }, [
            floatingPopoverRef,
            listWrapperRef
        ]);
        var onChange = function onChange(newValue, item) {
            if (props.onChange) {
                // Условие для отправки если компонент используется без формы.
                if (!props.name && (typeof newValue === 'string' || Array.isArray(newValue))) {
                    props.onChange(newValue, item || null);
                }
                // Условие для отправки если компонент используется с формой.
                // Убрать условие "typeof ref === 'function'" в PLASMA 2.0
                if (props.name && (typeof newValue === "undefined" ? "undefined" : _type_of(newValue)) === 'object' && !Array.isArray(newValue)) {
                    props.onChange(newValue, item || null);
                }
            }
            // Условие для изменения внутреннего значения (только если newValue строка или массив строк).
            if (typeof newValue === 'string' || Array.isArray(newValue)) {
                setInternalValue(newValue);
            }
        };
        var handleListToggle = function handleListToggle(opened) {
            if (disabled || readOnly) {
                return;
            }
            if (opened) {
                dispatchPath({
                    type: 'opened_first_level'
                });
            } else {
                var _rootRef_current;
                dispatchFocusedPath({
                    type: 'reset'
                });
                dispatchPath({
                    type: 'reset'
                });
                dispatchTreePath({
                    type: 'reset'
                });
                // Скроллим чипы к левому краю при закрытии компонента
                var el = rootRef === null || rootRef === void 0 ? void 0 : (_rootRef_current = rootRef.current) === null || _rootRef_current === void 0 ? void 0 : _rootRef_current.querySelector('.input-scrollable-wrapper');
                if (multiselect && value.length > 0 && el) {
                    el.scrollLeft = 0;
                }
            }
            if (onToggle) {
                onToggle(opened);
            }
        };
        var handleCheckboxChange = function handleCheckboxChange(item) {
            if (!props.multiselect) {
                return;
            }
            var checkedCopy = new Map(checked);
            switch(checkedCopy.get(item.value)){
                // Если чекбокс в состоянии indeterminate
                case 'indeterminate':
                    {
                        (0, _utils1.updateDescendants)(item, checkedCopy, true, valueToItemMap);
                        break;
                    }
                // Если чекбокс в состоянии checked
                case true:
                    {
                        (0, _utils1.updateDescendants)(item, checkedCopy, false, valueToItemMap);
                        checkedCopy.set(item.value, false);
                        break;
                    }
                // Если чекбокс в состоянии unchecked
                case false:
                    {
                        (0, _utils1.updateDescendants)(item, checkedCopy, true, valueToItemMap);
                        checkedCopy.set(item.value, true);
                        break;
                    }
                default:
                    {
                        break;
                    }
            }
            var newValues = [];
            valueToItemMap.forEach(function(item, key) {
                if (checkedCopy.get(key)) {
                    newValues.push(item.value);
                }
            });
            // Оставляем values, которых нет в items.
            if (Array.isArray(value)) {
                value.forEach(function(val) {
                    if (!valueToItemMap.has(val)) {
                        newValues.push(val);
                    }
                });
            }
            if (closeAfterSelect) {
                dispatchPath({
                    type: 'reset'
                });
                dispatchFocusedPath({
                    type: 'reset'
                });
                dispatchTreePath({
                    type: 'reset'
                });
            }
            if (onChange) {
                onChange(newValues, item);
            }
        };
        var handleItemClick = function handleItemClick(item, e) {
            if (!(0, _utils.isEmpty)(item === null || item === void 0 ? void 0 : item.items)) {
                return;
            }
            if (props.multiselect) {
                handleCheckboxChange(item);
                return;
            }
            if (e) {
                e.stopPropagation();
            }
            var isCurrentChecked = checked.get(item.value);
            if (closeAfterSelect) {
                dispatchPath({
                    type: 'reset'
                });
                dispatchFocusedPath({
                    type: 'reset'
                });
                dispatchTreePath({
                    type: 'reset'
                });
            }
            // Закрываем список, если элемент уже выбран.
            if (mode === 'radio' && isCurrentChecked) {
                return;
            }
            if (onChange) {
                onChange(isCurrentChecked ? '' : item.value, item);
            }
            if (onItemSelect) {
                onItemSelect(item, e);
            }
        };
        var handlePressDown = function handlePressDown(item, e) {
            if ((0, _utils.isEmpty)(item.items)) {
                handleItemClick(item, e);
            } else if (props.multiselect) {
                handleCheckboxChange(item);
            }
        };
        var handleScroll = function handleScroll(e) {
            if (onScroll) {
                onScroll(e);
            }
            if (!onScrollBottom) return;
            var target = e.target;
            if (target.scrollHeight - target.scrollTop === target.clientHeight) {
                onScrollBottom(e);
            }
        };
        var onKeyDown = (0, _useKeyboardNavigation.useKeyNavigation)({
            focusedPath: focusedPath,
            dispatchFocusedPath: dispatchFocusedPath,
            path: path,
            dispatchPath: dispatchPath,
            pathMap: pathMap,
            focusedToValueMap: focusedToValueMap,
            handleListToggle: handleListToggle,
            handlePressDown: handlePressDown,
            treePath: treePath,
            dispatchTreePath: dispatchTreePath,
            treeView: treeView,
            valueToPathMap: valueToPathMap,
            items: transformedItems,
            readOnly: readOnly
        }).onKeyDown;
        // В данном эффекте мы следим за изменениями value снаружи и вносим коррективы в дерево чекбоксов.
        // Пример: когда юзер очистил value извне, тогда нужно пройтись по элементам и выключить все чекбоксы.
        (0, _react.useLayoutEffect)(function() {
            var checkedCopy = new Map(valueToCheckedMap);
            checkedCopy.forEach(function(_, key) {
                checkedCopy.set(key, false);
            });
            if (!(0, _utils.isEmpty)(value) || typeof value === 'number') {
                if (Array.isArray(value)) {
                    value.forEach(function(val) {
                        // Только если value находится в items, т.к. value может и не существовать в items.
                        if (valueToItemMap.has(val)) {
                            checkedCopy.set(val, true);
                            (0, _utils1.updateDescendants)(valueToItemMap.get(val), checkedCopy, true);
                            (0, _utils1.updateAncestors)(valueToItemMap.get(val), checkedCopy);
                        }
                    });
                } else {
                    // Только если value находится в items, т.к. value может и не существовать в items.
                    // eslint-disable-next-line no-lonely-if
                    if (valueToItemMap.has(value)) {
                        checkedCopy.set(value, 'done');
                        (0, _utils1.updateSingleAncestors)(valueToItemMap.get(value), checkedCopy, 'dot');
                    }
                }
            }
            setChecked(checkedCopy);
        // В deps мы кладем именно outerValue и internalValue, а не просто value.
        // Т.к. вначале нужно отфильтровать и провалидировать outerValue и результат положить в переменную.
        // А переменную, содержащую сложные типы данных, нельзя помещать в deps.
        }, [
            outerValue,
            internalValue,
            items
        ]);
        (0, _react.useLayoutEffect)(function() {
            if (defaultValue) {
                setInternalValue(defaultValue);
            }
        }, [
            defaultValue
        ]);
        return /*#__PURE__*/ _react.default.createElement(Root, _object_spread({
            view: view,
            size: size,
            labelPlacement: labelPlacement,
            chipView: chipView,
            disabled: disabled,
            readOnly: readOnly,
            hintView: hintView,
            hintSize: hintSize,
            id: id,
            ref: rootRef
        }, rest), name && /*#__PURE__*/ _react.default.createElement(_SelectNative.SelectNative, {
            items: valueToItemMap,
            name: name,
            value: internalValue,
            multiselect: props.multiselect,
            onChange: onChange,
            onSetValue: setInternalValue,
            ref: ref
        }), /*#__PURE__*/ _react.default.createElement(_Selectcontext.Context.Provider, {
            value: {
                focusedPath: focusedPath,
                checked: checked,
                multiselect: props.multiselect,
                size: size,
                handleCheckboxChange: handleCheckboxChange,
                handleItemClick: handleItemClick,
                variant: variant,
                renderItem: renderItem,
                renderSelectionIcon: renderSelectionIcon,
                treeId: treeId,
                // eslint-disable-next-line @typescript-eslint/ban-ts-comment
                // @ts-ignore
                // eslint-disable-next-line no-underscore-dangle
                _checkboxAppearance: rest._checkboxAppearance,
                treePath: treePath,
                dispatchTreePath: dispatchTreePath,
                arrowPlacement: arrowPlacement,
                valueToPathMap: valueToPathMap,
                singleLine: singleLine
            }
        }, /*#__PURE__*/ _react.default.createElement(_FloatingPopover.FloatingPopover, {
            ref: floatingPopoverRef,
            opened: isCurrentListOpen,
            onToggle: handleListToggle,
            placement: placement,
            portal: portal,
            listWidth: listWidth,
            offset: _offset,
            target: function target(referenceRef) {
                return /*#__PURE__*/ _react.default.createElement(_ui.Target, {
                    ref: name ? null : ref,
                    value: value,
                    opened: isCurrentListOpen,
                    valueToItemMap: valueToItemMap,
                    label: label,
                    placeholder: placeholder,
                    onKeyDown: onKeyDown,
                    labelPlacement: labelPlacement,
                    size: size,
                    contentLeft: contentLeft,
                    contentRight: contentRight,
                    disabled: disabled,
                    readOnly: readOnly,
                    renderValue: renderValue,
                    selectProps: props,
                    inputWrapperRef: referenceRef,
                    multiselect: props.multiselect,
                    view: view,
                    helperText: helperText,
                    treeId: treeId,
                    activeDescendantItemValue: activeDescendantItemValue,
                    isTargetAmount: isTargetAmount,
                    onChange: onChange,
                    chipView: chipView,
                    separator: separator,
                    requiredProps: requiredProps,
                    hintProps: hintProps
                });
            },
            zIndex: zIndex,
            isInner: false,
            shift: shift,
            flip: flip
        }, /*#__PURE__*/ _react.default.createElement(Root, _object_spread({
            view: view,
            size: size,
            labelPlacement: labelPlacement,
            chipView: chipView,
            disabled: disabled,
            readOnly: readOnly
        }, rest), treeView ? /*#__PURE__*/ _react.default.createElement(_ui.TreeList, {
            items: items,
            listMaxHeight: listMaxHeight,
            onScroll: virtual ? undefined : handleScroll,
            virtual: virtual,
            beforeList: beforeList,
            afterList: afterList,
            emptyStateDescription: emptyStateDescription
        }) : /*#__PURE__*/ _react.default.createElement(_Selectstyles.ListWrapper, {
            ref: listWrapperRef,
            listWidth: listWidth
        }, /*#__PURE__*/ _react.default.createElement(_Selectstyles.Ul, {
            role: "tree",
            id: "".concat(treeId, "_tree_level_1"),
            "aria-multiselectable": Boolean(props.multiselect),
            listMaxHeight: listMaxHeight || listHeight,
            onScroll: virtual ? undefined : handleScroll,
            virtual: virtual
        }, beforeList, props.multiselect && props.selectAllOptions && // TODO: #2004
        /*#__PURE__*/ _react.default.createElement(_ui.SelectAll, {
            selectAllOptions: props.selectAllOptions,
            variant: variant
        }), (0, _utils.isEmpty)(transformedItems) ? /*#__PURE__*/ _react.default.createElement(_Selectstyles.StyledEmptyState, {
            className: _Selecttokens.classes.emptyStateWrapper,
            description: emptyStateDescription || 'Ничего не найдено'
        }) : /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, virtual ? /*#__PURE__*/ _react.default.createElement(_ui.VirtualList, {
            items: transformedItems,
            listMaxHeight: listMaxHeight || listHeight,
            onScroll: onScroll
        }) : transformedItems.map(function(item, index) {
            return /*#__PURE__*/ _react.default.createElement(_ui.Inner, {
                key: "".concat(index, "/0"),
                item: item,
                currentLevel: 0,
                path: path,
                dispatchPath: dispatchPath,
                index: index,
                listWidth: listWidth,
                portal: listWrapperRef,
                shift: shift,
                flip: flip
            });
        })), afterList))))));
    });
};
var selectConfig = {
    name: 'Select',
    tag: 'div',
    layout: selectRoot,
    base: _Selectstyles.base,
    variations: {},
    defaults: {
        view: 'default',
        size: 'm',
        labelPlacement: 'outer',
        chipView: 'default'
    }
};
