"use strict";exports.__esModule = true;exports.selectNodeContents = exports.removeAllSelections = void 0;var _globalObject = require("@skbkontur/global-object");

var selectNodeContents = exports.selectNodeContents = function selectNodeContents(node, start, end) {
  if (!node) {
    return;
  }
  if ((0, _globalObject.isBrowser)(_globalObject.globalObject) && 'createRange' in _globalObject.globalObject.document) {
    try {
      var selection = _globalObject.globalObject.getSelection();
      var range = _globalObject.globalObject.document.createRange();
      if (start !== undefined && end !== undefined) {
        range.setStart(node, start);
        range.setEnd(node, end);
      } else {
        range.selectNodeContents(node);
      }
      if (selection !== null) {
        // Fix IE from issue not working (https://github.com/skbkontur/retail-ui/issues/1205)
        selection.removeAllRanges();
        selection.addRange(range);
        return;
      }
    } catch (e) {

      // empty block
    }}

  if ((0, _globalObject.isBrowser)(_globalObject.globalObject) && 'createTextRange' in _globalObject.globalObject.document.body) {
    // @ts-expect-error: IE-specific API.
    var _range = _globalObject.globalObject.document.body.createTextRange();
    _range.moveToElementText(node);
    if (typeof _range.select === 'function') {
      _range.select();
    }
    return;
  }
};

var removeAllSelections = exports.removeAllSelections = function removeAllSelections() {
  var selection = _globalObject.globalObject.getSelection == null ? void 0 : _globalObject.globalObject.getSelection();
  if (selection) {
    try {
      // Fix IE from issue not working (https://github.com/skbkontur/retail-ui/issues/1205)
      selection.removeAllRanges();
    } catch (e) {

      // empty block
    }}
};