import { CanvasView } from "../../../../../view/elements/CanvasView.js";
import EmptyView from "../../../../../view/elements/EmptyView.js";
import sampler2D2Canvas from "../sampler2d_to_html_canvas.js";

export function debug_draw_sampler(engine, sampler, x = 0, y = 0) {

    const view = new CanvasView();
    view.size.set(sampler.width, sampler.height);
    sampler2D2Canvas(sampler, 1, 0, view.el);

    view.css({
        position: 'absolute',
        top: "0",
        left: "0"
    });

    const container = new EmptyView({
        css: {
            position: 'absolute',
            top: `${y}px`,
            left: `${x}px`
        }
    });
    container.size.set(sampler.width, sampler.height);
    container.addChild(view);

    engine.gameView.addChild(container);

    container.$redraw = () => {
        sampler2D2Canvas(sampler, 1, 0, view.el);
    };

    return container;
}