import QuizAnswerer from "@/components/QuizAnswerer";
import { Root, createRoot } from "react-dom/client";


export class ContainerWidget {
    root: Root | undefined;

    constructor({ selector, quizId }: {
        quizId: string;
        selector: string;
    }) {
        const element = document.getElementById(selector);
        if (!element) throw new Error("Element for widget doesn't exist");

        this.root = createRoot(element);

        this.root.render(
            <QuizAnswerer
                quizId={quizId}
                changeFaviconAndTitle={false}
                disableGlobalCss
            />
        );
    }

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