"use strict";

exports.__esModule = true;
exports.default = void 0;
var _noop2 = _interopRequireDefault(require("lodash/fp/noop"));
var _get2 = _interopRequireDefault(require("lodash/fp/get"));
var _react = _interopRequireWildcard(require("react"));
var _cssColorFunction = require("css-color-function");
var _classnames = _interopRequireDefault(require("classnames"));
var _novaIcons = require("@coorpacademy/nova-icons");
var _link = _interopRequireDefault(require("../link"));
var _provider = _interopRequireDefault(require("../provider"));
var _style = _interopRequireDefault(require("./style.css"));
var _propTypes = _interopRequireDefault(require("./prop-types"));
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 CTA = (props, legacyContext) => {
  const {
    skin
  } = legacyContext;
  const {
    'aria-label': ariaLabel,
    submitValue = 'submit',
    name: ctaName,
    href,
    target,
    disabled = false,
    light = false,
    small = false,
    secondary = false,
    onClick,
    className,
    logout = false,
    rectangular = false,
    fullWidth = false,
    certificationButton = false,
    useButtonTag = false
  } = props;
  const [hovered, setHovered] = (0, _react.useState)(false);
  const handleMouseEnter = (0, _react.useCallback)(() => {
    setHovered(true);
  }, []);
  const handleMouseLeave = (0, _react.useCallback)(() => {
    setHovered(false);
  }, []);
  const getStyle = (0, _react.useCallback)(() => {
    const color = (0, _get2.default)('common.primary', skin);
    const grey = (0, _get2.default)('common.grey', skin);
    if (logout) return;
    if (disabled) {
      return {
        backgroundColor: grey,
        borderColor: grey,
        opacity: '0.3'
      };
    }
    if (hovered) {
      const darkenColor = (0, _cssColorFunction.convert)(`color(${color} blackness(+10%))`);
      return {
        backgroundColor: darkenColor,
        borderColor: darkenColor
      };
    }
    if (secondary) return {
      color,
      borderColor: color
    };
    if (light) return {
      color
    };
    return {
      borderColor: color,
      backgroundColor: color
    };
  }, [disabled, hovered, light, logout, secondary, skin]);
  return /*#__PURE__*/_react.default.createElement(_link.default, {
    href: href,
    onClick: disabled ? _noop2.default : onClick,
    onMouseEnter: handleMouseEnter,
    onMouseLeave: handleMouseLeave,
    target: target,
    className: (0, _classnames.default)(_style.default.button, disabled ? _style.default.disabled : null, small ? _style.default.smallButton : null, light ? _style.default.lightButton : null, secondary ? _style.default.secondaryButton : null, logout ? _style.default.logoutButton : null, rectangular ? _style.default.rectangularButton : null, fullWidth ? _style.default.fullWidth : null, certificationButton ? _style.default.certificationButton : null, className),
    "data-name": ctaName || 'cta',
    style: getStyle(),
    "aria-label": ariaLabel,
    useButtonTag: useButtonTag
  }, logout ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.logoutWrapper,
    "data-name": "cta-logout-label"
  }, /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionCoorpacademyLogout, {
    height: 15,
    width: 15,
    className: _style.default.logoutIcon
  }), submitValue) : submitValue);
};
CTA.propTypes = process.env.NODE_ENV !== "production" ? _propTypes.default : {};
CTA.contextTypes = {
  skin: _provider.default.childContextTypes.skin
};
var _default = exports.default = CTA;
//# sourceMappingURL=index.js.map