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

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

let App;
if (
  browser.detectChrome() ||
  browser.detectSafari() ||
  browser.detectFirefox() ||
  browser.detectEdge() ||
  browser.detectWeixin() ||
  browser.detectWeixinMiniProgram() ||
  browser.detectAlipay() ||
  browser.detectTT()
) {
  App = ShowMobile;
} 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.mount("#app");
});
