"use strict";

exports.__esModule = true;
exports.command = void 0;
require("core-js/modules/es.array.includes.js");
require("core-js/modules/es.string.includes.js");
var command = {
  name: 'scrollToFocusedCell',
  callback: function callback(hot) {
    var _hot$getSelectedRange = hot.getSelectedRangeLast(),
      highlight = _hot$getSelectedRange.highlight;
    var firstVisibleRow = hot.view.getFirstFullyVisibleRow() - 1;
    var firstVisibleColumn = hot.view.getFirstFullyVisibleColumn() - 1;
    var lastVisibleRow = hot.view.getLastFullyVisibleRow() + 1;
    var lastVisibleColumn = hot.view.getLastFullyVisibleColumn() + 1;
    var visibleCoordsFrom = hot._createCellCoords(firstVisibleRow, firstVisibleColumn);
    var visibleCoordsTo = hot._createCellCoords(lastVisibleRow, lastVisibleColumn);
    var visibleRange = hot._createCellRange(visibleCoordsFrom, visibleCoordsFrom, visibleCoordsTo);
    if (!visibleRange.includes(highlight) && (highlight.row >= 0 || highlight.col >= 0)) {
      var offsetRows = Math.floor(hot.countVisibleRows() / 2);
      var offsetColumns = Math.floor(hot.countVisibleCols() / 2);
      var scrollX = Math.max(highlight.row - offsetRows, 0);
      var scrollY = Math.max(highlight.col - offsetColumns, 0);
      var scrollCoords = [scrollX, scrollY];

      // for row header focus do not change the scroll Y position, leave as it is
      if (highlight.col < 0) {
        scrollCoords[1] = null;

        // for column header focus do not change the scroll X position, leave as it is
      } else if (highlight.row < 0) {
        scrollCoords[0] = null;
      }
      hot.scrollViewportTo.apply(hot, scrollCoords);
    }
  }
};
exports.command = command;