<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 scalable = "$preview_scalable";
        const keepRatio = "$preview_keepRatio";
        const throttleScale = "$preview_throttleScale";
        const snappable = "$preview_snappable";
        const snapDirections = "$preview_snapDirections";
        const elementSnapDirections = "$preview_elementSnapDirections";
        const snapThreshold = "$preview_snapThreshold";
        const verticalGuidelines = "$preview_verticalGuidelines";
        const horizontalGuidelines = "$preview_horizontalGuidelines";
        const snapContainer = "$preview_snapContainer";
        const bounds = "$preview_bounds";
        const targetRef = null;
        const moveableRef = null;
        return {
            draggable,
            throttleDrag,
            edgeDraggable,
            startDragRotate,
            throttleDragRotate,
            scalable,
            keepRatio,
            throttleScale,
            snappable,
            snapDirections,
            elementSnapDirections,
            snapThreshold,
            verticalGuidelines,
            horizontalGuidelines,
            snapContainer,
            bounds,
            targetRef,
            moveableRef
        };
    },
    methods: {
        onDrag(e) {
            e.target.style.transform = e.transform;
        },
        onScale(e) {
            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"
        style="position: relative;border: 1px solid black;"
    >
        <div
            class="container"
            style="position: relative;top: 50px;left: 50px;border: 1px solid red;width: 500px;height: 500px;"
        >
            <div
                class="snapContainer"
                style="position: relative;top: 50px;left: 50px;border: 1px solid #ccc;width: 400px;height: 400px;transform: scale(0.7, 0.7);"
            >
                <div
                    class="target"
                    ref="targetRef"
                    style="width: 200px;height: 150px;transform: translate(0px, 0px) scale(1.5, 1);"
                >Target</div>
            </div>
            <Moveable
                ref="moveableRef"
                :target="targetRef"
                :draggable="draggable"
                :throttleDrag="throttleDrag"
                :edgeDraggable="edgeDraggable"
                :startDragRotate="startDragRotate"
                :throttleDragRotate="throttleDragRotate"
                :scalable="scalable"
                :keepRatio="keepRatio"
                :throttleScale="throttleScale"
                :snappable="snappable"
                :snapDirections="snapDirections"
                :elementSnapDirections="elementSnapDirections"
                :snapThreshold="snapThreshold"
                :verticalGuidelines="verticalGuidelines"
                :horizontalGuidelines="horizontalGuidelines"
                :snapContainer="snapContainer"
                :bounds="bounds"
                @drag="onDrag"
                @scale="onScale"
                @bound="onBound"/>
        </div>
    </div>
</template>