<script>
import Moveable from "vue-moveable";

export default {
    components: { Moveable },
    data() {
        const draggable = "$preview_draggable";
        const throttleDrag = "$preview_throttleDrag";
        const edgeDraggable = "$preview_edgeDraggable";
        const startDragRotate = "$preview_startDragRotate";
        const throttleDragRotate = "$preview_throttleDragRotate";
        const resizable = "$preview_resizable";
        const keepRatio = "$preview_keepRatio";
        const snappable = "$preview_snappable";
        const bounds = "$preview_bounds";
        const edge = "$preview_edge";
        const targetRef = null;
        const moveableRef = null;
        return {
            draggable,
            throttleDrag,
            edgeDraggable,
            startDragRotate,
            throttleDragRotate,
            resizable,
            keepRatio,
            snappable,
            bounds,
            edge,
            targetRef,
            moveableRef
        };
    },
    methods: {
        onDrag(e) {
            e.target.style.transform = e.transform;
        },
        onResize(e) {
            e.target.style.width = `${e.width}px`;
            e.target.style.height = `${e.height}px`;
            e.target.style.transform = e.drag.transform;
        },
        onBound(e) {
            console.log(e);
        }
    },
    mounted() {
        this.targetRef = this.$refs.targetRef;
        this.moveableRef = this.$refs.moveableRef;
    }
};
</script>
<template>
    <div class="root">
        <div
            class="container"
            style="width: 500px;height: 500px;border: 1px solid #ccc;"
        >
            <div
                class="target"
                ref="targetRef"
            >Target</div>
            <Moveable
                ref="moveableRef"
                :target="targetRef"
                :draggable="draggable"
                :throttleDrag="throttleDrag"
                :edgeDraggable="edgeDraggable"
                :startDragRotate="startDragRotate"
                :throttleDragRotate="throttleDragRotate"
                :resizable="resizable"
                :keepRatio="keepRatio"
                :snappable="snappable"
                :bounds="bounds"
                :edge="edge"
                @drag="onDrag"
                @resize="onResize"
                @bound="onBound"/>
        </div>
    </div>
</template>