"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _react = _interopRequireWildcard(require("react"));
require("./index.scss");
var _radioGroupItem = _interopRequireDefault(require("./radio-group-item"));
var _excluded = ["options", "name", "type", "defaultValue", "selectColor", "selectTextColor", "unSelectColor", "unSelectTextColor", "isWrap", "onChange", "children"];
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function uuid() {
  return Math.random().toString(36).substring(2);
}
var RadioGroup = function RadioGroup(_ref) {
  var _options$;
  var options = _ref.options,
    _ref$name = _ref.name,
    name = _ref$name === void 0 ? uuid() : _ref$name,
    _ref$type = _ref.type,
    type = _ref$type === void 0 ? 'button' : _ref$type,
    defaultValue = _ref.defaultValue,
    _ref$selectColor = _ref.selectColor,
    selectColor = _ref$selectColor === void 0 ? '#F5743F' : _ref$selectColor,
    _ref$selectTextColor = _ref.selectTextColor,
    selectTextColor = _ref$selectTextColor === void 0 ? 'white' : _ref$selectTextColor,
    _ref$unSelectColor = _ref.unSelectColor,
    unSelectColor = _ref$unSelectColor === void 0 ? '#F0F0F0' : _ref$unSelectColor,
    _ref$unSelectTextColo = _ref.unSelectTextColor,
    unSelectTextColor = _ref$unSelectTextColo === void 0 ? '#727272' : _ref$unSelectTextColo,
    _ref$isWrap = _ref.isWrap,
    isWrap = _ref$isWrap === void 0 ? false : _ref$isWrap,
    _ref$onChange = _ref.onChange,
    onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
    children = _ref.children,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var _otherProps = otherProps || {};
  var defaultV = (options === null || options === void 0 ? void 0 : (_options$ = options[0]) === null || _options$ === void 0 ? void 0 : _options$.value) || defaultValue || '';
  var _useState = (0, _react.useState)(defaultV),
    selectedValue = _useState[0],
    setSelectedValue = _useState[1];
  (0, _react.useEffect)(function () {
    if (defaultV) {
      handleChange(defaultV);
    }
  }, [defaultV]);
  var handleChange = function handleChange(value) {
    setSelectedValue(value);
    onChange(value);
  };
  var wrapClass = isWrap ? 'flex-wrap: wrap;' : 'flex-wrap: nowrap;overflow-x: auto;';
  _otherProps.style = wrapClass + ' ' + _otherProps.style ? _otherProps.style : '';
  return /*#__PURE__*/_react["default"].createElement("div", (0, _extends2["default"])({
    className: "radio-group__panel"
  }, _otherProps), (options || []).map(function (option) {
    return /*#__PURE__*/_react["default"].createElement(_radioGroupItem["default"], {
      label: option.label,
      value: option.value,
      key: option.value,
      checked: selectedValue === option.value,
      name: name,
      type: type,
      selectColor: selectColor,
      selectTextColor: selectTextColor,
      unSelectColor: unSelectColor,
      unSelectTextColor: unSelectTextColor,
      onChange: handleChange
    });
    // return convertChildren(children, 'custom-radio-group-item', {
    //     label: option.label,
    //     value: option.value,
    //     key: option.value,
    //     checked: selectedValue === option.value,
    //     name: name,
    //     type: type,
    //     selectColor: selectColor,
    //     selectTextColor: selectTextColor,
    //     unSelectColor: unSelectColor,
    //     unSelectTextColor: unSelectTextColor,
    //     onChange: handleChange
    // })
  }));
};
RadioGroup.displayName = 'RadioGroup';
var _default = exports["default"] = RadioGroup;