"use strict";

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

var _resolution = require("@enact/ui/resolution");

var _Arranger = require("@enact/ui/ViewManager/Arranger");

var _Breadcrumb = require("./Breadcrumb");

var quadInOut = 'cubic-bezier(0.455, 0.030, 0.515, 0.955)';
var animationOptions = {
  easing: quadInOut
}; // Actvity Arranger

/*
 * Appends a transform that accounts for a single breadcrumb
 *
 * @param  {Node} node      DOM Node
 *
 * @returns {undefined}
 * @private
 */

var offsetForBreadcrumbs = function offsetForBreadcrumbs(node) {
  var isFirst = node && node.dataset && node.dataset.index === '0';
  return "translateX(".concat(isFirst ? 0 : (0, _resolution.unit)((0, _resolution.scale)(_Breadcrumb.breadcrumbWidth), 'rem'), ")");
};
/**
 * Arranger that slides panels in from the right and out to the left allowing space for the single
 * breadcrumb when `to` index is greater than zero.
 *
 * @type {Arranger}
 * @private
 */


var PanelsArranger = {
  enter: function enter(config) {
    var node = config.node;
    return (0, _Arranger.arrange)(config, [{
      transform: "".concat(offsetForBreadcrumbs(node), " translateX(100%)")
    }, {
      transform: offsetForBreadcrumbs(node)
    }], animationOptions);
  },
  leave: function leave(config) {
    var node = config.node;
    return (0, _Arranger.arrange)(config, [{
      transform: offsetForBreadcrumbs(node)
    }, {
      transform: 'translateX(-100%)'
    }], animationOptions);
  },
  stay: function stay(config) {
    var node = config.node;
    return (0, _Arranger.arrange)(config, [{
      transform: offsetForBreadcrumbs(node)
    }, {
      transform: offsetForBreadcrumbs(node)
    }], animationOptions);
  }
};
/**
 * Positions a breadcrumb based on its `data-index` and the current index, `to`
 *
 * @param  {Object} config  Arrangement configuration object
 * @returns {undefined}
 * @method
 * @private
 */

exports.PanelsArranger = PanelsArranger;

var positionBreadcrumb = function positionBreadcrumb(node, index) {
  var crumbIndex = node.dataset.index;
  var x = index - crumbIndex;
  var percentX = x * -100;
  return "translateX(".concat(percentX, "%)");
};

var enter = function enter(config) {
  var node = config.node,
      from = config.from,
      to = config.to,
      reverse = config.reverse;
  var keyframes = reverse ? [{
    transform: positionBreadcrumb(node, to)
  }, {
    transform: positionBreadcrumb(node, from)
  }] : [{
    transform: positionBreadcrumb(node, from)
  }, {
    transform: positionBreadcrumb(node, to)
  }];
  return (0, _Arranger.arrange)(config, keyframes, animationOptions);
};
/**
 * Arranger for panel breadcrumbs
 *
 * @type {Arranger}
 * @private
 */


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