"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.BreadcrumbArranger = exports.default = void 0;

var _cubicOut = _interopRequireDefault(require("eases/cubic-out"));

var _arrange = require("@enact/ui/ViewManager/arrange");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * Panel arrangers have a unique design requirement that varies their transition depending on the
 * direction (reverse) of the transition. This takes the two arrangement functions and returns
 * another function that picks which to call based on the value of `reverseTransition`.
 *
 * @param {Function} f forward function
 * @param {Function} b backward function
 * @returns {Function} Arrangement function
 * @method
 * @private
 */
var forwardBackward = function forwardBackward(f, b) {
  return function (config) {
    var f2 = config.reverseTransition ? b : f;
    f2(config);
  };
};
/**
 * Positions a breadcrumb based on its `data-index` and the current index, `to`
 *
 * @param  {Object} config  Arrangement configuration object
 * @returns {undefined}
 * @method
 * @private
 */


var positionBreadcrumb = (0, _arrange.ease)(_cubicOut.default, function (config) {
  var _config$from = config.from,
      from = _config$from === void 0 ? 0 : _config$from,
      node = config.node,
      percent = config.percent,
      to = config.to;
  var crumbIndex = node.dataset.index;
  var dx = (to - from) * percent;
  var x = from - crumbIndex;
  var percentX = (x + dx) * -100;
  (0, _arrange.replaceTransform)("translateX(".concat(percentX, "%)"), config);
});
/**
 * Arrangement function for breadcrumbs
 *
 * @param  {Object} config  Arrangement configuration object
 * @returns {undefined}
 * @method
 * @private
 */

var enter = forwardBackward((0, _arrange.startAfter)(0.75, positionBreadcrumb), (0, _arrange.startAfter)(0.5, positionBreadcrumb));
/**
 * Arranger for panel breadcrumbs
 *
 * @type {Arranger}
 * @private
 */

var BreadcrumbArranger = {
  enter: enter,
  stay: enter,
  leave: enter
};
exports.BreadcrumbArranger = BreadcrumbArranger;
var _default = BreadcrumbArranger;
exports.default = _default;