import config from "./config"
import api from './api'
import tools from './utils/tools'
import { permission, rolePermission } from './utils/permission'

import piTable from './components/piTable'
import piTableColumn from './components/piTable/column.js'
import piFilterBar from './components/piFilterBar'
import piUpload from './components/piUpload'
import piUploadMultiple from './components/piUpload/multiple'
import piUploadFile from './components/piUpload/file'
import piFormTable from './components/piFormTable'
import piTableSelect from './components/piTableSelect'
import piPageHeader from './components/piPageHeader'
import piSelect from './components/piSelect'
import piDialog from './components/piDialog'
import piForm from './components/piForm'
import piTitle from './components/piTitle'
import piWaterMark from './components/piWaterMark'
import piQrCode from './components/piQrCode'

import piStatusIndicator from './components/piMini/piStatusIndicator'
import piTrend from './components/piMini/piTrend'

import auth from './directives/auth'
import auths from './directives/auths'
import authsAll from './directives/authsAll'
import role from './directives/role'
import time from './directives/time'
import copy from './directives/copy'
import errorHandler from './utils/errorHandler'

import * as elIcons from '@element-plus/icons-vue'
import * as piIcons from "@/assets/icons";

export default {
	install(app) {
		//挂载全局对象
		app.config.globalProperties.$CONFIG = config;
		app.config.globalProperties.$TOOLS = tools;
		app.config.globalProperties.$API = api;
		app.config.globalProperties.$AUTH = permission;
		app.config.globalProperties.$ROLE = rolePermission;

		//注册全局组件
		app.component('piTable', piTable);
		app.component('piTableColumn', piTableColumn);
		app.component('piFilterBar', piFilterBar);
		app.component('piUpload', piUpload);
		app.component('piUploadMultiple', piUploadMultiple);
		app.component('piUploadFile', piUploadFile);
		app.component('piFormTable', piFormTable);
		app.component('piTableSelect', piTableSelect);
		app.component('piPageHeader', piPageHeader);
		app.component('piSelect', piSelect);
		app.component('piDialog', piDialog);
		app.component('piForm', piForm);
		app.component('piTitle', piTitle);
		app.component('piWaterMark', piWaterMark);
		app.component('piQrCode', piQrCode);
		app.component('piStatusIndicator', piStatusIndicator);
		app.component('piTrend', piTrend);

		//注册全局指令
		app.directive('auth', auth)
		app.directive('auths', auths)
		app.directive('auths-all', authsAll)
		app.directive('role', role)
		app.directive('time', time)
		app.directive('copy', copy)

		//统一注册el-icon图标
		for(let icon in elIcons){
			app.component(`ElIcon${icon}`, elIcons[icon])
		}
		for(let icon in piIcons.default){
			app.component(`PiIcon${icon}`, piIcons.default[icon])
		}
		//关闭async-validator全局控制台警告
		window.ASYNC_VALIDATOR_NO_WARNING = 1

		//全局代码错误捕捉
		app.config.errorHandler = errorHandler
	}
}
