import React, {useEffect, useRef, useState} from "react";
import "../../style/player.css";
import Draggable, {ControlPosition, DraggableBounds} from "react-draggable";

export default function Player({id, x, y, bounds}: {
    id: number,
    x: number,
    y: number,
    bounds: DraggableBounds
}) {

    const ref = useRef<HTMLDivElement>();
    useEffect(() => {
        const playerRect = ref.current?.getBoundingClientRect();
        bounds.bottom -= playerRect.height / 2;
        bounds.right -= playerRect.width / 2;
    }, [ref])

    return (
        <Draggable
            nodeRef={ref}
            bounds={bounds}
            defaultPosition={{x: x, y: y}}>
            <div ref={ref}
                 className="player"
                 style={{
                     position: "absolute",
                 }}>
                <p>{id}</p>
            </div>
        </Draggable>

    )
}