"use strict";

exports.__esModule = true;
exports.default = void 0;
var _uniqueId2 = _interopRequireDefault(require("lodash/fp/uniqueId"));
var _noop2 = _interopRequireDefault(require("lodash/fp/noop"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _icon = _interopRequireDefault(require("../icon"));
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 DEFAULT_ICON_STYLE = {
  padding: '0',
  width: '20px',
  height: '20px'
};
const CheckboxWithTitle = props => {
  const {
    title,
    name,
    checked,
    onChange = _noop2.default,
    'data-name': dataName,
    'aria-label': ariaLabel,
    icon = {
      iconName: 'check',
      iconColor: 'white',
      preset: 's'
    },
    customStyle = {}
  } = props;
  const {
    iconName,
    iconColor,
    preset
  } = icon;
  const idCheckbox = (0, _react.useMemo)(() => (0, _uniqueId2.default)('input-checkbox-'), []);
  const handleChange = (0, _react.useMemo)(() => e => onChange(e.target.checked), [onChange]);
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.container,
    style: {
      ...customStyle
    }
  }, /*#__PURE__*/_react.default.createElement("label", {
    htmlFor: idCheckbox
  }, /*#__PURE__*/_react.default.createElement("input", {
    type: "checkbox",
    id: idCheckbox,
    name: name,
    onChange: handleChange,
    checked: checked,
    className: _style.default.checkbox,
    "data-name": dataName,
    "aria-label": ariaLabel
  }), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.label
  }, checked ? /*#__PURE__*/_react.default.createElement(_icon.default, {
    className: _style.default.icon,
    iconName: iconName,
    iconColor: iconColor,
    preset: preset,
    customStyle: DEFAULT_ICON_STYLE
  }) : /*#__PURE__*/_react.default.createElement(_icon.default, {
    className: _style.default.icon,
    iconName: 'square',
    iconColor: 'transparent',
    preset: "s",
    customStyle: DEFAULT_ICON_STYLE
  }))), title ? /*#__PURE__*/_react.default.createElement("span", {
    // eslint-disable-next-line react/no-danger
    dangerouslySetInnerHTML: {
      __html: title
    }
  }) : null);
};
CheckboxWithTitle.propTypes = process.env.NODE_ENV !== "production" ? {
  title: _propTypes.default.string,
  name: _propTypes.default.string,
  checked: _propTypes.default.bool,
  onChange: _propTypes.default.func,
  'aria-label': _propTypes.default.string,
  'data-name': _propTypes.default.string,
  icon: _propTypes.default.shape({
    iconName: _propTypes.default.string,
    iconColor: _propTypes.default.string,
    preset: _propTypes.default.string
  }),
  customStyle: _propTypes.default.objectOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]))
} : {};
var _default = exports.default = CheckboxWithTitle;
//# sourceMappingURL=index.js.map