<script>
import Moveable, { MoveableManagerInterface, Renderer } from "vue-moveable";

const Editable = {
    name: "editable",
    props: [],
    events: [],
    render(moveable, React) {
        const rect = moveable.getRect();
        const { pos2 } = moveable.state;
        const EditableViewer = moveable.useCSS("div", `
        {
            position: absolute;
            left: 0px;
            top: 0px;
            will-change: transform;
            transform-origin: 0px 0px;
        }
        .custom-button {
            width: 24px;
            height: 24px;
            margin-bottom: 4px;
            background: #4af;
            border-radius: 4px;
            appearance: none;
            border: 0;
            color: white;
            font-weight: bold;
        }
            `);
        return React.createElement(EditableViewer, {
            key: "editable-viewer",
            className: "moveable-editable",
            style: {
                transform: `translate(${pos2[0]}px, ${pos2[1]}px) rotate(${rect.rotation}deg) translate(10px)`
            }
        }, [
            "\r\n            ",
            React.createElement("button", {
                className: "custom-button",
                onClick: () => {
                    alert("+");
                }
            }, [
                "+"
            ]),
            "\r\n            ",
            React.createElement("button", {
                className: "custom-button",
                onClick: () => {
                    alert("-");
                }
            }, [
                "-"
            ]),
            "\r\n        "
        ]);
    }
};
export default {
    components: { Moveable },
    data() {
        const targetRef = null;
        return { targetRef };
    },
    methods: {
        onDrag(e) {
            e.target.style.transform = e.transform;
        },
        onResize(e) {
            e.target.style.width = `${e.width}px`;
            e.target.style.height = `${e.height}px`;
            e.target.style.transform = e.drag.transform;
        },
        onRotate(e) {
            e.target.style.transform = e.drag.transform;
        }
    },
    mounted() {
        this.targetRef = this.$refs.targetRef;
    }
};
</script>
<template>
    <div class="container">
        <div
            class="target"
            ref="targetRef"
        >Target</div>
        <Moveable
            :target="targetRef"
            :ables="[Editable]"
            :props="({ editable: true })"
            :draggable="true"
            :resizable="true"
            :rotatable="true"
            @drag="onDrag"
            @resize="onResize"
            @rotate="onRotate"/>
    </div>
</template>