"use strict";

exports.__esModule = true;
exports.default = void 0;
var _isEmpty2 = _interopRequireDefault(require("lodash/fp/isEmpty"));
var _keys2 = _interopRequireDefault(require("lodash/fp/keys"));
var _noop2 = _interopRequireDefault(require("lodash/fp/noop"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _novaIcons = require("@coorpacademy/nova-icons");
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 InputTextarea = props => {
  const {
    title: propsTitle,
    name,
    placeholder,
    value,
    hint,
    theme = 'default',
    onChange = _noop2.default,
    error,
    valid,
    description,
    disabled,
    modified = false
  } = props;
  const mainClass = themeStyle[theme];
  const className = (0, _getClassState.default)(_style.default.defaultStyle, _style.default.modified, _style.default.error, modified, error);
  const handleChange = (0, _react.useMemo)(() => e => onChange(e.target.value), [onChange]);
  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 = error ? /*#__PURE__*/_react.default.createElement(_novaIcons.NovaSolidStatusClose, {
    className: _style.default.leftIcon
  }) : null;
  const validIconView = 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)
  }, /*#__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("textarea", {
    name: name,
    value: value,
    placeholder: placeholder,
    onChange: handleChange,
    disabled: disabled,
    "data-testid": name
  }), errorIconView, validIconView, hintView), descriptionView);
};
InputTextarea.propTypes = process.env.NODE_ENV !== "production" ? {
  placeholder: _propTypes.default.string,
  title: _propTypes.default.string,
  name: _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,
  valid: _propTypes.default.bool
} : {};
var _default = exports.default = InputTextarea;
//# sourceMappingURL=index.js.map