"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 _row = _interopRequireDefault(require("antd/lib/row"));
var _col = _interopRequireDefault(require("antd/lib/col"));
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", "ColNum", "isGroupRow", "BeforebdColor", "BeforebgColor", "AfterbdColor", "AfterbgColor", "widths", "heights", "CheckSpanWidth", "styles", "buttonColor", "bgColors", "slectstyles", "befslectstyles", "slectstylesbgc", "flag"];
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,
    ColNum = _ref.ColNum,
    isGroupRow = _ref.isGroupRow,
    BeforebdColor = _ref.BeforebdColor,
    BeforebgColor = _ref.BeforebgColor,
    AfterbdColor = _ref.AfterbdColor,
    AfterbgColor = _ref.AfterbgColor,
    widths = _ref.widths,
    heights = _ref.heights,
    CheckSpanWidth = _ref.CheckSpanWidth,
    styles = _ref.styles,
    buttonColor = _ref.buttonColor,
    bgColors = _ref.bgColors,
    slectstyles = _ref.slectstyles,
    befslectstyles = _ref.befslectstyles,
    slectstylesbgc = _ref.slectstylesbgc,
    flag = _ref.flag,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var _useState = (0, React.useState)(''),
    ID = _useState[0],
    setID = _useState[1];
  var _useState2 = (0, React.useState)(),
    stylesr = _useState2[0],
    setStyles = _useState2[1];
  var _useState3 = (0, React.useState)(''),
    widthsr = _useState3[0],
    setwidthsr = _useState3[1];
  var _useState4 = (0, React.useState)(''),
    heightsr = _useState4[0],
    setheightsr = _useState4[1];
  var _useState5 = (0, React.useState)(''),
    marginTopsr = _useState5[0],
    setmarginTopsr = _useState5[1];
  var _useState6 = (0, React.useState)(''),
    marginLeftsr = _useState6[0],
    setmarginLeftsr = _useState6[1];
  var _useState7 = (0, React.useState)(''),
    borderRadiusr = _useState7[0],
    setborderRadiusr = _useState7[1];
  var doc = document.getElementById(ID) || document;
  // const [_style,setStylediv] =useState({width:"64px"})

  var _style = (0, _extends2["default"])({}, style) || {};
  var _styles = (0, _extends2["default"])({}, style) || {};
  var _otherProps = (0, _extends2["default"])({}, otherProps) || {};
  _style['marginLeft'] = 'none';
  _style['marginRight'] = 'none';
  _style['marginTop'] = 'none';
  _style['marginBottom'] = 'none';
  _otherProps.style = _style;
  // _styles['width'] = "none" 

  (0, React.useEffect)(function () {
    setID("radio_" + uuid());
  }, []);

  // useEffect(()=>{
  //   if(groupflag){
  //     setStylediv(style || {width:"242px"})
  //     if(optionType=='button'){
  //       if(size=='small'){
  //         setStylediv(style || {width:"152px"})
  //       }else if(size == 'medium'){
  //         setStylediv(style ||{width:"200px"})
  //       }else if(size == 'large'){
  //         setStylediv(style ||{width:"215px"})
  //       }
  //     }
  //   }else if(isGroupRow){
  //     setStylediv(style || {width:"242px"})
  //   }
  //   else if(!groupflag)
  //   {
  //     setStylediv(style || {width:"64px"})
  //   }
  // },[groupflag,optionType,style,isGroupRow,size])

  (0, React.useEffect)(function () {
    if (ID) {
      radioInnerStyle();
      radioStyleAfter();
      CheckSpanWidths();
      buttonborder();
      buttoncolor();
    }
  });
  function uuid() {
    return (Math.random() * 1e6 >> 0).toString(36);
  }

  // 间距
  var CheckSpanWidths = function CheckSpanWidths() {
    setTimeout(function () {
      var elems = doc === null || doc === void 0 ? void 0 : doc.querySelectorAll('span.ant-radio+* ');
      var index = 0;
      var length = elems.length;
      for (; index < length; index++) {
        elems[index].style.paddingLeft = CheckSpanWidth + 'px'; //间距
      }
    }, 0);
  };

  // 单选圆圈大小
  var radioInnerStyle = function radioInnerStyle() {
    setTimeout(function () {
      var elems = doc === null || doc === void 0 ? void 0 : doc.querySelectorAll('.ant-radio-inner');
      var index = 0,
        length = elems.length;
      for (; index < length; index++) {
        elems[index].style.width = widths + "px"; //单选圆圈宽
        elems[index].style.height = heights + "px"; //单选圆圈高
        // 选中前颜色
        elems[index].style.borderColor = BeforebdColor; //边框颜色
        elems[index].style.backgroundColor = BeforebgColor; //背景色
      }
    }, 0);
  };

  // 单选框选中后颜色
  var radioStyleAfter = function radioStyleAfter() {
    radioInnerStyle();
    setTimeout(function () {
      var radioChecked = doc === null || doc === void 0 ? void 0 : doc.querySelector('.ant-radio-checked');
      var elems = radioChecked === null || radioChecked === void 0 ? void 0 : radioChecked.querySelector('.ant-radio-inner');
      if (elems) {
        elems.style.backgroundColor = AfterbgColor; //多选框背景色
      }

      setStyles(styles);
      setwidthsr(widths);
      setheightsr(heights);
      setmarginTopsr(Math.round(-widths / 2));
      setmarginLeftsr(Math.round(-heights / 2));
      setborderRadiusr(widths);

      //创建元素
      var style = document.createElement("style"); //创建一个<style>标签
      //小圆圈
      var change = document.createTextNode('#' + ID + ' ' + '.ant-radio-inner::after{content:"";background-color:' + stylesr + ";width:" + widthsr + 'px' + ";height:" + heightsr + 'px' + ";margin-top:" + marginTopsr + 'px' + ";margin-left:" + marginLeftsr + 'px' + ";border-radius:" + borderRadiusr + 'px' + ";}"); //更改后伪元素的样式
      style.appendChild(change); //把样式添加到style标签里
      document.body.appendChild(style); //把内联样式表添加到html中
      elems === null || elems === void 0 ? void 0 : elems.classList.add("change");
    }, 0);
  };

  // button 的border颜色 
  var buttonborder = function buttonborder() {
    setTimeout(function () {
      //边框色
      var firstbor = doc.querySelectorAll('.ant-radio-button-wrapper:last-child');
      var elemsbor = doc.querySelectorAll('.ant-radio-button-wrapper');
      var elesnotfirst = doc.querySelector('.ant-radio-button-wrapper:not(:first-child)');
      var index = 0;
      var j = 0;
      var length = elemsbor.length;
      var lengths = firstbor.length;
      for (; index < length; index++) {
        elemsbor[index].style.borderColor = buttonColor; //按钮边框色
        // elemsbor[index].style.backgroundColor = befslectstyles ; //按钮选中前背景色
      }

      for (; j < lengths; j++) {
        firstbor[j].style.borderLeft = "1px solid " + buttonColor; //按钮边框色
      }
      //创建元素
      var style = document.createElement("style"); //创建一个<style>标签
      //伪元素
      var firstbef = document.createTextNode('#' + ID + ' ' + '.ant-radio-button-wrapper:not(:first-child)::before{content:"";background-color:' + buttonColor + '}'); //更改后伪元素的样式
      style.appendChild(firstbef); //把样式添加到style标签里
      document.body.appendChild(style); //把内联样式表添加到html中
      elesnotfirst === null || elesnotfirst === void 0 ? void 0 : elesnotfirst.classList.add("firstbef");
    }, 0);
  };

  //button 选中色
  var buttoncolor = function buttoncolor() {
    setTimeout(function () {
      //选择前
      var buttonall = doc.querySelectorAll('.ant-radio-button-wrapper');
      var index = 0,
        length = buttonall.length;
      for (; index < length; index++) {
        buttonall[index].style.backgroundColor = null; //背景色
        buttonall[index].style.color = null; //button字体颜色
        if (style !== null && style !== void 0 && style.color) {
          buttonall[index].style.color = style.color;
        }
        if (style !== null && style !== void 0 && style.backgroundColor) {
          buttonall[index].style.backgroundColor = style.backgroundColor;
        }
      }
      // 选中后
      var outcolor = doc === null || doc === void 0 ? void 0 : doc.querySelector('.ant-radio-button-wrapper-checked');
      if (outcolor) {
        outcolor.style.backgroundColor = slectstylesbgc; //button背景颜色
        outcolor.style.color = slectstyles; //button字体颜色
      }
      // if (buttonStyle == 'solid') {  //填色
      //   let outcolor = doc?.querySelector('.ant-radio-button-wrapper-checked')
      //   if (outcolor) {
      //     outcolor.style.backgroundColor = slectstyles; //button字体颜色
      //   }
      // }
      // else {  //描边
      //   let outcolor = doc?.querySelector('.ant-radio-button-wrapper-checked')
      //   if (outcolor) {
      //     outcolor.style.color = slectstyles; //button字体颜色
      //   }
      // }
    }, 0);
  };

  // group 组
  var RadioGroup = function RadioGroup() {
    var _useState8 = (0, React.useState)(null),
      value = _useState8[0],
      setValue = _useState8[1];
    var onChange = function onChange(e) {
      radioStyleAfter();
      buttoncolor();
      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, optionType]);
    var defaultprops = (0, _extends2["default"])({
      disabled: disabled,
      optionType: optionType,
      buttonStyle: buttonStyle,
      size: size,
      style: style,
      defaultValue: defaultValue,
      onChange: onChange,
      ref: ref,
      ColNum: ColNum,
      isGroupRow: isGroupRow
    }, otherProps);
    if (controlled && selectvalue) {
      defaultprops.value = selectvalue;
    }
    // 布局
    function isGroupRowComponent() {
      var spanNum = 24 / ColNum;
      spanNum = Math.trunc(spanNum);
      return /*#__PURE__*/React.createElement(_radio["default"].Group, (0, _extends2["default"])({
        style: {
          width: '100%'
        }
      }, defaultprops), /*#__PURE__*/React.createElement(_row["default"], null, data === null || data === void 0 ? void 0 : data.map(function (item, index) {
        return /*#__PURE__*/React.createElement(_col["default"], {
          span: spanNum
        }, /*#__PURE__*/React.createElement(_radio["default"], {
          value: item.value,
          key: index,
          disabled: item.disabled,
          autoFocus: item.autoFocus,
          style: _style
        }, item.value));
      })));
    }
    return isGroupRow ? isGroupRowComponent() : /*#__PURE__*/React.createElement(_radio["default"].Group, (0, _extends2["default"])({}, defaultprops, {
      ref: ref,
      style: {
        width: '100%'
      }
    }), 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,
        style: _style
      }, 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,
        style: style
      }, item.value);
    })));
  };

  // 单个
  var RadioOne = function RadioOne() {
    var _useState9 = (0, React.useState)(null),
      value = _useState9[0],
      setValue = _useState9[1];
    // 单选框
    var onChange = function onChange(e) {
      if (optionType == 'button') {
        RadioOneprops.checked = true;
      } else {
        setValue(e.target.value);
        radioStyleAfter();
        buttoncolor();
        selectvalue = e.target.value;
        console.log(e.target.value, 'onChangeone');
        getSelectedValue = e.target.value;
      }
    };
    var onClick = function onClick() {
      setTimeout(function () {
        var elemsbor = doc.querySelector('.ant-radio-button-wrapper');
        elemsbor.classList.add('ant-radio-button-wrapper-checked');
        var outcolor = doc === null || doc === void 0 ? void 0 : doc.querySelector('.ant-radio-button-wrapper-checked');
        if (outcolor) {
          outcolor.style.color = slectstyles; //button字体颜色
          outcolor.style.backgroundColor = slectstylesbgc; //button背景颜色
        }

        elemsbor.classList.add('outcolor');
      }, 0);
    };
    var RadioOneprops = (0, _extends2["default"])({
      disabled: disabled,
      style: style,
      value: radiodata,
      radiodata: radiodata || 'radio',
      ref: ref,
      onChange: onChange
    }, otherProps);
    (0, React.useEffect)(function () {
      if (controlled && selectvalue) {
        setValue(selectvalue);
      }
      onChange;
    }, [controlled, selectvalue, value, checked, optionType]);
    if (checked) {
      RadioOneprops.checked = true;
    }
    var Radiobutton = function Radiobutton() {
      return optionType == 'button' ? /*#__PURE__*/React.createElement(_radio["default"].Button, (0, _extends2["default"])({}, RadioOneprops, {
        ref: ref,
        checked: checked,
        onClick: onClick,
        style: _style
      }), radiodata) : /*#__PURE__*/React.createElement(_radio["default"], (0, _extends2["default"])({}, RadioOneprops, {
        ref: ref,
        value: value,
        style: _style
      }), radiodata);
    };

    // 案例
    var ToggleDisabled = function ToggleDisabled() {
      var _useState10 = (0, React.useState)(true),
        disableds = _useState10[0],
        setDisableds = _useState10[1];
      var toggleDis = function toggleDis() {
        setDisableds(!disableds);
      };
      return /*#__PURE__*/React.createElement("div", {
        style: style
      }, /*#__PURE__*/React.createElement(_radio["default"], {
        defaultChecked: false,
        disabled: disableds
      }, "Disabled"), /*#__PURE__*/React.createElement(_radio["default"], {
        defaultChecked: true,
        disabled: disableds
      }, "Disabled"), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement(_button["default"], {
        type: "primary",
        onClick: toggleDis,
        style: {
          marginTop: 16
        }
      }, "Toggle disabled"));
    };
    return cases ? /*#__PURE__*/React.createElement(ToggleDisabled, null) : /*#__PURE__*/React.createElement(Radiobutton, null);
  };
  return /*#__PURE__*/React.createElement("div", {
    id: ID,
    style: _styles,
    className: flag ? "isflag" : "radiostyle"
  }, groupflag ? /*#__PURE__*/React.createElement(RadioGroup, null) : /*#__PURE__*/React.createElement(RadioOne, null))

  // <HomeOutlined/>
  ;
};

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