import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _get from "@babel/runtime/helpers/get";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import { __decorate } from "tslib";
import React from 'react';
import { observer } from 'mobx-react';
import KeyCode from '../../../es/_util/KeyCode';
import { ProgressType } from '../../../es/progress/enum';
import { CheckBox } from '../check-box/CheckBox';
import Progress from '../progress';
import { Size } from '../core/enum';
import autobind from '../_util/autobind';
import isOverflow from '../overflow-tip/util';
import { show } from '../tooltip/singleton';

var Switch = /*#__PURE__*/function (_CheckBox) {
  _inherits(Switch, _CheckBox);

  var _super = _createSuper(Switch);

  function Switch() {
    _classCallCheck(this, Switch);

    return _super.apply(this, arguments);
  }

  _createClass(Switch, [{
    key: "handleKeyDown",
    value: function handleKeyDown(e) {
      if (e.keyCode === KeyCode.LEFT) {
        this.setChecked(false);
      } else if (e.keyCode === KeyCode.RIGHT) {
        this.setChecked(true);
      }

      _get(_getPrototypeOf(Switch.prototype), "handleKeyDown", this).call(this, e);
    }
  }, {
    key: "showTooltip",
    value: function showTooltip(e) {
      var currentTarget = e.currentTarget;
      var _this$props = this.props,
          children = _this$props.children,
          unCheckedChildren = _this$props.unCheckedChildren;
      var switchLabel = currentTarget.nextElementSibling;
      var text = this.isChecked() ? children : unCheckedChildren || children;

      if (text && isOverflow(switchLabel)) {
        show(currentTarget, {
          title: text
        });
        return true;
      }

      return false;
    }
  }, {
    key: "getOmitPropsKeys",
    value: function getOmitPropsKeys() {
      return _get(_getPrototypeOf(Switch.prototype), "getOmitPropsKeys", this).call(this).concat(['loading']);
    }
  }, {
    key: "isDisabled",
    value: function isDisabled() {
      if (_get(_getPrototypeOf(Switch.prototype), "isDisabled", this).call(this)) {
        return true;
      }

      var _this$props$loading = this.props.loading,
          loading = _this$props$loading === void 0 ? false : _this$props$loading;
      return loading;
    }
  }, {
    key: "getLabelText",
    value: function getLabelText() {
      return undefined;
    }
  }, {
    key: "getTextNode",
    value: function getTextNode() {
      var prefixCls = this.prefixCls,
          _this$props2 = this.props,
          children = _this$props2.children,
          unCheckedChildren = _this$props2.unCheckedChildren;
      var text = this.isChecked() ? children : unCheckedChildren || children;
      return /*#__PURE__*/React.createElement("span", {
        className: "".concat(prefixCls, "-label")
      }, text ? /*#__PURE__*/React.createElement("span", {
        className: "".concat(prefixCls, "-label-content")
      }, text) : null);
    }
  }, {
    key: "renderSwitchFloatLabel",
    value: function renderSwitchFloatLabel() {
      var prefixCls = this.prefixCls;
      return /*#__PURE__*/React.createElement("span", {
        className: "".concat(prefixCls, "-float-label")
      }, this.getLabelChildren());
    }
  }, {
    key: "getWrapperClassNames",
    value: function getWrapperClassNames() {
      var prefixCls = this.prefixCls,
          loading = this.props.loading;
      return _get(_getPrototypeOf(Switch.prototype), "getWrapperClassNames", this).call(this, _defineProperty({}, "".concat(prefixCls, "-loading"), loading));
    }
  }, {
    key: "renderInner",
    value: function renderInner() {
      var loading = this.props.loading;

      if (loading) {
        return /*#__PURE__*/React.createElement(Progress, {
          key: "loading",
          type: ProgressType.loading,
          size: Size.small
        });
      }

      return null;
    }
  }]);

  return Switch;
}(CheckBox);

Switch.displayName = 'Switch';
/**
 * tooltip disable sign
 */
// eslint-disable-next-line camelcase

Switch.__PRO_SWITCH = true; // eslint-disable-next-line camelcase

Switch.__IS_IN_CELL_EDITOR = true;
Switch.defaultProps = _objectSpread(_objectSpread({}, CheckBox.defaultProps), {}, {
  suffixCls: 'switch'
});

__decorate([autobind], Switch.prototype, "handleKeyDown", null);

Switch = __decorate([observer], Switch);
export default Switch;
//# sourceMappingURL=Switch.js.map
