import { queenApi } from "queenjs";
import { Provider } from "queenjs/adapter/vue";
import { createApp, defineComponent } from "vue";
import { Router } from "vue-router";
import "../../styles/tree";

let setModuleHooks: any[] = [];

const App = defineComponent(() => {
  setModuleHooks.forEach((hook) => hook());
  setModuleHooks = [];
  return () => (
    <Provider>
      <router-view></router-view>
    </Provider>
  );
});

export function startApp(
  router: Router,
  hooks: any[] = [],
  callback?: (app: ReturnType<typeof createApp>) => void
) {
  setModuleHooks = hooks;
  queenApi.router = router;
  const app = createApp(App);
  callback?.(app);
  app.use(router).mount("#app");
}
