"use strict";

exports.__esModule = true;
exports.default = void 0;
var _getOr2 = _interopRequireDefault(require("lodash/fp/getOr"));
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 _provider = _interopRequireWildcard(require("../provider"));
var _inputPreview = _interopRequireDefault(require("./input-preview"));
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 InputHtml = (props, legacyContext) => {
  const {
    value = '',
    onChange = _noop2.default
  } = props;
  const [text, setText] = (0, _react.useState)(value);
  const [preview, setPreview] = (0, _react.useState)(true);
  const handleChange = (0, _react.useCallback)(e => {
    const _value = e.target.value;
    setText(_value);
    onChange(_value);
  }, [onChange]);
  const handlePreview = (0, _react.useCallback)(e => {
    e.preventDefault();
    setPreview(!preview);
  }, [preview, setPreview]);
  const skin = (0, _provider.GetSkinFromContext)(legacyContext);
  const mediumColor = (0, _getOr2.default)('#999999', 'common.medium', skin);
  const {
    title,
    placeholder,
    error,
    description,
    disabled
  } = props;
  const className = error ? _style.default.error : _style.default.defaultStyle;
  const iconContent = !preview ? /*#__PURE__*/_react.default.createElement(_novaIcons.NovaLineBusinessCircleView, {
    style: {
      color: mediumColor
    },
    height: 16
  }) : /*#__PURE__*/_react.default.createElement(_novaIcons.NovaLineContentEditionPencil2, {
    style: {
      color: mediumColor
    },
    height: 16
  });
  return /*#__PURE__*/_react.default.createElement("div", {
    className: className
  }, /*#__PURE__*/_react.default.createElement("label", null, /*#__PURE__*/_react.default.createElement("span", {
    className: _style.default.title
  }, `${title} `), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.contentWrapper
  }, /*#__PURE__*/_react.default.createElement(_inputPreview.default, {
    title: title,
    text: text,
    placeholder: placeholder,
    onChange: handleChange,
    disabled: disabled,
    preview: preview,
    className: _style.default.input
  })), /*#__PURE__*/_react.default.createElement("span", {
    "data-testid": preview ? 'pencil-icon' : 'preview-icon',
    className: _style.default.toggle,
    onClick: handlePreview
  }, iconContent)), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.description
  }, description));
};
InputHtml.propTypes = process.env.NODE_ENV !== "production" ? {
  title: _propTypes.default.string,
  placeholder: _propTypes.default.string,
  disabled: _propTypes.default.bool,
  value: _propTypes.default.string,
  error: _propTypes.default.string,
  onChange: _propTypes.default.func,
  description: _propTypes.default.string
} : {};
InputHtml.contextTypes = {
  skin: _provider.default.childContextTypes.skin
};
var _default = exports.default = InputHtml;
//# sourceMappingURL=index.js.map