'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var plasmaNewHope = require('@salutejs/plasma-new-hope');
var TextField_config = require('./TextField.config.js');
var TextField_clear_config = require('./TextField.clear.config.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

var _excluded = ["status", "label", "keepPlaceholder", "placeholder", "animatedHint", "helperText", "hintText", "enumerationType", "chips", "chipView", "chipValidator", "onSearch", "onChangeChips", "chipType", "size"];
var mergedConfigDefault = /*#__PURE__*/plasmaNewHope.mergeConfig(plasmaNewHope.textFieldConfig, TextField_config.config);
var TextFieldDefault = /*#__PURE__*/plasmaNewHope.component(mergedConfigDefault);
var mergedConfigClear = /*#__PURE__*/plasmaNewHope.mergeConfig(plasmaNewHope.textFieldConfig, TextField_clear_config.config);
var TextFieldClear = /*#__PURE__*/plasmaNewHope.component(mergedConfigClear);
var TextFieldComponent = /*#__PURE__*/plasmaNewHope.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__*/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 = _rollupPluginBabelHelpers.objectWithoutProperties(props, _excluded);

  /** 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.default.createElement(TextFieldComponent, _rollupPluginBabelHelpers.extends({}, 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.default.createElement(TextFieldComponent, _rollupPluginBabelHelpers.extends({}, rest, labelProps, {
    view: _view,
    label: _label,
    size: size,
    placeholder: placeholder,
    leftHelper: helperText,
    ref: ref,
    enumerationType: "plain",
    hintText: String(hintText || ''),
    onSearch: onSearch
  }));
});

exports.TextField = TextField;
exports.TextFieldClear = TextFieldClear;
exports.TextFieldComponent = TextFieldComponent;
exports.TextFieldDefault = TextFieldDefault;
//# sourceMappingURL=TextField.js.map
