"use strict";

exports.__esModule = true;
exports.default = void 0;
var _isEmpty2 = _interopRequireDefault(require("lodash/fp/isEmpty"));
var _keys2 = _interopRequireDefault(require("lodash/fp/keys"));
var _isNil2 = _interopRequireDefault(require("lodash/fp/isNil"));
var _noop2 = _interopRequireDefault(require("lodash/fp/noop"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _novaIcons = require("@coorpacademy/nova-icons");
var _classnames = _interopRequireDefault(require("classnames"));
var _getClassState = _interopRequireDefault(require("../../util/get-class-state"));
var _style = _interopRequireDefault(require("./style.css"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const themeStyle = {
  setup: _style.default.setup,
  coorpmanager: _style.default.coorpmanager,
  cockpit: _style.default.cockpit,
  default: _style.default.defaultStyle
};
const InputText = props => {
  const {
    autoFocus = false,
    placeholder = '',
    value,
    type = 'text',
    hint,
    defaultValue,
    onChange = _noop2.default,
    error,
    valid,
    theme = 'default',
    description,
    disabled,
    modified = false,
    title: propsTitle,
    'data-name': dataName = 'input-text',
    'aria-label': ariaLabel = 'Input Text',
    inputColor = false
  } = props;
  const isCMTheme = theme === 'coorpmanager';
  const handleChange = (0, _react.useMemo)(() => e => onChange(e.target.value), [onChange]);
  const mainClass = themeStyle[theme];
  const className = (0, _getClassState.default)(_style.default.defaultStyle, _style.default.modified, _style.default.error, modified, error);
  const descriptionView = description && theme !== 'coorpmanager' ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.description
  }, description) : null;
  const toolTipView = description && theme === 'coorpmanager' ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.infoIconWrapper
  }, /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionCoorpacademyInformationIcon, {
    className: _style.default.infoIcon
  }), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.descriptionLabel
  }, description)) : null;
  const hintView = theme === 'coorpmanager' ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.hint
    // eslint-disable-next-line react/no-danger
    ,
    dangerouslySetInnerHTML: {
      __html: error || hint
    }
  }) : null;
  const errorIconView = isCMTheme && error ? /*#__PURE__*/_react.default.createElement(_novaIcons.NovaSolidStatusClose, {
    className: _style.default.leftIcon
  }) : null;
  const validIconView = isCMTheme && valid ? /*#__PURE__*/_react.default.createElement(_novaIcons.NovaSolidStatusCheckCircle2, {
    className: _style.default.leftIcon
  }) : null;
  return /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)(mainClass, className, disabled && _style.default.disabled, (0, _isNil2.default)(propsTitle) && _style.default.isNoTitle)
  }, /*#__PURE__*/_react.default.createElement("label", null, /*#__PURE__*/_react.default.createElement("span", {
    className: (0, _classnames.default)(_style.default.title, (0, _isEmpty2.default)(value) && _style.default.noValue)
  }, propsTitle, toolTipView), /*#__PURE__*/_react.default.createElement("input", {
    autoFocus: autoFocus,
    type: type,
    name: propsTitle,
    className: _style.default.input,
    placeholder: placeholder,
    defaultValue: defaultValue,
    autoComplete: 'off',
    value: value,
    onInput: handleChange,
    disabled: disabled,
    onChange: _noop2.default,
    "data-name": dataName,
    "aria-label": ariaLabel
  }), inputColor && !error && value ? /*#__PURE__*/_react.default.createElement("span", {
    className: _style.default.preview,
    style: {
      backgroundColor: value
    }
  }) : null, errorIconView, validIconView, hintView), descriptionView);
};
InputText.propTypes = process.env.NODE_ENV !== "production" ? {
  autoFocus: _propTypes.default.bool,
  title: _propTypes.default.string,
  placeholder: _propTypes.default.string,
  defaultValue: _propTypes.default.string,
  theme: _propTypes.default.oneOf((0, _keys2.default)(themeStyle)),
  disabled: _propTypes.default.bool,
  value: _propTypes.default.string,
  hint: _propTypes.default.string,
  error: _propTypes.default.string,
  onChange: _propTypes.default.func,
  description: _propTypes.default.string,
  modified: _propTypes.default.bool,
  type: _propTypes.default.string,
  valid: _propTypes.default.bool,
  'aria-label': _propTypes.default.string,
  'data-name': _propTypes.default.string,
  inputColor: _propTypes.default.bool
} : {};
var _default = exports.default = InputText;
//# sourceMappingURL=index.js.map