"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 _cssColorFunction = require("css-color-function");
var _provider = _interopRequireWildcard(require("../../../atom/provider"));
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 FreeText = (props, legacyContext) => {
  const skin = (0, _provider.GetSkinFromContext)(legacyContext);
  const {
    placeholder = '',
    value = '',
    onChange = _noop2.default,
    'aria-label': ariaLabel
  } = props;
  const [hovered, setHovered] = (0, _react.useState)(false);
  const handleChange = (0, _react.useCallback)(e => onChange(e.target.value), [onChange]);
  const primarySkinColor = (0, _getOr2.default)('#00B0FF', 'common.primary', skin);
  const handleMouseOver = (0, _react.useCallback)(() => setHovered(true), [setHovered]);
  const handleMouseLeave = (0, _react.useCallback)(() => setHovered(false), [setHovered]);
  const shadowBoxPrimaryColor = (0, _react.useMemo)(() => (0, _cssColorFunction.convert)(`color(${primarySkinColor} a(12%))`), [primarySkinColor]);
  return /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "freeText",
    className: _style.default.wrapper,
    onMouseOver: handleMouseOver,
    onMouseLeave: handleMouseLeave,
    style: {
      ...(value && {
        boxShadow: hovered ? 'none' : `0 4px 16px ${shadowBoxPrimaryColor}`
      })
    }
  }, /*#__PURE__*/_react.default.createElement("input", {
    "data-name": "free-text-input",
    type: "text",
    "aria-label": ariaLabel || value || placeholder,
    title: ariaLabel || value || placeholder,
    className: _style.default.freeText,
    placeholder: placeholder,
    value: value,
    onInput: handleChange,
    onChange: _noop2.default,
    style: {
      boxShadow: `0 4px 16px ${shadowBoxPrimaryColor}`,
      ...(value && {
        boxShadow: `0 4px 16px ${hovered ? (0, _cssColorFunction.convert)(`color(${primarySkinColor} a(20%))`) : shadowBoxPrimaryColor}`
      }),
      color: primarySkinColor
    }
  }));
};
FreeText.contextTypes = {
  skin: _provider.default.childContextTypes.skin
};
FreeText.propTypes = process.env.NODE_ENV !== "production" ? {
  placeholder: _propTypes.default.string,
  value: _propTypes.default.string,
  onChange: _propTypes.default.func,
  'aria-label': _propTypes.default.string
} : {};
var _default = exports.default = FreeText;
//# sourceMappingURL=index.js.map