import { Root, createRoot } from "react-dom/client";
import QuizSideButton from "./QuizSideButton";
import { ComponentPropsWithoutRef } from "react";


export class SideWidget {
    root: Root | undefined;
    element = document.createElement("div");

    constructor({ quizId, position }: ComponentPropsWithoutRef<typeof QuizSideButton>) {
        this.element.style.setProperty("display", "none");
        document.body.appendChild(this.element);

        this.root = createRoot(this.element);

        this.root.render(
            <QuizSideButton
                quizId={quizId}
                position={position}
            />
        );
    }

    destroy() {
        if (this.root) this.root.unmount();
        this.element.remove();
    }
}
