import { IPoint } from "@fullstackcraftllc/codevideo-types";
import { convertToContainerCoordinates } from "./convertToContainerCoordinates";
import { DEFAULT_MOUSE_POSITION } from "src/constants/CodeVideoIDEConstants";

export const getCoordinatesByCodeVideoDataID = (dataId: string, containerRef: React.RefObject<HTMLDivElement | null>): IPoint => {
    if (!containerRef) return DEFAULT_MOUSE_POSITION;
    const fileElement = document.querySelector(`[data-codevideo-id="${dataId}"]`);
    if (!fileElement) {
        console.warn('element with data-codevideo-id not found', dataId);
        return DEFAULT_MOUSE_POSITION;
    }
    console.log(`Looking for element with data-codevideo-id=${dataId}, found:`, fileElement);
    // console.log('fileElement', fileElement);
    const rect = fileElement.getBoundingClientRect();
    return convertToContainerCoordinates({
        x: rect.left + rect.width / 2,
        y: rect.top + rect.height / 2
    }, containerRef);
};