"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 = _interopRequireDefault(require("react"));
require("./index.scss");
var _excluded = ["label", "value", "checked", "type", "name", "selectColor", "selectTextColor", "unSelectColor", "unSelectTextColor", "onChange"];
var styleFunction = function styleFunction(type, bgColors, textColors, checked) {
  var bgColor = checked ? bgColors[1] : bgColors[0];
  var textColor = checked ? textColors[1] : textColors[0];
  if (type === 'button') {
    return {
      'backgroundColor': bgColor,
      'color': textColor
    };
  }
  if (type === 'text') {
    return {
      'color': textColor,
      'position': checked ? 'relative' : 'static'
    };
  }
  return {};
};
var RadioGroupItem = function RadioGroupItem(_ref) {
  var _ref$label = _ref.label,
    label = _ref$label === void 0 ? '标签' : _ref$label,
    _ref$value = _ref.value,
    value = _ref$value === void 0 ? 'value' : _ref$value,
    checked = _ref.checked,
    _ref$type = _ref.type,
    type = _ref$type === void 0 ? 'button' : _ref$type,
    name = _ref.name,
    _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,
    onChange = _ref.onChange,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var _otherProps = otherProps || {};
  var handleChange = function handleChange(event) {
    onChange(event.target.value);
  };
  // 获取特殊的样式
  var customStyle = styleFunction(type, [unSelectColor, selectColor], [unSelectTextColor, selectTextColor], checked);
  if (_otherProps.style) {
    _otherProps.style = (0, _extends2["default"])({}, _otherProps.style, customStyle);
  } else {
    _otherProps.style = (0, _extends2["default"])({}, customStyle);
  }
  var className = type === 'button' ? 'radio-group-item__button' : 'radio-group-item__text';
  return /*#__PURE__*/_react["default"].createElement("label", (0, _extends2["default"])({
    key: value,
    className: className
  }, _otherProps), type === 'text' && checked && /*#__PURE__*/_react["default"].createElement("span", {
    className: "radio-group-item__text__line",
    style: {
      'background-color': selectColor
    }
  }), /*#__PURE__*/_react["default"].createElement("input", {
    type: "radio",
    style: {
      'display': 'none'
    },
    name: name,
    value: value,
    checked: checked,
    onChange: handleChange
  }), label);
};
RadioGroupItem.displayName = 'RadioGroupItem';
var _default = exports["default"] = RadioGroupItem;