"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _react = _interopRequireDefault(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _icon = _interopRequireDefault(require("../icon"));

var _components = require("../components");

var _context = require("../config-provider/context");

var LoadingLine = _icon.default.LoadingLine;

var Switch = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
  var disabled = _ref.disabled,
      loading = _ref.loading,
      size = _ref.size,
      className = _ref.className,
      otherProps = (0, _objectWithoutProperties2.default)(_ref, ["disabled", "loading", "size", "className"]);

  var _React$useContext = _react.default.useContext(_context.ConfigContext),
      getPrefixClassName = _React$useContext.getPrefixClassName;

  var switchCls = getPrefixClassName('switch'); // render

  var loadingIcon = /*#__PURE__*/_react.default.createElement("div", {
    className: "".concat(switchCls, "-handle")
  }, loading && /*#__PURE__*/_react.default.createElement(LoadingLine, null));

  return /*#__PURE__*/_react.default.createElement(_components.RcSwitch, Object.assign({}, otherProps, {
    disabled: disabled || loading,
    prefixCls: switchCls,
    size: size,
    ref: ref,
    loadingIcon: loadingIcon,
    className: (0, _classnames.default)(size === 'large' && "".concat(switchCls, "-lg"), size === 'small' && "".concat(switchCls, "-sm"), loading && "".concat(switchCls, "-loading"), className)
  }));
});

Switch.displayName = 'Switch';
Switch.defaultProps = {
  size: 'medium',
  disabled: false,
  defaultChecked: false,
  loading: false
};
var _default = Switch;
exports.default = _default;