import create from "../utils/create";
var MIN_SWIPE_DISTANCE = 50;
import TouchMixin from "../mixins/touch";
export default create({
  render: function render() {
    var _vm = this;

    var _h = _vm.$createElement;

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

    return _c('div', _vm._g({
      class: _vm.b('content', {
        animated: this.animated
      })
    }, _vm.listeners), [_vm.animated ? _c('div', {
      class: _vm.b('track'),
      style: _vm.style
    }, [_vm._t("default")], 2) : _vm._t("default")], 2);
  },
  mixins: [TouchMixin],
  name: "content",
  props: {
    count: Number,
    duration: [Number, String],
    animated: Boolean,
    swipeable: Boolean,
    currentIndex: Number
  },
  methods: {
    // 监听滑动触摸结束
    onTouchEnd: function onTouchEnd() {
      var direction = this.direction,
          deltaX = this.deltaX,
          currentIndex = this.currentIndex;
      /* istanbul ignore else */

      if (direction === "horizontal" && this.offsetX >= MIN_SWIPE_DISTANCE) {
        /* istanbul ignore else */
        if (deltaX > 0 && currentIndex !== 0) {
          this.$emit("change", currentIndex - 1);
        } else if (deltaX < 0 && currentIndex !== this.count - 1) {
          this.$emit("change", currentIndex + 1);
        }
      }
    }
  },
  computed: {
    style: function style() {
      if (this.animated) {
        return {
          transform: "translate3d(" + -1 * this.currentIndex * 100 + "%, 0, 0)",
          transitionDuration: this.duration + "s"
        };
      }
    },
    listeners: function listeners() {
      if (this.swipeable) {
        return {
          touchstart: this.touchStart,
          touchmove: this.touchMove,
          touchend: this.onTouchEnd,
          touchcancel: this.onTouchEnd
        };
      }
    }
  }
});