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

import "./i18n/i18nWidget";

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

    const root = createRoot(element);

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

export default widget;
