import QuizAnswerer from "@/components/QuizAnswerer";
import { createRoot } from "react-dom/client";
// eslint-disable-next-line react-refresh/only-export-components
export * from "./widgets";

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

    const root = createRoot(element);

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

export default widget;
