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

export default {
    components: { Moveable },
    setup() {
        const snappable = "$preview_snappable";
        const isDisplaySnapDigit = "$preview_isDisplaySnapDigit";
        const isDisplayInnerSnapDigit = "$preview_isDisplayInnerSnapDigit";
        const snapGap = "$preview_snapGap";
        const snapDirections = "$preview_snapDirections";
        const elementSnapDirections = "$preview_elementSnapDirections";
        const snapThreshold = "$preview_snapThreshold";
        const maxSnapElementGuidelineDistance = "$preview_maxSnapElementGuidelineDistance";
        const targetRef = ref(null);
        const moveableRef = ref(null);
        const onRender = e => {
            e.target.style.cssText += e.cssText;
        };
        const onSnap = e => {
            console.log(e.guidelines, e.elements);
        };
        return {
            targetRef,
            moveableRef,
            snappable,
            isDisplaySnapDigit,
            isDisplayInnerSnapDigit,
            snapGap,
            snapDirections,
            elementSnapDirections,
            snapThreshold,
            maxSnapElementGuidelineDistance,
            onRender,
            onSnap
        };
    }
};
</script>
<template>
    <div class="root">
        <div
            class="container"
            style="left: 200px;top: 100px;width: 500px;height: 500px;border: 1px solid #ccc;"
        >
            <div
                class="target element1"
                style="width: 100px;height: 100px;left: 0px;top: 120px;"
            >Element1</div>
            <div
                class="target element2"
                style="width: 100px;height: 100px;left: 400px;top: 120px;"
            >Element2</div>
            <div
                class="target element3"
                style="width: 300px;height: 100px;top: 400px;left: 50px;"
            >Element3</div>
            <div
                class="target"
                ref="targetRef"
                style="width: 150px;height: 150px;"
            >Target</div>
            <Moveable
                ref="moveableRef"
                :target="targetRef"
                :draggable="true"
                :scalable="true"
                :rotatable="true"
                :snappable="snappable"
                :isDisplaySnapDigit="isDisplaySnapDigit"
                :isDisplayInnerSnapDigit="isDisplayInnerSnapDigit"
                :snapGap="snapGap"
                :snapDirections="snapDirections"
                :elementSnapDirections="elementSnapDirections"
                :snapThreshold="snapThreshold"
                :maxSnapElementGuidelineDistance="maxSnapElementGuidelineDistance"
                :elementGuidelines="['.element1', '.element2', '.element3']"
                @render="onRender"
                @snap="onSnap"/>
        </div>
    </div>
</template>