"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 _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 }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
const InputSwitch = props => {
  const {
    title,
    name,
    id,
    value,
    disabled,
    onChange = _noop2.default,
    description,
    modified = false,
    theme = 'default',
    titlePosition = 'left',
    details = '',
    requiredSelection = false,
    'data-name': dataName,
    'aria-labelledby': ariaLabelledBy,
    'aria-label': ariaLabel
  } = props;
  const idSwitch = id || (0, _uniqueId2.default)('input-switch-');
  const isDisabled = disabled ? 'disabled' : '';
  const handleChange = (0, _react.useMemo)(() => e => onChange(e.target.checked), [onChange]);
  const titleView = title ? /*#__PURE__*/_react.default.createElement("span", {
    id: `title-view-${dataName}`,
    className: _style.default.title
  }, `${title} `, ' ') : null;
  const descriptionView = description ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.description
  }, description) : null;
  const getClass = () => {
    switch (theme) {
      case 'coorpmanager':
        return {
          defaultClass: _style.default.coorpmanager,
          modifiedClass: _style.default.coorpmanagerModified
        };
      case 'mooc':
        return {
          defaultClass: _style.default.partielUncheck,
          modifiedClass: _style.default.coorpmanagerModified
        };
      default:
        return {
          defaultClass: _style.default.defaultStyle,
          modifiedClass: _style.default.modified
        };
    }
  };
  const {
    defaultClass,
    modifiedClass
  } = getClass();
  const className = (0, _getClassState.default)(defaultClass, modifiedClass, null, modified);
  return /*#__PURE__*/_react.default.createElement("div", {
    className: className,
    "data-name": `switch-input-${theme}${dataName}`
  }, titlePosition === 'left' ? titleView : null, /*#__PURE__*/_react.default.createElement("div", {
    className: requiredSelection ? _style.default.requiredSelection : null
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.btnSwitchContainer
  }, /*#__PURE__*/_react.default.createElement("input", _extends({}, ariaLabelledBy ? {
    'aria-labelledby': ariaLabelledBy
  } : {}, title ? {
    'aria-labelledby': `title-view-${dataName}`
  } : {}, ariaLabel && !ariaLabelledBy && !title ? {
    'aria-label': ariaLabel
  } : {}, {
    type: "checkbox",
    id: idSwitch,
    name: name,
    onChange: handleChange,
    checked: value,
    disabled: isDisabled,
    className: _style.default.checkbox,
    "aria-labelledby": ariaLabelledBy
  })), /*#__PURE__*/_react.default.createElement("label", {
    htmlFor: idSwitch,
    "data-name": "input-switch-label",
    tabIndex: 0,
    "aria-label": ariaLabel,
    title: ariaLabel
  }))), /*#__PURE__*/_react.default.createElement("div", {
    className: !details ? _style.default.alignedTextContainer : null
  }, titlePosition === 'right' ? titleView : null, details ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.detailsTxt
  }, details) : null), descriptionView);
};
InputSwitch.propTypes = process.env.NODE_ENV !== "production" ? {
  title: _propTypes.default.string,
  name: _propTypes.default.string,
  id: _propTypes.default.string,
  value: _propTypes.default.bool,
  disabled: _propTypes.default.bool,
  onChange: _propTypes.default.func,
  description: _propTypes.default.string,
  'aria-labelledby': _propTypes.default.string,
  'aria-label': _propTypes.default.string,
  modified: _propTypes.default.bool,
  titlePosition: _propTypes.default.oneOf(['right', 'left']),
  theme: _propTypes.default.oneOf(['default', 'coorpmanager', 'mooc']),
  details: _propTypes.default.string,
  'data-name': _propTypes.default.string,
  requiredSelection: _propTypes.default.bool
} : {};
var _default = exports.default = InputSwitch;
//# sourceMappingURL=index.js.map