"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _FormControlLabel = _interopRequireDefault(require("@material-ui/core/FormControlLabel"));
var _CheckboxGroupProps = _interopRequireWildcard(require("./CheckboxGroupProps"));
var _Checkbox = _interopRequireDefault(require("./Checkbox"));
var _CheckboxProps = _interopRequireDefault(require("./CheckboxProps"));
var _TooltippedIcon = _interopRequireDefault(require("../DataDisplay/TooltippedElements/TooltippedIcon"));
var _styles = require("@material-ui/core/styles");
var _classnames = _interopRequireDefault(require("classnames"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(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 () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var useStyles = (0, _styles.makeStyles)(function (theme) {
  return {
    container: {
      display: "flex",
      flexDirection: "column"
    },
    checkBoxContainer: {
      display: "flex",
      flexDirection: function flexDirection(props) {
        return props.row ? "row" : "column";
      },
      flexWrap: "wrap",
      marginLeft: "8px"
    },
    errorText: {
      marginTop: theme.spacing(0.5),
      color: theme.palette.error.main,
      fontSize: theme.typography.fieldLabelSize,
      float: "left"
    },
    warningIcon: {
      width: "1em",
      height: "1em",
      fontSize: 16,
      alignSelf: "center",
      marginRight: theme.spacing(2),
      "& > svg": {
        color: theme.palette.error.main
      }
    },
    checkboxItemWarning: {
      color: theme.palette.error.main
    },
    checkboxItem: function checkboxItem(props) {
      return _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
        display: "flex",
        flex: 1
      }, theme.breakpoints.up("xs"), {}), theme.breakpoints.up("sm"), {}), theme.breakpoints.up("md"), props.row ? {
        width: "45%"
      } : {}), theme.breakpoints.up("lg"), props.row ? {
        width: "30%"
      } : {}), theme.breakpoints.up("xl"), props.row ? {
        width: "20%"
      } : {}), "marginTop", theme.spacing(1));
    }
  };
});
var CheckboxGroup = function CheckboxGroup(_ref2) {
  var _checkboxGroupProps$g, _checkboxGroupProps$g2;
  var checkboxGroupProps = _ref2.checkboxGroupProps;
  if ((0, _CheckboxGroupProps.isCheckboxGroupProps)(checkboxGroupProps) === false) {
    throw new TypeError("checkboxGroupProps property is not of type CheckboxGroupProps");
  }
  var update = checkboxGroupProps == null ? void 0 : checkboxGroupProps.get(_CheckboxGroupProps.default.propNames.update);
  var value = checkboxGroupProps == null ? void 0 : checkboxGroupProps.get(_CheckboxGroupProps.default.propNames.value);
  var label = checkboxGroupProps == null ? void 0 : checkboxGroupProps.get(_CheckboxGroupProps.default.propNames.label);
  var error = checkboxGroupProps == null ? void 0 : checkboxGroupProps.get(_CheckboxGroupProps.default.propNames.error);
  var readOnly = (checkboxGroupProps == null ? void 0 : checkboxGroupProps.get(_CheckboxGroupProps.default.propNames.readOnly)) || false;
  var disabled = (checkboxGroupProps == null ? void 0 : checkboxGroupProps.get(_CheckboxGroupProps.default.propNames.disabled)) || false;
  var options = (_checkboxGroupProps$g = checkboxGroupProps == null ? void 0 : checkboxGroupProps.get(_CheckboxGroupProps.default.propNames.options)) != null ? _checkboxGroupProps$g : [];
  var row = (_checkboxGroupProps$g2 = checkboxGroupProps.get(_CheckboxGroupProps.default.propNames.row)) != null ? _checkboxGroupProps$g2 : true;
  var classes = useStyles({
    row: row
  });
  var handleGroupUpdate = function handleGroupUpdate(checked, value, newValue) {
    var values = value ? value.split("|") : [];
    var position = values.indexOf(newValue);
    if (checked && position === -1) {
      values.push(newValue);
    }
    if (!checked && position !== -1) {
      values.splice(position, 1);
    }
    update(values.join("|"));
  };
  var checkBoxGroup = /*#__PURE__*/_react.default.createElement("div", {
    className: classes.container
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: classes.checkBoxContainer,
    "data-qa": "checkboxgroup-container"
  }, options.map(function (option, index) {
    var _option$label;
    var checkboxProps = new _CheckboxProps.default();
    checkboxProps.set(_CheckboxProps.default.propNames.update, function (checked) {
      return handleGroupUpdate(checked, value, option.value);
    });
    checkboxProps.set(_CheckboxProps.default.propNames.value, value == null ? void 0 : value.split("|").includes(option.value));
    checkboxProps.set(_CheckboxProps.default.propNames.label, (_option$label = option.label) != null ? _option$label : option.value);
    checkboxProps.set(_CheckboxProps.default.propNames.readOnly, readOnly);
    checkboxProps.set(_CheckboxProps.default.propNames.disabled, disabled);
    return /*#__PURE__*/_react.default.createElement("div", {
      key: index,
      className: (0, _classnames.default)(classes.checkboxItem, _defineProperty({}, classes.checkboxItemWarning, !!option.warningMessage))
    }, /*#__PURE__*/_react.default.createElement(_Checkbox.default, {
      checkboxProps: checkboxProps
    }), option.warningMessage && /*#__PURE__*/_react.default.createElement(_TooltippedIcon.default, {
      className: classes.warningIcon,
      titleValue: option.warningMessage,
      id: "warning"
    }));
  })), error && /*#__PURE__*/_react.default.createElement("div", {
    className: classes.errorText
  }, error));
  return label == null ? checkBoxGroup : /*#__PURE__*/_react.default.createElement(_FormControlLabel.default, {
    control: checkBoxGroup,
    label: label
  });
};
__signature__(CheckboxGroup, "useStyles{classes}", function () {
  return [useStyles];
});
__signature__(CheckboxGroup, "useStyles{classes}", function () {
  return [useStyles];
});
var _default = _react.default.memo(CheckboxGroup);
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/CheckboxGroup.js");
  reactHotLoader.register(CheckboxGroup, "CheckboxGroup", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/CheckboxGroup.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/CheckboxGroup.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/CheckboxGroup.js");
  reactHotLoader.register(CheckboxGroup, "CheckboxGroup", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/CheckboxGroup.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/CheckboxGroup.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();