"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 TextField () {
        return TextField;
    },
    get TextFieldClear () {
        return TextFieldClear;
    },
    get TextFieldComponent () {
        return TextFieldComponent;
    },
    get TextFieldDefault () {
        return TextFieldDefault;
    }
});
var _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
var _styledcomponents = require("@salutejs/plasma-new-hope/styled-components");
var _TextFieldconfig = require("./TextField.config");
var _TextFieldclearconfig = require("./TextField.clear.config");
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 _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;
}
var mergedConfigDefault = (0, _styledcomponents.mergeConfig)(_styledcomponents.textFieldConfig, _TextFieldconfig.config);
var TextFieldDefault = (0, _styledcomponents.component)(mergedConfigDefault);
var mergedConfigClear = (0, _styledcomponents.mergeConfig)(_styledcomponents.textFieldConfig, _TextFieldclearconfig.config);
var TextFieldClear = (0, _styledcomponents.component)(mergedConfigClear);
var TextFieldComponent = (0, _styledcomponents.createConditionalComponent)(TextFieldDefault, [
    {
        conditions: {
            prop: 'appearance',
            value: 'clear'
        },
        component: TextFieldClear
    }
]);
var statusToView = {
    success: 'positive',
    warning: 'warning',
    error: 'negative'
};
var animatedHintToLabelPlacement = {
    placeholder: 'outer',
    label: 'inner'
};
var TextField = /*#__PURE__*/ (0, _react.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.default.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.default.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
    }));
});
