"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TestRadioInputSection = TestRadioInputSection;
exports.default = void 0;

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectWithoutProperties"));

var _react = _interopRequireDefault(require("react"));

var _styles = require("@material-ui/core/styles");

var _Grid = _interopRequireDefault(require("@material-ui/core/Grid"));

var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));

var useStyles = function useStyles(props) {
  return (0, _styles.makeStyles)(function (theme) {
    return {
      root: {},
      gridColumn: {
        spacing: theme.spacing(2)
      },
      gridRow: {
        "align-items": "center",
        justifyContent: props.centerContent ? 'center' : 'normal'
      }
    };
  });
};

function TestRadioInputSection(_ref) {
  var children = _ref.children,
      style = _ref.style,
      props = (0, _objectWithoutProperties2.default)(_ref, ["children", "style"]);
  var classes = useStyles(props)();
  var theme = (0, _styles.useTheme)(); // Validate props

  var taskLabels = [];

  if (props.taskLabels) {
    taskLabels = props.taskLabels;
  }

  var testRadioButtonsList = props.testRadioButtonsList; // if testRadioButtonsList is one-dimensional, make it two-dimensional

  if (testRadioButtonsList[0] && testRadioButtonsList[0].constructor !== Array) {
    testRadioButtonsList = [testRadioButtonsList];
  }

  function FormRow(props) {
    var radioButtonRow = props.radioButtonRow;
    var row = [];

    if (props.taskLabel) {
      row.push( /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Grid.default, {
        item: true
      }, /*#__PURE__*/_react.default.createElement(_Typography.default, null, /*#__PURE__*/_react.default.createElement("strong", null, props.taskLabel, ":")))));
    }

    row.push(radioButtonRow.map(function (radioButton) {
      return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Grid.default, {
        item: true
      }, radioButton));
    }));
    return row;
  }

  return /*#__PURE__*/_react.default.createElement(_Grid.default, {
    container: true,
    spacing: 1,
    style: style
  }, testRadioButtonsList.map(function (radioButtonRow, idx) {
    return /*#__PURE__*/_react.default.createElement(_Grid.default, {
      container: true,
      item: true,
      spacing: 1,
      className: classes.gridRow
    }, /*#__PURE__*/_react.default.createElement(FormRow, {
      radioButtonRow: radioButtonRow,
      taskLabel: taskLabels[idx]
    }));
  }));
}

TestRadioInputSection.defaultProps = {
  testRadioButtonsList: [],
  taskLabels: []
};
var _default = TestRadioInputSection;
exports.default = _default;