import * as React from "react";
import Moveable from "@/react-moveable";

export default function App(props: Record<string, any>) {
    const targetRef = React.useRef<HTMLDivElement>(null);
    const moveableRef = React.useRef<Moveable>(null);

    return (
        <div className="root">
            <div className="container" style={{
                left: "200px",
                top: "100px",
                width: "500px",
                height: "500px",
                border: "1px solid #ccc",
            }}>
                <div className="target element1" style={{
                    width: "100px",
                    height: "100px",
                    left: "0px",
                    top: "120px",
                }}>Element1</div>
                <div className="target element2" style={{
                    width: "100px",
                    height: "100px",
                    left: "400px",
                    top: "120px",
                }}>Element2</div>
                <div className="target element3" style={{
                    width: "300px",
                    height: "100px",
                    top: "400px",
                    left: "50px",
                }}>Element3</div>
                <div className="target" ref={targetRef} style={{
                    width: "150px",
                    height: "150px",
                }}>Target</div>
                <Moveable
                    ref={moveableRef}
                    target={targetRef}
                    draggable={true}
                    scalable={true}
                    rotatable={true}
                    snappable={props.snappable}
                    isDisplaySnapDigit={props.isDisplaySnapDigit}
                    isDisplayInnerSnapDigit={props.isDisplayInnerSnapDigit}
                    snapGap={props.snapGap}
                    snapDirections={props.snapDirections}
                    elementSnapDirections={props.elementSnapDirections}
                    snapThreshold={props.snapThreshold}
                    maxSnapElementGuidelineDistance={props.maxSnapElementGuidelineDistance}
                    elementGuidelines={[".element1", ".element2", ".element3"]}
                    onRender={e => {
                        e.target.style.cssText += e.cssText;
                    }}
                    onSnap={e => {
                        console.log(e.guidelines, e.elements);
                    }}
                />
            </div>
        </div>
    );
}
