"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _RadioGroup = _interopRequireDefault(require("@material-ui/core/RadioGroup"));
var _Radio = _interopRequireDefault(require("@material-ui/core/Radio"));
var _FormControlLabel = _interopRequireDefault(require("@material-ui/core/FormControlLabel"));
var _FormControl = _interopRequireDefault(require("@material-ui/core/FormControl"));
var _FormLabel = _interopRequireDefault(require("@material-ui/core/FormLabel"));
var _styles = require("@material-ui/core/styles");
var _RadioProps = _interopRequireWildcard(require("./RadioProps.js"));
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);
})();
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 {
    /* Radio Button */
    radioIcon: {
      border: "1px solid",
      borderColor: theme.palette.grey.borders,
      backgroundColor: theme.palette.background.paper,
      width: theme.spacing(1.6),
      height: theme.spacing(1.6),
      borderRadius: "50%",
      ".MuiRadio-root:focus &, .MuiRadio-root:active &, .MuiRadio-root.Mui-focusVisible &": {
        boxShadow: "0 0 4px ".concat(theme.palette.focus),
        outline: "none"
      }
    },
    container: {
      display: "flex",
      flexDirection: "column"
    },
    radioIconChecked: {
      borderColor: "currentColor",
      "&:before": {
        content: "\" \"",
        backgroundColor: "currentColor",
        width: theme.spacing(1),
        height: theme.spacing(1),
        position: "absolute",
        borderRadius: "50%",
        top: "50%",
        left: "50%",
        transform: "translate(-50%, -50%)"
      }
    },
    radioFormControl: {
      minWidth: theme.spacing(30)
    },
    errorText: {
      marginTop: theme.spacing(0.5),
      color: theme.palette.error.main,
      fontSize: theme.typography.fieldLabelSize,
      float: "left"
    }
  };
});
var extractAndValidateProps = function extractAndValidateProps(radioProps) {
  var _radioProps$get, _radioProps$get2, _radioProps$get3, _radioProps$get4;
  if ((0, _RadioProps.isRadioProps)(radioProps) === false) {
    throw new TypeError("radioProps property is not of type RadioProps");
  }
  var name = radioProps.get(_RadioProps.default.propNames.name);
  var label = radioProps.get(_RadioProps.default.propNames.label);
  var defaultVal = radioProps.get(_RadioProps.default.propNames.defaultVal);
  var value = (_radioProps$get = radioProps.get(_RadioProps.default.propNames.value)) != null ? _radioProps$get : defaultVal;
  var update = radioProps.get(_RadioProps.default.propNames.update);
  var row = (_radioProps$get2 = radioProps.get(_RadioProps.default.propNames.row)) != null ? _radioProps$get2 : true;
  var radios = radioProps.get(_RadioProps.default.propNames.radios);
  var disabled = (_radioProps$get3 = radioProps.get(_RadioProps.default.propNames.disabled)) != null ? _radioProps$get3 : false;
  var allowSingleRadio = (_radioProps$get4 = radioProps.get(_RadioProps.default.propNames.allowSingleRadio)) != null ? _radioProps$get4 : false;
  if (!radios || radios.length < 2 && !allowSingleRadio) {
    throw new Error("Radio component must have at least two options");
  }
  if (radios.length < 1) {
    throw new Error("Radio component must have at least one option");
  }
  if (!name || name.length === 0) {
    throw new Error("Radio component name is required and missing");
  }
  if (value && !radios.some(function (radio) {
    return radio.value === value;
  })) {
    throw new Error("Radio component must have a matching option for it's value");
  }
  if (defaultVal && !radios.some(function (radio) {
    return radio.value === defaultVal;
  })) {
    throw new Error("Radio component must have a matching option for it's default value");
  }
  if (radios.some(function (radio) {
    return radios.some(function (x) {
      return x !== radio && x.value === radio.value;
    });
  })) {
    throw new Error("Radio component must not have duplicated radio values");
  }
  return {
    name: name,
    label: label,
    defaultVal: defaultVal,
    value: value,
    update: update,
    row: row,
    radios: radios,
    disabled: disabled
  };
};
var Radio = function Radio(_ref) {
  var radioProps = _ref.radioProps;
  var classes = useStyles();
  var _extractAndValidatePr = extractAndValidateProps(radioProps),
    name = _extractAndValidatePr.name,
    label = _extractAndValidatePr.label,
    defaultVal = _extractAndValidatePr.defaultVal,
    value = _extractAndValidatePr.value,
    update = _extractAndValidatePr.update,
    row = _extractAndValidatePr.row,
    radios = _extractAndValidatePr.radios,
    disabled = _extractAndValidatePr.disabled;
  var handleChange = update ? function (event) {
    return update(event.target.value);
  } : null;
  var error = radioProps == null ? void 0 : radioProps.get(_RadioProps.default.propNames.error);
  var hasError = error !== false && !!error;
  var radio = /*#__PURE__*/_react.default.createElement(_FormControl.default, {
    component: "fieldset",
    className: classes.radioFormControl,
    error: hasError
  }, /*#__PURE__*/_react.default.createElement(_FormLabel.default, {
    component: "legend"
  }, label), /*#__PURE__*/_react.default.createElement(_RadioGroup.default, {
    row: row,
    "aria-label": name,
    name: name,
    defaultValue: defaultVal,
    value: value,
    onChange: handleChange
  }, radios.map(function (radio) {
    var _radio$disabled;
    var handleClick = radio.clickEvent ? function (event) {
      return radio.clickEvent(event.target.value);
    } : null;
    return /*#__PURE__*/_react.default.createElement(_FormControlLabel.default, {
      key: "radiobutton_".concat(radio.value),
      value: radio.value,
      label: radio.label,
      disabled: disabled ? true : (_radio$disabled = radio.disabled) != null ? _radio$disabled : false,
      control: /*#__PURE__*/_react.default.createElement(_Radio.default, {
        color: "primary",
        checkedIcon: /*#__PURE__*/_react.default.createElement("span", {
          className: (0, _classnames.default)(classes.radioIcon, classes.radioIconChecked)
        }),
        icon: /*#__PURE__*/_react.default.createElement("span", {
          className: classes.radioIcon
        }),
        onClick: handleClick
      })
    });
  })));
  return hasError && /*#__PURE__*/_react.default.createElement("div", {
    className: classes.container
  }, radio, /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)(classes.errorText)
  }, error)) || radio;
};
__signature__(Radio, "useStyles{classes}", function () {
  return [useStyles];
});
__signature__(Radio, "useStyles{classes}", function () {
  return [useStyles];
});
var _default = Radio;
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/Radio.js");
  reactHotLoader.register(extractAndValidateProps, "extractAndValidateProps", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Radio.js");
  reactHotLoader.register(Radio, "Radio", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Radio.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Radio.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/Radio.js");
  reactHotLoader.register(extractAndValidateProps, "extractAndValidateProps", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Radio.js");
  reactHotLoader.register(Radio, "Radio", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Radio.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Radio.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();