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

export const convertToContainerCoordinates = (point: IPoint, containerRef: React.RefObject<HTMLDivElement | null>): IPoint => {
    if (!containerRef) return DEFAULT_MOUSE_POSITION;
    if (!containerRef?.current) return point;

    const containerRect = containerRef.current.getBoundingClientRect();
    console.log('🔧 [convertToContainerCoordinates] Container rect:', {
        left: containerRect.left,
        top: containerRect.top,
        width: containerRect.width,
        height: containerRect.height
    });
    console.log('🔧 [convertToContainerCoordinates] Input point:', point);
    
    const x = point.x - containerRect.left;
    const y = point.y - containerRect.top;
    
    console.log('🔧 [convertToContainerCoordinates] Converted coordinates:', { x, y });

    return { x, y };
};