import ElementPlus from "element-plus";
import "element-plus/dist/index.css";

import format from "./lib/format.js";

import mButton from "./components/MButton";
import mTable from "./components/MTable";
import mPagination from "./components/MPagination";
// 组件列表
const components = [mButton, mTable, mPagination];

// 定义 install 方法，接收 Vue 作为参数。如果使用 use 注册插件，那么所有的组件都会被注册
const install = (Vue) => {
  Vue.use(ElementPlus);
  // 判断是否安装
  if (install.installed) return;
  // 遍历注册全局组件
  components.map((component) => Vue.component(component.name, component));
  // TODO 全局过滤器
  Vue.config.globalProperties.$filters = format;
};

if (typeof window !== "undefined" && window.Vue) {
  install(window.Vue);
}

export default {
  install,
  mButton,
  mTable,
  mPagination,
};
