import { createApp } from "vue";
import App from "./App.vue";
import store from "./store";
import router from "./router";

import "./styles/common.scss";

import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import zhCn from "element-plus/es/locale/lang/zh-cn";

import "./permission";

import basicContainer from "./components/basic-container/main.vue";
import Pagination from "./components/Pagination/index.vue";

const app = createApp(App);

const debounce = (fn: any, delay: any) => {
  let timer: any;
  return (...args: any) => {
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(() => {
      fn(...args);
    }, delay);
  };
};

const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
  constructor(callback: any) {
    callback = debounce(callback, 200);
    super(callback);
  }
};

app.component("basicContainer", basicContainer);
app.component("Pagination", Pagination);

app.use(store);
app.use(router);
app.use(ElementPlus, {
  locale: zhCn
});
app.mount("#app");
