"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _icon = _interopRequireDefault(require("../icon"));
var _colors = require("../../variables/colors");
var _style = _interopRequireDefault(require("./style.css"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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; }
const ICON_COLOR = _colors.COLORS.cm_primary_blue;
const BACKGROUND_COLOR = _colors.COLORS.white;
const CHECK_ICON_NAME_MAP = {
  single: 'circle-check',
  multi: 'square-check'
};
const getButtonContent = (faIcon, options = {}) => {
  const {
    selectionMode = 'single',
    isSelected = false,
    iconColor = ICON_COLOR
  } = options;
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.contentWrapper
  }, isSelected ?
  /*#__PURE__*/
  /* checkbox icon */
  _react.default.createElement("div", {
    className: _style.default.checkIcon
  }, /*#__PURE__*/_react.default.createElement(_icon.default, {
    iconName: CHECK_ICON_NAME_MAP[selectionMode],
    iconColor: iconColor,
    backgroundColor: BACKGROUND_COLOR,
    size: {
      faSize: 16,
      wrapperSize: 16
    }
  })) : null,
  /*#__PURE__*/
  /* selection tick (L18) / icon */
  _react.default.createElement("div", {
    className: _style.default.iconWrapper
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.icon
  }, /*#__PURE__*/_react.default.createElement(_icon.default, {
    iconName: faIcon,
    iconColor: isSelected ? iconColor : '',
    size: {
      faSize: 32,
      wrapperSize: 32
    }
  })), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.iconText
  }, faIcon)));
};
const SelectIcon = props => {
  const {
    faIcon,
    'data-name': dataName,
    'aria-label': ariaLabel,
    onClick,
    options = {}
  } = props;
  const {
    isSelected = false
  } = options;
  const contentView = getButtonContent(faIcon, options);
  const styleButton = (0, _classnames.default)(_style.default.defaultStyle, isSelected && _style.default.selected);
  const handleOnClick = (0, _react.useCallback)(() => onClick(), [onClick]);
  const IconButton = (0, _react.useCallback)(() => /*#__PURE__*/_react.default.createElement("button", {
    type: "button",
    "aria-label": ariaLabel,
    "data-name": dataName,
    "data-testid": `button-${dataName}`,
    className: styleButton,
    onClick: handleOnClick
  }, contentView), [ariaLabel, contentView, dataName, handleOnClick, styleButton]);
  return /*#__PURE__*/_react.default.createElement(IconButton, null);
};
SelectIcon.propTypes = process.env.NODE_ENV !== "production" ? {
  'aria-label': _propTypes.default.string,
  'data-name': _propTypes.default.string,
  faIcon: _propTypes.default.string,
  onClick: _propTypes.default.func,
  options: _propTypes.default.shape({
    selectionMode: _propTypes.default.oneOf(['single', 'multi']),
    isSelected: _propTypes.default.bool,
    iconColor: _propTypes.default.string
  })
} : {};
var _default = exports.default = SelectIcon;
//# sourceMappingURL=index.js.map