import _regeneratorRuntime from '@babel/runtime/regenerator';
import { _ as __awaiter } from './tslib.es6-848120af.js';
import { j as justWait, g as getRect } from './element-e017af69.js';

// eslint-disable-next-line @typescript-eslint/naming-convention
var DRAG_TYPE;
(function (DRAG_TYPE) {
  DRAG_TYPE["DOT_TO_DOT"] = "DOT_TO_DOT";
  DRAG_TYPE["STEPS"] = "STEPS";
})(DRAG_TYPE || (DRAG_TYPE = {}));
var STEP_UNIT = 56;
function dragElement(_ref) {
  var page = _ref.page,
    source = _ref.source,
    target = _ref.target,
    mode = _ref.mode,
    _ref$reverse = _ref.reverse,
    reverse = _ref$reverse === void 0 ? false : _ref$reverse,
    _ref$stepUnit = _ref.stepUnit,
    stepUnit = _ref$stepUnit === void 0 ? STEP_UNIT : _ref$stepUnit;
  return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var sourceRect, targetRect, start, end, unit, steps, i, _t;
    return _regeneratorRuntime.wrap(function (_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          _context.next = 1;
          return getRect(source, page);
        case 1:
          sourceRect = _context.sent;
          _context.next = 2;
          return getRect(target, page);
        case 2:
          targetRect = _context.sent;
          start = (sourceRect.top + sourceRect.bottom) / 2;
          end = (targetRect.top + targetRect.bottom) / 2;
          if (reverse) {
            end = start - (end - start);
          }
          _context.next = 3;
          return page.mouse.move((sourceRect.left + sourceRect.right) / 2, start);
        case 3:
          _context.next = 4;
          return page.mouse.down();
        case 4:
          _t = mode;
          _context.next = _t === DRAG_TYPE.DOT_TO_DOT ? 5 : _t === DRAG_TYPE.STEPS ? 8 : 13;
          break;
        case 5:
          _context.next = 6;
          return page.mouse.move((targetRect.left + targetRect.right) / 2, end);
        case 6:
          _context.next = 7;
          return justWait(1000);
        case 7:
          return _context.abrupt("continue", 13);
        case 8:
          unit = end > start ? stepUnit : -stepUnit;
          steps = Math.abs(Math.round((end - start) / unit));
          i = 0;
        case 9:
          if (!(i < steps)) {
            _context.next = 12;
            break;
          }
          _context.next = 10;
          return page.mouse.move((targetRect.left + targetRect.right) / 2, start + unit * (i + 1), {
            steps: 1
          });
        case 10:
          _context.next = 11;
          return justWait(200);
        case 11:
          i++;
          _context.next = 9;
          break;
        case 12:
          return _context.abrupt("continue", 13);
        case 13:
          _context.next = 14;
          return page.mouse.up();
        case 14:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
}

var drag = /*#__PURE__*/Object.freeze({
    __proto__: null,
    get DRAG_TYPE () { return DRAG_TYPE; },
    dragElement: dragElement
});

export { DRAG_TYPE as D, dragElement as a, drag as d };
