import _Button from "antd/es/button";
import _Space from "antd/es/space";
import _Input from "antd/es/input";
import _Radio from "antd/es/radio";
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
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"];
/* eslint-disable @typescript-eslint/no-shadow */
import * as React from 'react';
import { useState, useEffect } from 'react';
import "./index.less";
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 = _objectWithoutPropertiesLoose(_ref, _excluded);
  // group 组
  var RadioGroup = function RadioGroup() {
    var _useState = 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;
    };
    useEffect(function () {
      if (controlled && selectvalue) {
        setValue(selectvalue);
      }
      onChange;
    }, [controlled, selectvalue, value]);
    var defaultprops = _extends({
      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.Group, _extends({}, defaultprops, {
      ref: ref
    }), optionType == 'default' && /*#__PURE__*/React.createElement(_Space, {
      direction: direction
    }, data === null || data === void 0 ? void 0 : data.map(function (item, index) {
      return /*#__PURE__*/React.createElement(_Radio, {
        value: item.value,
        key: index,
        disabled: item.disabled,
        autoFocus: item.autoFocus
      }, item.value);
    }), moreInput && /*#__PURE__*/React.createElement(_Radio, {
      value: moreInputLable
    }, moreInputLable, value === moreInputLable ? /*#__PURE__*/React.createElement(_Input, {
      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.Button, {
        value: item.value,
        key: index,
        disabled: item.disabled,
        autoFocus: item.autoFocus
      }, item.value);
    })));
  };

  // 单个
  var RadioOne = function RadioOne() {
    var RadioOneprops = _extends({
      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.Button, _extends({}, RadioOneprops, {
        ref: ref
      }), radiodata) : /*#__PURE__*/React.createElement(_Radio, _extends({}, RadioOneprops, {
        ref: ref
      }), radiodata);
    };

    // 案例
    var ToggleDisabled = function ToggleDisabled() {
      var _useState2 = 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, {
        defaultChecked: false,
        disabled: disableds
      }, radionameone), /*#__PURE__*/React.createElement(_Radio, {
        defaultChecked: true,
        disabled: disableds
      }, radionametwo), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement(_Button, {
        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';
export default antRadio;