"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 _styles = require("@material-ui/core/styles");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

(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(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

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) {
  var _MuiFormControlLab;

  return {
    container: {
      display: "flex",
      flexDirection: "column"
    },
    checkBoxContainer: {
      display: "flex",
      flexDirection: "row",
      flexWrap: "wrap",
      "& .MuiFormControlLabel-root": (_MuiFormControlLab = {}, _defineProperty(_MuiFormControlLab, theme.breakpoints.up("xs"), {}), _defineProperty(_MuiFormControlLab, theme.breakpoints.up("sm"), {}), _defineProperty(_MuiFormControlLab, theme.breakpoints.up("md"), {
        width: "45%"
      }), _defineProperty(_MuiFormControlLab, theme.breakpoints.up("lg"), {
        width: "30%"
      }), _defineProperty(_MuiFormControlLab, theme.breakpoints.up("xl"), {
        width: "20%"
      }), _defineProperty(_MuiFormControlLab, "& + .MuiFormControlLabel-root", {
        marginTop: theme.spacing(1)
      }), _MuiFormControlLab)
    },
    errorText: {
      marginTop: theme.spacing(0.5),
      color: theme.palette.error.main,
      fontSize: theme.typography.fieldLabelSize,
      float: "left"
    }
  };
});

var CheckboxGroup = function CheckboxGroup(_ref) {
  var _checkboxGroupProps$g;

  var checkboxGroupProps = _ref.checkboxGroupProps;
  var classes = useStyles();

  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 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
  }, 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(_Checkbox.default, {
      key: index,
      checkboxProps: checkboxProps
    });
  })), 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 = _default2;
exports.default = _default3;
;

(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);
})();