"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _button = _interopRequireDefault(require("antd/lib/button"));
var _space = _interopRequireDefault(require("antd/lib/space"));
var _input = _interopRequireDefault(require("antd/lib/input"));
var _radio = _interopRequireDefault(require("antd/lib/radio"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
require("./index.less");
var _excluded = ["className", "id", "style", "checked", "defaultChecked", "label", "disabled", "selectvalue", "value", "name", "data", "size", "direction", "optionType", "buttonStyle", "defaultValue", "controlled", "groupflag", "radiodata", "moreInput", "moreInputLable", "getSelectedValue", "cases", "radionameone", "radionametwo", "buttonName", "ref", "getValue"];
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var antRadio = function antRadio(_ref) {
  var className = _ref.className,
    id = _ref.id,
    style = _ref.style,
    checked = _ref.checked,
    defaultChecked = _ref.defaultChecked,
    label = _ref.label,
    disabled = _ref.disabled,
    selectvalue = _ref.selectvalue,
    value = _ref.value,
    name = _ref.name,
    data = _ref.data,
    size = _ref.size,
    direction = _ref.direction,
    optionType = _ref.optionType,
    buttonStyle = _ref.buttonStyle,
    defaultValue = _ref.defaultValue,
    controlled = _ref.controlled,
    groupflag = _ref.groupflag,
    radiodata = _ref.radiodata,
    moreInput = _ref.moreInput,
    moreInputLable = _ref.moreInputLable,
    getSelectedValue = _ref.getSelectedValue,
    cases = _ref.cases,
    radionameone = _ref.radionameone,
    radionametwo = _ref.radionametwo,
    buttonName = _ref.buttonName,
    ref = _ref.ref,
    getValue = _ref.getValue,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  // group 组
  var RadioGroup = function RadioGroup() {
    var _useState = (0, React.useState)(null),
      value = _useState[0],
      setValue = _useState[1];
    var onChange = function onChange(e) {
      setValue(e.target.value);
      selectvalue = e.target.value;
      console.log(e.target.value, 'onChange');
      getSelectedValue = e.target.value;
    };
    (0, React.useEffect)(function () {
      if (controlled && selectvalue) {
        setValue(selectvalue);
      }
      onChange;
    }, [controlled, selectvalue, value]);
    var defaultprops = (0, _extends2["default"])({
      disabled: disabled,
      optionType: optionType,
      buttonStyle: buttonStyle,
      size: size,
      style: style,
      defaultValue: defaultValue,
      onChange: onChange,
      ref: ref
    }, otherProps);
    if (controlled && selectvalue) {
      defaultprops.value = selectvalue;
    }
    return /*#__PURE__*/React.createElement(_radio["default"].Group, (0, _extends2["default"])({}, defaultprops, {
      ref: ref
    }), optionType == 'default' && /*#__PURE__*/React.createElement(_space["default"], {
      direction: direction
    }, data === null || data === void 0 ? void 0 : data.map(function (item, index) {
      return /*#__PURE__*/React.createElement(_radio["default"], {
        value: item.value,
        key: index,
        disabled: item.disabled,
        autoFocus: item.autoFocus
      }, item.value);
    }), moreInput && /*#__PURE__*/React.createElement(_radio["default"], {
      value: moreInputLable
    }, moreInputLable, value === moreInputLable ? /*#__PURE__*/React.createElement(_input["default"], {
      style: {
        width: 100,
        marginLeft: 10
      }
    }) : null)), optionType == 'button' && (data === null || data === void 0 ? void 0 : data.map(function (item, index) {
      return /*#__PURE__*/React.createElement(_radio["default"].Button, {
        value: item.value,
        key: index,
        disabled: item.disabled,
        autoFocus: item.autoFocus
      }, item.value);
    })));
  };

  // 单个
  var RadioOne = function RadioOne() {
    var RadioOneprops = (0, _extends2["default"])({
      disabled: disabled,
      style: style,
      value: radiodata,
      radiodata: radiodata || 'radio',
      ref: ref
    }, otherProps);
    if (checked) {
      RadioOneprops.checked = true;
    }
    var Radiobutton = function Radiobutton() {
      return optionType == 'button' ? /*#__PURE__*/React.createElement(_radio["default"].Button, (0, _extends2["default"])({}, RadioOneprops, {
        ref: ref
      }), radiodata) : /*#__PURE__*/React.createElement(_radio["default"], (0, _extends2["default"])({}, RadioOneprops, {
        ref: ref
      }), radiodata);
    };

    // 案例
    var ToggleDisabled = function ToggleDisabled() {
      var _useState2 = (0, React.useState)(true),
        disableds = _useState2[0],
        setDisableds = _useState2[1];
      var toggleDis = function toggleDis() {
        setDisableds(!disableds);
        console.log(disableds, '123');
      };
      return /*#__PURE__*/React.createElement("div", {
        style: style
      }, /*#__PURE__*/React.createElement(_radio["default"], {
        defaultChecked: false,
        disabled: disableds
      }, radionameone), /*#__PURE__*/React.createElement(_radio["default"], {
        defaultChecked: true,
        disabled: disableds
      }, radionametwo), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement(_button["default"], {
        type: "primary",
        onClick: toggleDis,
        style: {
          marginTop: 16
        }
      }, buttonName));
    };
    return cases ? /*#__PURE__*/React.createElement(ToggleDisabled, null) : /*#__PURE__*/React.createElement(Radiobutton, null);
  };
  return groupflag ? /*#__PURE__*/React.createElement(RadioGroup, null) : /*#__PURE__*/React.createElement(RadioOne, null)
  // <HomeOutlined/>
  ;
};

antRadio.displayName = 'antRadio';
var _default = antRadio;
exports["default"] = _default;