"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

var _create = _interopRequireDefault(require("../utils/create"));

var _relation = require("../mixins/relation");

var _default = (0, _create.default)({
  render: function render() {
    var _vm = this;

    var _h = _vm.$createElement;

    var _c = _vm._self._c || _h;

    return _c('div', _vm._g({
      class: _vm.b(),
      style: _vm.style
    }, _vm.$listeners), [_vm.shouldRender ? _vm._t("default") : _vm._e()], 2);
  },
  name: "swipe-item",
  mixins: [(0, _relation.ChildrenMixin)("vmSwipe")],
  data: function data() {
    return {
      offset: 0,
      mounted: false
    };
  },
  mounted: function mounted() {
    var _this = this;

    this.$nextTick(function () {
      _this.mounted = true;
    });
  },
  computed: {
    style: function style() {
      var style = {};
      var _this$parents = this.parents,
          size = _this$parents.size,
          vertical = _this$parents.vertical;
      style[vertical ? "height" : "width"] = size + "px";

      if (this.offset) {
        style.transform = "translate" + (vertical ? "Y" : "X") + "(" + this.offset + "px)";
      }

      return style;
    },
    shouldRender: function shouldRender() {
      var index = this.index,
          parents = this.parents,
          mounted = this.mounted;

      if (!parents.lazyRender) {
        return true;
      } // wait for all item to mount, so we can get the exact count


      if (!mounted) {
        return false;
      }

      var active = parents.activeIndicator;
      var maxActive = parents.count - 1;
      var prevActive = active === 0 ? maxActive : active - 1;
      var nextActive = active === maxActive ? 0 : active + 1;
      return index === active || index === prevActive || index === nextActive;
    }
  }
});

exports.default = _default;