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

export default {
    components: { Moveable },
    data() {
        const hideChildMoveableDefaultLines = "$preview_hideChildMoveableDefaultLines";
        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 throttleResize = "$preview_throttleResize";
        const renderDirections = "$preview_renderDirections";
        const rotatable = "$preview_rotatable";
        const throttleRotate = "$preview_throttleRotate";
        const rotationPosition = "$preview_rotationPosition";
        const minWidth = "$preview_minWidth";
        const minHeight = "$preview_minHeight";
        const maxWidth = "$preview_maxWidth";
        const maxHeight = "$preview_maxHeight";
        const moveableRef = null;
        return {
            hideChildMoveableDefaultLines,
            draggable,
            throttleDrag,
            edgeDraggable,
            startDragRotate,
            throttleDragRotate,
            resizable,
            keepRatio,
            throttleResize,
            renderDirections,
            rotatable,
            throttleRotate,
            rotationPosition,
            minWidth,
            minHeight,
            maxWidth,
            maxHeight,
            moveableRef
        };
    },
    methods: {
        onClick() {
            this.$refs.moveableRef.updateRect();
        },
        onDragGroup({ events }) {
            events.forEach(ev => {
                ev.target.style.transform = ev.transform;
            });
        },
        onResizeGroupStart({ setMin, setMax }) {
            setMin([this.minWidth, this.minHeight]);
            setMax([this.maxWidth, this.maxHeight]);
        },
        onResizeGroup({ events }) {
            events.forEach(ev => {
                ev.target.style.width = `${ev.width}px`;
                ev.target.style.height = `${ev.height}px`;
                ev.target.style.transform = ev.drag.transform;
            });
        },
        onRotateGroup({ events }) {
            events.forEach(ev => {
                ev.target.style.transform = ev.drag.transform;
            });
        }
    },
    mounted() {
        this.moveableRef = this.$refs.moveableRef;
    }
};
</script>
<template>
    <div class="container">
        <button @click="onClick">Resize</button>
        <div class="target target1">Target1</div>
        <div
            class="target target2"
            style="min-width: 50px;min-height: 50px;"
        >Target2</div>
        <div class="target target3">Target3</div>
        <Moveable
            ref="moveableRef"
            :target="'.target'"
            :hideChildMoveableDefaultLines="hideChildMoveableDefaultLines"
            :draggable="draggable"
            :throttleDrag="throttleDrag"
            :edgeDraggable="edgeDraggable"
            :startDragRotate="startDragRotate"
            :throttleDragRotate="throttleDragRotate"
            :resizable="resizable"
            :keepRatio="keepRatio"
            :throttleResize="throttleResize"
            :renderDirections="renderDirections"
            :rotatable="rotatable"
            :throttleRotate="throttleRotate"
            :rotationPosition="rotationPosition"
            @dragGroup="onDragGroup"
            @resizeGroupStart="onResizeGroupStart"
            @resizeGroup="onResizeGroup"
            @rotateGroup="onRotateGroup"/>
    </div>
</template>