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 _iterable_to_array(iter) {
    if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
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 _to_array(arr) {
    return _array_with_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_rest();
}
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);
}
import React, { forwardRef, useEffect, useRef, useState } from "react";
import { css } from "styled-components";
import { cx, safeUseId } from "../../utils";
import { useOutsideClick, useForkRef } from "../../hooks";
import { base as sizeCSS } from "./variations/_size/base";
import { base as viewCSS } from "./variations/_view/base";
import { base as disabledCSS } from "./variations/_disabled/base";
import { base as readOnlyCSS } from "./variations/_read-only/base";
import { base as labelPlacementCSS } from "./variations/_label-placement/base";
import { base as hintViewCSS } from "./variations/_hint-view/base";
import { base as hintSizeCSS } from "./variations/_hint-size/base";
import { base as chipViewCSS } from "./variations/_chip-view/base";
import { Input, InputContainer, LeftHelper, Label, InputWrapper, InputLabelWrapper, StyledContentLeft, StyledContentRight, StyledChips, StyledTextBefore, StyledTextAfter, StyledIndicator, StyledOptionalText, InputPlaceholder, OuterLabelWrapper, TitleCaption, StyledHintWrapper, StyledIndicatorWrapper, StyledContentRightWrapper, InputPlaceholderValue } from "./TextField.styles";
import { classes } from "./TextField.tokens";
import { TextFieldChip, TextFieldChipNew } from "./ui";
import { useKeyNavigation } from "./hooks";
import { HintComponent } from "./ui/Hint/Hint";
import { getInputWidth } from "./getInputWidth";
export var base = css([
    "display:block;"
]);
var HINT_DEFAULT_OFFSET = [
    0,
    0
];
export var textFieldRoot = function textFieldRoot(Root) {
    return /*#__PURE__*/ forwardRef(function(_0, _1) {
        var _ref = [
            _0,
            _1
        ], _ref1 = _to_array(_ref), _ref2 = _ref1[0], _rest = _ref1.slice(1), id = _ref2.id, className = _ref2.className, style = _ref2.style, // layout
        contentLeft = _ref2.contentLeft, contentRight = _ref2.contentRight, label = _ref2.label, labelPlacement = _ref2.labelPlacement, keepPlaceholder = _ref2.keepPlaceholder, textBefore = _ref2.textBefore, textAfter = _ref2.textAfter, placeholder = _ref2.placeholder, leftHelper = _ref2.leftHelper, _ref_enumerationType = _ref2.enumerationType, enumerationType = _ref_enumerationType === void 0 ? 'plain' : _ref_enumerationType, _ref_requiredPlacement = _ref2.requiredPlacement, requiredPlacement = _ref_requiredPlacement === void 0 ? 'right' : _ref_requiredPlacement, _ref_hasRequiredIndicator = _ref2.hasRequiredIndicator, hasRequiredIndicator = _ref_hasRequiredIndicator === void 0 ? false : _ref_hasRequiredIndicator, titleCaption = _ref2.titleCaption, _ref_chipView = _ref2.chipView, chipView = _ref_chipView === void 0 ? 'default' : _ref_chipView, chipValidator = _ref2.chipValidator, _ref_hintTrigger = _ref2.// hint
        hintTrigger, hintTrigger = _ref_hintTrigger === void 0 ? 'hover' : _ref_hintTrigger, hintText = _ref2.hintText, _ref_hintView = _ref2.hintView, hintView = _ref_hintView === void 0 ? 'default' : _ref_hintView, _ref_hintSize = _ref2.hintSize, hintSize = _ref_hintSize === void 0 ? 'm' : _ref_hintSize, hintTargetIcon = _ref2.hintTargetIcon, _ref_hintTargetPlacement = _ref2.hintTargetPlacement, hintTargetPlacement = _ref_hintTargetPlacement === void 0 ? 'outer' : _ref_hintTargetPlacement, _ref_hintPlacement = _ref2.hintPlacement, hintPlacement = _ref_hintPlacement === void 0 ? 'auto' : _ref_hintPlacement, hintHasArrow = _ref2.hintHasArrow, _ref_hintOffset = _ref2.hintOffset, hintOffset = _ref_hintOffset === void 0 ? HINT_DEFAULT_OFFSET : _ref_hintOffset, hintWidth = _ref2.hintWidth, hintContentLeft = _ref2.hintContentLeft, // variations
        appearance = _ref2.appearance, view = _ref2.view, size = _ref2.size, _ref_readOnly = _ref2.readOnly, readOnly = _ref_readOnly === void 0 ? false : _ref_readOnly, _ref_disabled = _ref2.disabled, disabled = _ref_disabled === void 0 ? false : _ref_disabled, _ref_required = _ref2.required, required = _ref_required === void 0 ? false : _ref_required, _ref_clear = _ref2.clear, clear = _ref_clear === void 0 ? false : _ref_clear, optional = _ref2.optional, _ref_optionalText = _ref2.optionalText, optionalText = _ref_optionalText === void 0 ? 'optional' : _ref_optionalText, hasDivider = _ref2.hasDivider, // controlled
        outerValue = _ref2.value, values = _ref2.chips, _ref_chipType = _ref2.chipType, chipType = _ref_chipType === void 0 ? 'default' : _ref_chipType, // @ts-ignore
        _chips = _ref2._chips, // @ts-ignore
        _chipClickArea = _ref2._chipClickArea, // @ts-ignore
        _onChipCloseClick = _ref2._onChipCloseClick, // events
        onChange = _ref2.onChange, onChangeChips = _ref2.onChangeChips, onSearch = _ref2.onSearch, onKeyDown = _ref2.onKeyDown, onFocus = _ref2.onFocus, onBlur = _ref2.onBlur, onPaste = _ref2.onPaste, // Пропсы для внутреннего использования, не отдается наружу.
        // @ts-ignore
        _onEnterDisabled = _ref2._onEnterDisabled, // @ts-ignore
        _forceChipManipulationWithReadonly = _ref2._forceChipManipulationWithReadonly, _ref__interaction_disabled = _ref2./** Внутреннее свойство _interaction_disabled нужно для компонента Select,
                 * в режиме textfield-like, чтобы запретить взаимодействие с компонентом. */ // @ts-ignore
        _interaction_disabled, _interaction_disabled = _ref__interaction_disabled === void 0 ? false : _ref__interaction_disabled, rest = _object_without_properties(_ref2, [
            "id",
            "className",
            "style",
            "contentLeft",
            "contentRight",
            "label",
            "labelPlacement",
            "keepPlaceholder",
            "textBefore",
            "textAfter",
            "placeholder",
            "leftHelper",
            "enumerationType",
            "requiredPlacement",
            "hasRequiredIndicator",
            "titleCaption",
            "chipView",
            "chipValidator",
            "hintTrigger",
            "hintText",
            "hintView",
            "hintSize",
            "hintTargetIcon",
            "hintTargetPlacement",
            "hintPlacement",
            "hintHasArrow",
            "hintOffset",
            "hintWidth",
            "hintContentLeft",
            "appearance",
            "view",
            "size",
            "readOnly",
            "disabled",
            "required",
            "clear",
            "optional",
            "optionalText",
            "hasDivider",
            "value",
            "chips",
            "chipType",
            "_chips",
            "_chipClickArea",
            "_onChipCloseClick",
            "onChange",
            "onChangeChips",
            "onSearch",
            "onKeyDown",
            "onFocus",
            "onBlur",
            "onPaste",
            "_onEnterDisabled",
            "_forceChipManipulationWithReadonly",
            "_interaction_disabled"
        ]), _rest1 = _sliced_to_array(_rest, 1), ref = _rest1[0];
        var _inputRef_current, _inputRef_current1;
        var contentRef = useRef(null);
        var inputContainerRef = useRef(null);
        var inputRef = useRef(null);
        var inputForkRef = useForkRef(inputRef, ref);
        var chipsRefs = useRef([]);
        var hintRef = useRef(null);
        var controlledRefs = {
            contentRef: contentRef,
            inputRef: inputRef,
            chipsRefs: chipsRefs
        };
        var _useState = _sliced_to_array(useState(Boolean(outerValue) || Boolean(inputRef === null || inputRef === void 0 ? void 0 : (_inputRef_current = inputRef.current) === null || _inputRef_current === void 0 ? void 0 : _inputRef_current.value) || Boolean(rest === null || rest === void 0 ? void 0 : rest.defaultValue)), 2), hasValue = _useState[0], setHasValue = _useState[1];
        var _useState1 = _sliced_to_array(useState(false), 2), hasFocus = _useState1[0], setHasFocus = _useState1[1];
        var _useState2 = _sliced_to_array(useState([]), 2), chips = _useState2[0], setChips = _useState2[1];
        var _useState3 = _sliced_to_array(useState(false), 2), isHintVisible = _useState3[0], setIsHintVisible = _useState3[1];
        var uniqId = safeUseId();
        var innerId = id || uniqId;
        var labelId = safeUseId();
        var helperTextId = safeUseId();
        var isChipEnumeration = enumerationType === 'chip';
        var isChipsVisible = isChipEnumeration && Boolean((chips === null || chips === void 0 ? void 0 : chips.length) || (_chips === null || _chips === void 0 ? void 0 : _chips.length));
        var withHasChips = isChipsVisible ? classes.hasChips : undefined;
        var hasLabelValue = Boolean(label);
        var hasInnerLabel = size !== 'xs' && labelPlacement === 'inner' && !isChipsVisible && hasLabelValue;
        var hasOuterLabel = labelPlacement === 'outer' && hasLabelValue;
        var innerKeepPlaceholder = keepPlaceholder && labelPlacement === 'inner';
        var hasPlaceholder = Boolean(placeholder) && (innerKeepPlaceholder || !hasInnerLabel);
        var hasTextAfter = Boolean(textAfter);
        var hasTextBefore = textBefore && !isChipEnumeration;
        if (labelPlacement === 'inner') {
            if (!hasValue && !hasPlaceholder && !hasFocus) {
                hasTextAfter = false;
                hasTextBefore = false;
            }
        }
        var hasPlaceholderPadding = hasInnerLabel && keepPlaceholder && size !== 'xs';
        var innerLabelValue = hasInnerLabel || hasOuterLabel ? label : undefined;
        var innerLabelPlacementValue = labelPlacement === 'inner' && !hasInnerLabel ? undefined : labelPlacement;
        var innerPlaceholderValue = hasPlaceholder ? placeholder : undefined;
        var placeholderShown = Boolean(innerPlaceholderValue) && !hasValue;
        var clearClass = clear || appearance === 'clear' ? classes.clear : undefined;
        var hasDividerClass = hasDivider ? classes.hasDivider : undefined;
        var hasInnerHintClass = hintText && hintTargetPlacement === 'outer' ? classes.hasHint : undefined;
        var hasHintClass = hintText ? classes.hasHint : undefined;
        var requiredPlacementClass = requiredPlacement === 'right' ? classes.requiredAlignRight : undefined;
        var labelPlacementClass = innerLabelPlacementValue ? classes["".concat(innerLabelPlacementValue, "LabelPlacement")] : undefined;
        var hasValueClass = hasValue ? classes.hasValue : undefined;
        var keepPlaceholderClass = hasPlaceholder && placeholderShown && classes.keepPlaceholder;
        var wrapperWithoutLeftContent = !contentLeft && isChipsVisible && chipType === 'default' ? classes.hasEmptyContentLeft : undefined;
        var wrapperWithoutRightContent = !contentRight && isChipsVisible && chipType === 'default' ? classes.hasEmptyContentRight : undefined;
        var contentRightCompensationMargin = !hasOuterLabel && hintText && hintTargetPlacement === 'inner' ? classes.contentRightCompensationMargin : undefined;
        useOutsideClick(function() {
            setIsHintVisible(false);
        }, [
            hintRef
        ]);
        var hintInnerRef = useRef(null);
        var hintForkRef = useForkRef(hintRef, hintInnerRef);
        var handleInput = function handleInput(event) {
            var value = event.target.value;
            setHasValue(Boolean(value));
        };
        var handleFocus = function handleFocus(event) {
            setHasFocus(true);
            onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
        };
        var handleBlur = function handleBlur(event) {
            setHasFocus(false);
            onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
        };
        var handleHintShow = function handleHintShow() {
            return setIsHintVisible(true);
        };
        var handleHintHide = function handleHintHide() {
            return setIsHintVisible(false);
        };
        var handleHintClick = function handleHintClick(event) {
            var _hintInnerRef_current;
            if (!hintText || hintTrigger !== 'click') {
                return;
            }
            event.stopPropagation();
            var targetIsPopover = event.target === hintInnerRef.current;
            var rootHasTarget = (_hintInnerRef_current = hintInnerRef.current) === null || _hintInnerRef_current === void 0 ? void 0 : _hintInnerRef_current.contains(event.target);
            if (!targetIsPopover && !rootHasTarget) {
                setIsHintVisible(true);
            }
        };
        var handleChange = function handleChange(event) {
            if (disabled || readOnly || _interaction_disabled) {
                return;
            }
            var _event_target = event.target, maxLength = _event_target.maxLength, value = _event_target.value;
            if (maxLength !== -1 && value.length > maxLength) {
                return;
            }
            if (onChange) {
                onChange(event);
            }
            if (hasTextAfter) {
                var textWidth = getInputWidth(event.currentTarget, inputContainerRef.current);
                event.currentTarget.style.width = "".concat(textWidth, "px");
            }
        };
        var handlePaste = function handlePaste(event) {
            if (disabled || readOnly || _interaction_disabled) {
                return;
            }
            if (onPaste) {
                onPaste(event);
            }
            if (hasTextAfter) {
                setTimeout(function() {
                    if (!inputRef.current) {
                        return;
                    }
                    var textWidth = getInputWidth(inputRef.current, inputContainerRef.current);
                    inputRef.current.style.width = "".concat(textWidth, "px");
                });
            }
        };
        var updateChips = function updateChips(newChips, newValues) {
            setChips(newChips);
            onChangeChips === null || onChangeChips === void 0 ? void 0 : onChangeChips(newValues);
        };
        var _useKeyNavigation = useKeyNavigation({
            controlledRefs: controlledRefs,
            disabled: disabled,
            readOnly: readOnly,
            chips: chips,
            newCustomChips: _chips,
            enumerationType: enumerationType,
            updateChips: updateChips,
            onSearch: onSearch,
            onChange: onChange,
            onEnterDisabled: _onEnterDisabled,
            onChipCloseClick: _onChipCloseClick,
            _interaction_disabled: _interaction_disabled
        }), handleInputKeydown = _useKeyNavigation.handleInputKeydown, handleChipKeyDown = _useKeyNavigation.handleChipKeyDown, onChipClear = _useKeyNavigation.onChipClear, handleContentKeyDown = _useKeyNavigation.handleContentKeyDown;
        var onChipClick = function onChipClick(event) {
            return event.stopPropagation();
        };
        var handleInputFocus = function handleInputFocus() {
            if (readOnly || disabled || !(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) || _interaction_disabled) {
                return;
            }
            inputRef.current.scrollTo({
                top: 0,
                left: inputRef.current.offsetLeft,
                behavior: 'smooth'
            });
            inputRef.current.focus();
        };
        var getRef = function getRef(element, index) {
            if (element && (chipsRefs === null || chipsRefs === void 0 ? void 0 : chipsRefs.current)) {
                chipsRefs.current[index] = element;
            }
        };
        var handleOnKeyDown = function handleOnKeyDown(event) {
            handleInputKeydown(event);
            if (onKeyDown) {
                onKeyDown(event);
            }
        };
        useEffect(function() {
            if (hasTextAfter && inputRef.current) {
                var textWidth = getInputWidth(inputRef.current, inputContainerRef.current);
                inputRef.current.style.width = "".concat(textWidth, "px");
            } else {
                var _inputRef_current;
                (_inputRef_current = inputRef.current) === null || _inputRef_current === void 0 ? void 0 : _inputRef_current.style.removeProperty('width');
            }
        }, [
            hasTextAfter,
            outerValue
        ]);
        useEffect(function() {
            if (!isChipEnumeration && !(values === null || values === void 0 ? void 0 : values.length)) {
                return;
            }
            var newChips = (values === null || values === void 0 ? void 0 : values.map(function(value, index) {
                return {
                    id: "".concat(index, "_").concat(value),
                    text: value
                };
            })) || [];
            setChips(newChips);
        }, [
            isChipEnumeration,
            values
        ]);
        useEffect(function() {
            setHasValue(Boolean(rest === null || rest === void 0 ? void 0 : rest.defaultValue));
        }, [
            rest.defaultValue
        ]);
        useEffect(function() {
            var _inputRef_current;
            setHasValue(Boolean(outerValue) || Boolean(inputRef === null || inputRef === void 0 ? void 0 : (_inputRef_current = inputRef.current) === null || _inputRef_current === void 0 ? void 0 : _inputRef_current.value));
        }, [
            outerValue,
            inputRef === null || inputRef === void 0 ? void 0 : (_inputRef_current1 = inputRef.current) === null || _inputRef_current1 === void 0 ? void 0 : _inputRef_current1.value
        ]);
        var innerOptional = Boolean(required ? false : optional);
        var hasPlaceholderOptional = innerOptional && !innerLabelValue && !hasOuterLabel;
        var optionalTextNode = innerOptional ? /*#__PURE__*/ React.createElement(StyledOptionalText, null, Boolean(hasPlaceholderOptional ? innerPlaceholderValue : innerLabelValue) && '\xa0', optionalText) : null;
        var classTextEllipsis = // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-ignore
        // eslint-disable-next-line no-underscore-dangle
        !rest._textEllipsisDisable && !textAfter ? classes.inputTextEllipsis : undefined;
        return /*#__PURE__*/ React.createElement(Root, _object_spread({
            view: view,
            size: size,
            disabled: disabled,
            readOnly: !disabled && readOnly,
            labelPlacement: innerLabelPlacementValue,
            onClick: handleInputFocus,
            "data-root": true,
            className: cx(labelPlacementClass, clearClass, hasDividerClass, hasInnerHintClass, classes.textFieldGroupItem, className),
            style: style
        }, hintText && {
            hintView: hintView,
            hintSize: hintSize
        }), (hasOuterLabel || titleCaption) && /*#__PURE__*/ React.createElement(OuterLabelWrapper, {
            isInnerLabel: labelPlacement === 'inner'
        }, hasOuterLabel && /*#__PURE__*/ React.createElement(StyledIndicatorWrapper, null, /*#__PURE__*/ React.createElement(Label, {
            id: labelId,
            htmlFor: id
        }, innerLabelValue), hintText && /*#__PURE__*/ React.createElement(StyledHintWrapper, null, /*#__PURE__*/ React.createElement(HintComponent, {
            ref: hintForkRef,
            hintText: hintText,
            hintTrigger: hintTrigger,
            isHintVisible: isHintVisible,
            hintTargetIcon: hintTargetIcon,
            hintPlacement: hintPlacement,
            hintHasArrow: hintHasArrow,
            hintOffset: hintOffset,
            hintWidth: hintWidth,
            hintContentLeft: hintContentLeft,
            handleHintShow: handleHintShow,
            handleHintHide: handleHintHide,
            handleHintClick: handleHintClick
        })), required && hasRequiredIndicator && /*#__PURE__*/ React.createElement(StyledIndicator, {
            className: cx(classes.outerLabelPlacement, requiredPlacementClass, hasHintClass)
        }), optionalTextNode), titleCaption && /*#__PURE__*/ React.createElement(TitleCaption, {
            "data-root": true
        }, titleCaption)), /*#__PURE__*/ React.createElement(InputWrapper, {
            // Ref для внутреннего использования. Не отдается наружу.
            ref: rest.inputWrapperRef,
            className: cx(withHasChips, wrapperWithoutLeftContent, wrapperWithoutRightContent, classes.inputWrapper)
        }, !hasOuterLabel && /*#__PURE__*/ React.createElement(React.Fragment, null, required && hasRequiredIndicator && /*#__PURE__*/ React.createElement(StyledIndicator, {
            className: cx(classes.innerLabelPlacement, requiredPlacementClass)
        }), hintText && hintTargetPlacement === 'outer' && /*#__PURE__*/ React.createElement(StyledHintWrapper, {
            className: classes.innerLabelPlacement
        }, /*#__PURE__*/ React.createElement(HintComponent, {
            ref: hintForkRef,
            hintText: hintText,
            hintTrigger: hintTrigger,
            isHintVisible: isHintVisible,
            hintTargetIcon: hintTargetIcon,
            hintPlacement: hintPlacement,
            hintHasArrow: hintHasArrow,
            hintOffset: hintOffset,
            hintWidth: hintWidth,
            hintContentLeft: hintContentLeft,
            size: size,
            handleHintShow: handleHintShow,
            handleHintHide: handleHintHide,
            handleHintClick: handleHintClick,
            isInnerLabel: true
        }))), contentLeft && /*#__PURE__*/ React.createElement(StyledContentLeft, {
            "data-root": true
        }, contentLeft), /*#__PURE__*/ React.createElement(InputLabelWrapper, {
            tabIndex: -1,
            ref: contentRef,
            onKeyDown: handleContentKeyDown,
            className: cx(withHasChips, classes.inputScrollableWrapper)
        }, Boolean(textBefore && isChipEnumeration) && /*#__PURE__*/ React.createElement(StyledTextBefore, null, textBefore), Boolean(_chips === null || _chips === void 0 ? void 0 : _chips.length) && /*#__PURE__*/ React.createElement(TextFieldChipNew, {
            chips: _chips,
            getRef: getRef,
            handleChipKeyDown: handleChipKeyDown,
            onChipClear: onChipClear,
            onChipCloseClick: _onChipCloseClick,
            chipClickArea: _chipClickArea,
            view: chipView || view,
            readOnly: readOnly,
            chipType: chipType,
            // TODO: #1547
            // @ts-ignore
            _forceChipManipulationWithReadonly: _forceChipManipulationWithReadonly
        }), isChipEnumeration && Boolean(chips === null || chips === void 0 ? void 0 : chips.length) && /*#__PURE__*/ React.createElement(StyledChips, {
            className: classes.chipsWrapper
        }, chips === null || chips === void 0 ? void 0 : chips.map(function(param, index) {
            var chipId = param.id, text = param.text;
            var validationView = chipValidator === null || chipValidator === void 0 ? void 0 : chipValidator(String(text));
            var resView = (validationView === null || validationView === void 0 ? void 0 : validationView.view) || chipView;
            return /*#__PURE__*/ React.createElement(TextFieldChip, {
                id: chipId,
                ref: function ref(element) {
                    return getRef(element, index);
                },
                key: "".concat(chipId, "_").concat(index),
                disabled: disabled,
                readOnly: readOnly,
                value: text,
                text: text,
                onKeyDown: function onKeyDown(event) {
                    return handleChipKeyDown(event, chipId, index);
                },
                onClear: function onClear() {
                    return onChipClear(chipId, index);
                },
                onClick: onChipClick,
                chipType: chipType,
                view: resView,
                rootWrapper: Root,
                // TODO: #1547
                // @ts-ignore
                _forceChipManipulationWithReadonly: _forceChipManipulationWithReadonly
            });
        })), /*#__PURE__*/ React.createElement(InputContainer, {
            ref: inputContainerRef,
            hasDynamicWidth: hasTextAfter
        }, hasTextBefore && /*#__PURE__*/ React.createElement(StyledTextBefore, null, textBefore), /*#__PURE__*/ React.createElement(Input, _object_spread({
            ref: inputForkRef,
            id: innerId,
            value: outerValue,
            required: enumerationType === 'chip' ? chips.length === 0 && required : required,
            "aria-labelledby": labelId,
            "aria-describedby": helperTextId,
            placeholder: innerPlaceholderValue,
            hasFocus: hasFocus,
            className: cx(hasValueClass, keepPlaceholderClass, classTextEllipsis, readOnly && classes.readOnlyInput),
            disabled: disabled,
            readOnly: !disabled && (readOnly || _interaction_disabled),
            onInput: handleInput,
            onChange: handleChange,
            onKeyDown: handleOnKeyDown,
            onFocus: handleFocus,
            onBlur: handleBlur,
            onPaste: handlePaste,
            "data-tour": true
        }, rest)), hasInnerLabel && /*#__PURE__*/ React.createElement(Label, {
            "data-root": true,
            id: labelId,
            htmlFor: innerId
        }, /*#__PURE__*/ React.createElement(InputPlaceholderValue, {
            className: cx(classTextEllipsis)
        }, innerLabelValue), optionalTextNode), placeholderShown && !hasValue && /*#__PURE__*/ React.createElement(InputPlaceholder, {
            hasPadding: hasPlaceholderPadding
        }, hasTextBefore && /*#__PURE__*/ React.createElement(StyledTextBefore, {
            isHidden: true
        }, textBefore), innerPlaceholderValue && /*#__PURE__*/ React.createElement(InputPlaceholderValue, {
            className: cx(classTextEllipsis)
        }, innerPlaceholderValue), hasPlaceholderOptional && optionalTextNode), hasTextAfter && /*#__PURE__*/ React.createElement(StyledTextAfter, null, textAfter))), /*#__PURE__*/ React.createElement(StyledContentRightWrapper, {
            className: cx(contentRightCompensationMargin)
        }, contentRight && /*#__PURE__*/ React.createElement(StyledContentRight, {
            "data-root": true
        }, contentRight), !hasOuterLabel && hintText && hintTargetPlacement === 'inner' && /*#__PURE__*/ React.createElement(HintComponent, {
            ref: hintForkRef,
            hintText: hintText,
            hintTrigger: hintTrigger,
            isHintVisible: isHintVisible,
            hintTargetIcon: hintTargetIcon,
            hintPlacement: hintPlacement,
            hintHasArrow: hintHasArrow,
            hintOffset: hintOffset,
            hintWidth: hintWidth,
            hintContentLeft: hintContentLeft,
            size: size,
            handleHintShow: handleHintShow,
            handleHintHide: handleHintHide,
            handleHintClick: handleHintClick,
            isInnerLabel: true
        }))), leftHelper && /*#__PURE__*/ React.createElement(LeftHelper, {
            "data-root": true,
            id: helperTextId,
            className: hasFocus ? classes.hasFocus : undefined
        }, leftHelper));
    });
};
export var textFieldConfig = {
    name: 'TextField',
    tag: 'div',
    layout: textFieldRoot,
    base: base,
    variations: {
        view: {
            css: viewCSS
        },
        size: {
            css: sizeCSS
        },
        disabled: {
            css: disabledCSS,
            attrs: true
        },
        readOnly: {
            css: readOnlyCSS,
            attrs: true
        },
        labelPlacement: {
            css: labelPlacementCSS
        },
        hintView: {
            css: hintViewCSS
        },
        hintSize: {
            css: hintSizeCSS
        },
        chipView: {
            css: chipViewCSS
        }
    },
    defaults: {
        size: 'm',
        view: 'default'
    }
};
