import { SideWidgetParams } from "@/model/widget/side";
import { Root, createRoot } from "react-dom/client";
import QuizSideButton from "./QuizSideButton";

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

  constructor(props: SideWidgetParams) {
    this.element.style.setProperty("display", "none");
    document.body.appendChild(this.element);

    this.root = createRoot(this.element);

    this.render(props);
  }

  render(props: SideWidgetParams) {
    this.root?.render(<QuizSideButton {...props} />);
  }

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