import { AppIcuPicker } from "./apps/icu-upc-picker/App";
import { main as mintedMain } from "./apps/minted-upc-picker/util";
import { addStyles, mountApp } from "./setupRoot";

import sharedStylesheet from "./_common/styles/shared.css?inline";
import { sleep } from "./_common/util";
import { Question } from "./_common/util/surveyUtil";
import { FloatingActionBar } from "./apps/floating-action-bar/FloatingActionBar";
import { AppIcuPickerT3277 } from "./apps/icu-upc-picker-t3277/App";
import { AppIcuPickerT3312 } from "./apps/icu-upc-picker-t3312/App";
import { AppMintedUpcPicker } from "./apps/minted-upc-picker/App";
import { main as noveltyFillerMain } from "./apps/noveltyPlanoOosFiller/util";

declare global {
  interface Window {
    Question: typeof Question;
  }
}

window["Question"] = Question;

// const ROOT_ELEMENT = setupRoot();
addStyles(sharedStylesheet);

export async function icuPicker() {
  const toggleModalEvent = new CustomEvent("toggle-icu-picker-event");
  mountApp(AppIcuPicker, "icu-picker", toggleModalEvent);
  await sleep(100);
}

export function icuPickerT3277() {
  const appName = "icu-t3277-picker";
  const toggleModalEvent = new CustomEvent(`toggle-${appName}-picker-event`);
  mountApp(AppIcuPickerT3277, appName, toggleModalEvent);
}

export async function icuPickerT3312() {
  const appName = "icu-t3312-picker";
  const toggleModalEvent = new CustomEvent(`toggle-${appName}-picker-event`);
  mountApp(AppIcuPickerT3312, appName, toggleModalEvent);

  await sleep(100);
}

export async function mintedUpcPicker() {
  const appName = "minted-upc-picker";
  const toggleModalEvent = new CustomEvent(`toggle-${appName}-picker-event`);

  mountApp(AppMintedUpcPicker, appName, toggleModalEvent);
  void mintedMain(toggleModalEvent);

  await sleep(100);
}

export function noveltyPlanoOosFiller(allUpcs: string[]) {
  void noveltyFillerMain(allUpcs);
}

export function floatingActionBar() {
  console.clear();

  const toggleModalEvent = new CustomEvent("toggle-floating-action-bar-event");
  mountApp(FloatingActionBar, "floating-action-bar", toggleModalEvent);
}
