"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _button = _interopRequireDefault(require("antd/lib/button"));
var _switch = _interopRequireDefault(require("antd/lib/switch"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _index = require("@ant-design/icons/es/index");
require("./index.less");
var _excluded = ["className", "style", "checked", "defaultChecked", "disabled", "size", "type", "loading", "checkedChildren", "unCheckedChildren", "buttonname", "disableType"];
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 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 = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var onChange = function onChange(checked) {
    console.log("switch to " + checked);
  };
  var defaultProps = (0, _extends2["default"])({
    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(_index.CheckOutlined, null);
    defaultProps.unCheckedChildren = /*#__PURE__*/React.createElement(_index.CloseOutlined, null);
  }
  if (checked) {
    defaultProps.checked = checked;
  }
  // useEffect(() => {
  //   defaultProps
  // }, [defaultChecked])

  var Primaryswitch = function Primaryswitch() {
    return defaultChecked ? /*#__PURE__*/React.createElement(_switch["default"], (0, _extends2["default"])({
      defaultChecked: true
    }, defaultProps)) : /*#__PURE__*/React.createElement(_switch["default"], defaultProps);
  };
  var Buttonswitch = function Buttonswitch() {
    var _useState = (0, React.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["default"], (0, _extends2["default"])({}, defaultProps, {
      disabled: disableds,
      defaultChecked: true
    })), /*#__PURE__*/React.createElement("br", null), "    ", /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement(_button["default"], {
      type: "primary",
      onClick: toggle
    }, buttonname));
  };
  return disableType === "开关" ? /*#__PURE__*/React.createElement(Primaryswitch, null) : /*#__PURE__*/React.createElement(Buttonswitch, null);
};
antSwitch.displayName = 'antSwitch';
var _default = antSwitch;
exports["default"] = _default;