"use strict";

exports.__esModule = true;
exports.default = void 0;
var _uniqueId2 = _interopRequireDefault(require("lodash/fp/uniqueId"));
var _noop2 = _interopRequireDefault(require("lodash/fp/noop"));
var _keys2 = _interopRequireDefault(require("lodash/fp/keys"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _novaIcons = require("@coorpacademy/nova-icons");
var _getClassState = _interopRequireDefault(require("../../util/get-class-state"));
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 titleStylesClassNames = {
  inherit: _style.default.inherit,
  primary: _style.default.primary,
  secondary: _style.default.secondary,
  tertiary: _style.default.tertiary
};
const InputCheckbox = props => {
  const {
    checked,
    onChange = _noop2.default,
    error,
    disabled,
    required,
    titleStyle = 'primary',
    modified = false,
    theme = 'default',
    title: propsTitle,
    noLabelMargins = false
  } = props;
  const titleStyleClassName = titleStylesClassNames[titleStyle];
  const idCheckbox = (0, _uniqueId2.default)('input-checkbox-');
  const title = `${propsTitle}${required ? '*' : ''}`;
  const handleChange = (0, _react.useCallback)(e => onChange(e.target.checked), [onChange]);
  const modifiedClassName = theme === 'coorpmanager' ? _style.default.coorpManagerModified : _style.default.defaultModified;
  const errorClassName = theme === 'coorpmanager' ? _style.default.coorpManagerError : _style.default.defaultError;
  const defaultContainerClassName = theme === 'coorpmanager' ? _style.default.coorpManager : _style.default.defaultStyle;
  const className = (0, _getClassState.default)(defaultContainerClassName, modifiedClassName, errorClassName, modified, error);
  return /*#__PURE__*/_react.default.createElement("label", {
    className: className,
    htmlFor: idCheckbox,
    "data-name": "checkbox-input-label"
  }, /*#__PURE__*/_react.default.createElement("input", {
    type: "checkbox",
    className: _style.default.checkbox,
    name: title,
    id: idCheckbox,
    checked: checked,
    onChange: handleChange,
    disabled: disabled,
    "data-name": "checkbox-input"
  }), /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "checkbox-label",
    className: (0, _classnames.default)(_style.default.label, noLabelMargins ? _style.default.noLabelMargins : undefined)
  }, /*#__PURE__*/_react.default.createElement(_novaIcons.NovaSolidStatusValidate, {
    className: _style.default.icon
  })), /*#__PURE__*/_react.default.createElement("span", {
    className: titleStyleClassName,
    title: title
  }, title));
};
InputCheckbox.propTypes = process.env.NODE_ENV !== "production" ? {
  title: _propTypes.default.string.isRequired,
  disabled: _propTypes.default.bool,
  required: _propTypes.default.bool,
  checked: _propTypes.default.bool,
  error: _propTypes.default.bool,
  onChange: _propTypes.default.func,
  modified: _propTypes.default.bool,
  noLabelMargins: _propTypes.default.bool,
  theme: _propTypes.default.oneOf(['coorpmanager', 'default']),
  titleStyle: _propTypes.default.oneOf((0, _keys2.default)(titleStylesClassNames))
} : {};
var _default = exports.default = InputCheckbox;
//# sourceMappingURL=index.js.map