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 _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 ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
function _object_without_properties(source, excluded) {
    if (source == null) return {};
    var target = _object_without_properties_loose(source, excluded);
    var key, i;
    if (Object.getOwnPropertySymbols) {
        var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
        for(i = 0; i < sourceSymbolKeys.length; i++){
            key = sourceSymbolKeys[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 = {};
    var sourceKeys = Object.keys(source);
    var key, i;
    for(i = 0; i < sourceKeys.length; i++){
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) continue;
        target[key] = source[key];
    }
    return target;
}
import React, { forwardRef } from 'react';
import { textFieldConfig, component, mergeConfig, createConditionalComponent } from '@salutejs/plasma-new-hope/styled-components';
import { config } from './TextField.config';
import { config as clearConfig } from './TextField.clear.config';
var mergedConfigDefault = mergeConfig(textFieldConfig, config);
export var TextFieldDefault = component(mergedConfigDefault);
var mergedConfigClear = mergeConfig(textFieldConfig, clearConfig);
export var TextFieldClear = component(mergedConfigClear);
export var TextFieldComponent = createConditionalComponent(TextFieldDefault, [
    {
        conditions: {
            prop: 'appearance',
            value: 'clear'
        },
        component: TextFieldClear
    }
]);
var statusToView = {
    success: 'positive',
    warning: 'warning',
    error: 'negative'
};
var animatedHintToLabelPlacement = {
    placeholder: 'outer',
    label: 'inner'
};
/**
 * Поле ввода текста.
 */ export var TextField = /*#__PURE__*/ forwardRef(function(props, ref) {
    var status = props.status, label = props.label, keepPlaceholder = props.keepPlaceholder, placeholder = props.placeholder, animatedHint = props.animatedHint, helperText = props.helperText, hintText = props.hintText, enumerationType = props.enumerationType, chips = props.chips, chipView = props.chipView, chipValidator = props.chipValidator, onSearch = props.onSearch, onChangeChips = props.onChangeChips, chipType = props.chipType, _props_size = props.size, size = _props_size === void 0 ? 'l' : _props_size, rest = _object_without_properties(props, [
        "status",
        "label",
        "keepPlaceholder",
        "placeholder",
        "animatedHint",
        "helperText",
        "hintText",
        "enumerationType",
        "chips",
        "chipView",
        "chipValidator",
        "onSearch",
        "onChangeChips",
        "chipType",
        "size"
    ]);
    /** TODO: #1064 Remove In plasma-2.0 */ /* eslint-disable no-underscore-dangle */ var _view = status ? statusToView[status] : 'default';
    var _labelPlacement = animatedHint ? animatedHintToLabelPlacement[animatedHint] : 'outer';
    var _label = label ? String(label) : undefined;
    if (size !== 'l' && _labelPlacement === 'inner' && !keepPlaceholder) {
        _label = undefined;
        _labelPlacement = 'outer';
    }
    if (size === 'l' && animatedHint === 'placeholder' && !label) {
        _label = placeholder;
        _labelPlacement = 'inner';
    }
    var labelProps = {
        label: _label,
        labelPlacement: _labelPlacement,
        keepPlaceholder: keepPlaceholder
    };
    if (enumerationType === 'chip') {
        return /*#__PURE__*/ React.createElement(TextFieldComponent, _object_spread_props(_object_spread({}, rest, labelProps), {
            view: _view,
            size: size,
            placeholder: placeholder,
            leftHelper: helperText,
            ref: ref,
            enumerationType: "chip",
            chips: chips,
            chipView: chipView,
            chipValidator: chipValidator,
            hintText: String(hintText || ''),
            onChangeChips: onChangeChips,
            chipType: chipType
        }));
    }
    return /*#__PURE__*/ React.createElement(TextFieldComponent, _object_spread_props(_object_spread({}, rest, labelProps), {
        view: _view,
        label: _label,
        size: size,
        placeholder: placeholder,
        leftHelper: helperText,
        ref: ref,
        enumerationType: "plain",
        hintText: String(hintText || ''),
        onSearch: onSearch
    }));
});
