var t = require("../common/component"), i = require("../mixins/touch");

(0, t.VantComponent)({
    props: {
        disabled: Boolean,
        leftWidth: {
            type: Number,
            value: 0
        },
        rightWidth: {
            type: Number,
            value: 0
        },
        asyncClose: Boolean
    },
    mixins: [ i.touch ],
    data: {
        catchMove: !0
    },
    created: function() {
        this.offset = 0;
    },
    methods: {
        open: function(t) {
            var i = this.data, s = i.leftWidth, e = i.rightWidth, n = "left" === t ? s : -e;
            this.swipeMove(n);
        },
        close: function() {
            this.swipeMove(0);
        },
        swipeMove: function() {
            var t = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : 0, i = "translate3d(" + (this.offset = t) + "px, 0, 0)", s = this.draging ? "none" : ".6s cubic-bezier(0.18, 0.89, 0.32, 1)";
            this.set({
                wrapperStyle: "\n        -webkit-transform: " + i + ";\n        -webkit-transition: " + s + ";\n        transform: " + i + ";\n        transition: " + s + ";\n      "
            });
        },
        swipeLeaveTransition: function() {
            var t = this.data, i = t.leftWidth, s = t.rightWidth, e = this.offset;
            0 < s && .3 * s < -e ? this.open("right") : 0 < i && .3 * i < e ? this.open("left") : this.swipeMove(0);
        },
        startDrag: function(t) {
            this.data.disabled || (this.draging = !0, this.startOffset = this.offset, this.firstDirection = "", 
            this.touchStart(t));
        },
        noop: function() {},
        onDrag: function(t) {
            if (!this.data.disabled && (this.touchMove(t), this.firstDirection || (this.firstDirection = this.direction, 
            this.set({
                catchMove: "horizontal" === this.firstDirection
            })), "vertical" !== this.firstDirection)) {
                var i = this.data, s = i.leftWidth, e = i.rightWidth, n = this.startOffset + this.deltaX;
                0 < e && e < -n || 0 < s && s < n || this.swipeMove(n);
            }
        },
        endDrag: function() {
            this.data.disabled || (this.draging = !1, this.swipeLeaveTransition());
        },
        onClick: function(t) {
            var i = t.currentTarget.dataset.key, s = void 0 === i ? "outside" : i;
            this.$emit("click", s), this.offset && (this.data.asyncClose ? this.$emit("close", {
                position: s,
                instance: this
            }) : this.swipeMove(0));
        }
    }
});