import _extends from "@babel/runtime/helpers/extends";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _Radio from "@alifd/next/es/radio";
import * as React from 'react';
import './index.less';
var RadioGroup = _Radio.Group;
var RadioGroupSetter = /*#__PURE__*/function (_React$PureComponent) {
  function RadioGroupSetter() {
    var _this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _React$PureComponent.call.apply(_React$PureComponent, [this].concat(args)) || this;
    _this.state = {
      setterValue: null
    };
    _this.renderLabel = function (dataSource) {
      var onChange = _this.props.onChange;
      var setterValue = _this.state.setterValue;
      var labelList = dataSource.map(function (item, index) {
        return item.img ? /*#__PURE__*/React.createElement("span", {
          key: index,
          className: "setter-choose-option " + (setterValue === item.value && 'setter-choose-checked' || ''),
          onClick: function onClick() {
            return onChange(item.value);
          }
        }, /*#__PURE__*/React.createElement("span", {
          style: {
            backgroundImage: "url(\"" + item.img + "\")"
          },
          className: "setter-choose-img"
        })) : /*#__PURE__*/React.createElement("span", {
          key: index,
          className: "setter-choose-label " + (setterValue === (item.value === undefined ? item : item.value) && 'setter-choose-checked' || ''),
          onClick: function onClick() {
            return onChange(item.value === undefined ? item : item.value);
          }
        }, item.label || item);
      });
      return labelList || [];
    };
    return _this;
  }
  _inheritsLoose(RadioGroupSetter, _React$PureComponent);
  var _proto = RadioGroupSetter.prototype;
  _proto.render = function render() {
    var _this$props = this.props,
      _onChange = _this$props.onChange,
      _this$props$disabled = _this$props.disabled,
      disabled = _this$props$disabled === void 0 ? false : _this$props$disabled,
      options = _this$props.options,
      value = _this$props.value;
    var hasImg = false;
    var dataSource = options.map(function (item) {
      if (typeof item == 'string') {
        return item;
      } else {
        if (item.img) {
          hasImg = true;
        }
        return {
          img: item.img,
          label: item.title || item.label,
          value: item.value
        };
      }
    });
    var otherProps = {};
    if (hasImg) {
      otherProps.children = this.renderLabel(dataSource);
    }
    return /*#__PURE__*/React.createElement("div", {
      className: "radiogroup-style"
    }, /*#__PURE__*/React.createElement(RadioGroup, _extends({
      size: "small",
      dataSource: dataSource,
      shape: "button",
      value: value,
      disabled: disabled,
      onChange: function onChange(val) {
        return _onChange(val);
      }
    }, otherProps)));
  };
  return RadioGroupSetter;
}(React.PureComponent);
RadioGroupSetter.displayName = 'RadioGroupSetter';
export { RadioGroupSetter as default };