<script>
import Moveable from "vue3-moveable";
import { ref } from "vue";

export default {
    components: { Moveable },
    setup() {
        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 snapGridWidth = "$preview_snapGridWidth";
        const snapGridHeight = "$preview_snapGridHeight";
        const isDisplayGridGuidelines = "$preview_isDisplayGridGuidelines";
        const targetRef = ref(null);
        const moveableRef = ref(null);
        const onDrag = e => {
            e.target.style.transform = e.transform;
        };
        const onScale = e => {
            e.target.style.transform = e.drag.transform;
        };
        return {
            targetRef,
            moveableRef,
            draggable,
            throttleDrag,
            edgeDraggable,
            startDragRotate,
            throttleDragRotate,
            scalable,
            keepRatio,
            throttleScale,
            snappable,
            snapGridWidth,
            snapGridHeight,
            isDisplayGridGuidelines,
            onDrag,
            onScale
        };
    }
};
</script>
<template>
    <div class="root">
        <div
            class="container"
            style="width: 500px;height: 500px;border: 1px solid #ccc;"
        >
            <div
                class="target"
                ref="targetRef"
                style="width: 200px;height: 150px;"
            >Target</div>
            <Moveable
                ref="moveableRef"
                :target="targetRef"
                :draggable="draggable"
                :throttleDrag="throttleDrag"
                :edgeDraggable="edgeDraggable"
                :startDragRotate="startDragRotate"
                :throttleDragRotate="throttleDragRotate"
                :scalable="scalable"
                :keepRatio="keepRatio"
                :throttleScale="throttleScale"
                :snappable="snappable"
                :snapGridWidth="snapGridWidth"
                :snapGridHeight="snapGridHeight"
                :isDisplayGridGuidelines="isDisplayGridGuidelines"
                @drag="onDrag"
                @scale="onScale"/>
        </div>
    </div>
</template>