import _Button from "antd/es/button";
import _Switch from "antd/es/switch";
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["className", "style", "checked", "defaultChecked", "disabled", "size", "type", "loading", "checkedChildren", "unCheckedChildren", "buttonname", "disableType"];
/* eslint-disable @typescript-eslint/no-shadow */
import * as React from 'react';
import { useState } from 'react';
import { CheckOutlined, CloseOutlined } from '@ant-design/icons/es/index';
import "./index.less";
var antSwitch = function antSwitch(_ref) {
  var className = _ref.className,
    style = _ref.style,
    checked = _ref.checked,
    defaultChecked = _ref.defaultChecked,
    disabled = _ref.disabled,
    size = _ref.size,
    type = _ref.type,
    loading = _ref.loading,
    checkedChildren = _ref.checkedChildren,
    unCheckedChildren = _ref.unCheckedChildren,
    buttonname = _ref.buttonname,
    disableType = _ref.disableType,
    otherProps = _objectWithoutPropertiesLoose(_ref, _excluded);
  var onChange = function onChange(checked) {
    console.log("switch to " + checked);
  };
  var defaultProps = _extends({
    size: size,
    style: style,
    disabled: disabled,
    loading: loading,
    defaultChecked: defaultChecked,
    buttonname: buttonname,
    onChange: onChange
  }, otherProps);
  if (type == "文本") {
    defaultProps.checkedChildren = checkedChildren;
    defaultProps.unCheckedChildren = unCheckedChildren;
  } else if (type == "icon") {
    defaultProps.checkedChildren = /*#__PURE__*/React.createElement(CheckOutlined, null);
    defaultProps.unCheckedChildren = /*#__PURE__*/React.createElement(CloseOutlined, null);
  }
  if (checked) {
    defaultProps.checked = checked;
  }
  // useEffect(() => {
  //   defaultProps
  // }, [defaultChecked])

  var Primaryswitch = function Primaryswitch() {
    return defaultChecked ? /*#__PURE__*/React.createElement(_Switch, _extends({
      defaultChecked: true
    }, defaultProps)) : /*#__PURE__*/React.createElement(_Switch, defaultProps);
  };
  var Buttonswitch = function Buttonswitch() {
    var _useState = useState(true),
      disableds = _useState[0],
      setDisableds = _useState[1];
    var toggle = function toggle() {
      setDisableds(!disableds);
    };
    return /*#__PURE__*/React.createElement("div", {
      style: style
    }, /*#__PURE__*/React.createElement(_Switch, _extends({}, defaultProps, {
      disabled: disableds,
      defaultChecked: true
    })), /*#__PURE__*/React.createElement("br", null), "    ", /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement(_Button, {
      type: "primary",
      onClick: toggle
    }, buttonname));
  };
  return disableType === "开关" ? /*#__PURE__*/React.createElement(Primaryswitch, null) : /*#__PURE__*/React.createElement(Buttonswitch, null);
};
antSwitch.displayName = 'antSwitch';
export default antSwitch;