import * as elIcons from '@element-plus/icons-vue'
import {App} from "vue";
import * as piIcons from '@assets/icons'
import auth from './directives/auth'
import role from './directives/role'
import excludeRole from './directives/excludeRole'
import time from './directives/time'
import copy from './directives/copy'
import drag from './directives/drag'
import errorHandler from "@/utils/errorHandler";

import piDialog from "@/components/piDialog"
import piTable from "@/components/piTable"
import piUpload from "@/components/piUpload"
import piSelect from "@/components/piSelect"
import piImage from "@/components/piImage"
import piIcon from "@/components/piIcon"

export default {
	install(app: App) {
		// 注册全局组件
		app.component('piDialog', piDialog)
		app.component('piTable', piTable)
		app.component('piUpload', piUpload)
		app.component('piSelect', piSelect)
		app.component('piImage', piImage)
		app.component('piIcon', piIcon)

		//注册全局指令
		app.directive('auth', auth)
		app.directive('role', role)
		app.directive('exclude-role', excludeRole)
		app.directive('time', time)
		app.directive('copy', copy)
		app.directive('drag', drag)

		//统一注册el-icon图标
		for (let icon in elIcons) {
			app.component(`ElIcon${icon}`, elIcons[icon])
		}
		//统一注册sc-icon图标
		for (let icon in piIcons.default) {
			app.component(`PiIcon${icon}`, piIcons.default[icon])
		}

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