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

export default {
    components: { Moveable },
    setup() {
        const maxWidth = "$preview_maxWidth";
        const maxHeight = "$preview_maxHeight";
        const minWidth = "$preview_minWidth";
        const minHeight = "$preview_minHeight";
        const resizable = "$preview_resizable";
        const keepRatio = "$preview_keepRatio";
        const throttleResize = "$preview_throttleResize";
        const renderDirections = "$preview_renderDirections";
        const targetRef = ref(null);
        const onResize = e => {
            e.target.style.width = `${e.width}px`;
            e.target.style.height = `${e.height}px`;
            e.target.style.transform = e.drag.transform;
        };
        return {
            targetRef,
            maxWidth,
            maxHeight,
            minWidth,
            minHeight,
            resizable,
            keepRatio,
            throttleResize,
            renderDirections,
            onResize
        };
    }
};
</script>
<template>
    <div class="root">
        <div class="container">
            <div
                class="target"
                ref="targetRef"
                :style="`max-width: ${maxWidth};max-height: ${maxHeight};min-width: ${minWidth};min-height: ${minHeight};`"
            >Target</div>
            <Moveable
                :target="targetRef"
                :resizable="resizable"
                :keepRatio="keepRatio"
                :throttleResize="throttleResize"
                :renderDirections="renderDirections"
                @resize="onResize"/>
        </div>
    </div>
</template>