"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.nestableListBaseUniDriverFactory = exports.default = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _dragAndDropDriverFactory = require("../utils/DragAndDrop/dragAndDropDriverFactory");
var _unidriver = require("../utils/test-utils/unidriver");
var _constants = require("./constants");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var nestableListBaseUniDriverFactory = (base, body) => {
  var dndProviderBase = (0, _unidriver.findByHook)(base, _constants.dataHooks.provider);
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(dndProviderBase, body)), {}, {
    /**
     * reorder nestable list items by data-hook
     * @param {ReorderDataHooks} dataHooks { dataHookFrom: string, dataHookTo: string }
     * @return {Promise<void>}
     */

    reorder: function () {
      var _reorder = (0, _asyncToGenerator2.default)(function* (_ref) {
        var {
          dataHookFrom,
          dataHookTo
        } = _ref;
        var baseEl = yield dndProviderBase.getNative();
        var dragAndDropDriver = (0, _dragAndDropDriverFactory.dragAndDropDriverFactory)({
          base: dndProviderBase,
          element: baseEl
        });
        yield dragAndDropDriver.beginDrag({
          dataHook: dataHookFrom
        });
        yield dragAndDropDriver.dragOver({
          dataHook: dataHookTo
        });
        yield dragAndDropDriver.endDrag({
          dataHook: dataHookTo
        });
      });
      function reorder(_x) {
        return _reorder.apply(this, arguments);
      }
      return reorder;
    }(),
    /**
     * change nestable list item depth
     * @param {NestableItemDetails} nestableItemDetails { dataHook: string, depthLevel: number, threshold?: number }
     * @return {Promise<void>}
     */

    changeItemDepth: function () {
      var _changeItemDepth2 = (0, _asyncToGenerator2.default)(function* (_ref2) {
        var {
          dataHook,
          depthLevel,
          threshold = 30
        } = _ref2;
        return (0, _dragAndDropDriverFactory.changeItemDepth)({
          dataHook,
          depthLevel,
          threshold,
          dragAndDropDriver: (0, _dragAndDropDriverFactory.dragAndDropDriverFactory)({
            base: dndProviderBase,
            element: yield dndProviderBase.getNative()
          })
        });
      });
      function changeItemDepth(_x2) {
        return _changeItemDepth2.apply(this, arguments);
      }
      return changeItemDepth;
    }(),
    /**
     * get nestable list item position
     * @param itemDetails { dataHook: string }
     * @return {Promise<void>}
     */

    getItemPosition: function () {
      var _getItemPosition = (0, _asyncToGenerator2.default)(function* (_ref3) {
        var {
          dataHook
        } = _ref3;
        return (0, _dragAndDropDriverFactory.dragAndDropDriverFactory)({
          base: dndProviderBase
        }).getItemPosition({
          dataHook
        });
      });
      function getItemPosition(_x3) {
        return _getItemPosition.apply(this, arguments);
      }
      return getItemPosition;
    }(),
    /**
     * get nestable list item depth
     * @param itemDetails { dataHook: string }
     * @return {Promise<void>}
     */

    getItemDepth: function () {
      var _getItemDepth = (0, _asyncToGenerator2.default)(function* (_ref4) {
        var {
          dataHook
        } = _ref4;
        return (0, _dragAndDropDriverFactory.dragAndDropDriverFactory)({
          base: dndProviderBase
        }).getItemDepth({
          dataHook
        });
      });
      function getItemDepth(_x4) {
        return _getItemDepth.apply(this, arguments);
      }
      return getItemDepth;
    }()
  });
};
exports.nestableListBaseUniDriverFactory = nestableListBaseUniDriverFactory;
var _default = exports.default = nestableListBaseUniDriverFactory;
//# sourceMappingURL=NestableListBase.uni.driver.js.map