import "@/assets/scss/theme.scss";

import i18n, { getLocale, setI18nLanguage, loadLocaleMessages } from "../i18n";
import Components from "@/global_components";
import Show from "./show.vue";
import { createApp } from "vue";
import Checkbrowser from '@/components/assembly/Checkbrowser.vue'
import ClickOutSide from "../utils/fns/ClickOutSide";
import ToolTip from "../utils/fns/ToolTip";
import VueLazyLoad from 'vue3-lazyload'
import browser from "../utils/browser";
import Deferred from "@/utils/Deferred";
import store from '../store'


let App;
if (
  browser.detectChrome() ||
  browser.detectSafari() ||
  browser.detectFirefox() ||
  browser.detectEdge() ||
  browser.detectWeixin() ||
  browser.detectWeixinMiniProgram() ||
  browser.detectAlipay() || 
  browser.detectTT()
) {
  App = Show;
} else {
  App = Checkbrowser
}

const local = getLocale();


loadLocaleMessages(i18n, local).then(() => {
  setI18nLanguage(i18n, local);

  const app = (window.__app = createApp(App));
  app.locked = null;
  app.lock = function () {
    app.locked = Deferred();
    return app.locked;
  };

  app.unlock = function () {
    if (app.locked) {
      app.locked.resolve();
      app.locked = null;
    }
  };

  app.use(i18n);
  app.use(store);
  app.use(Components);
  app.use(VueLazyLoad);
  app.directive("click-outside", ClickOutSide);
  app.directive("tooltip", ToolTip);
  app.mount("#app");
});
