import config from "./config"
import api from './api'
import tool from './utils/tool'
import http from "./utils/request"
import { permission, rolePermission } from './utils/permission'


import scSelect from './components/scSelect'
import scDialog from './components/scDialog'
import scDesigner from './components/scDesigner'
import scDesignerDrag from './components/scDesigner/drag'
import scDesignerForm from './components/scDesigner/form'
import scDesignerStyle from './components/scDesigner/style'
import scDesignerPattern from './components/scDesigner/pattern'
import scDesignerProperty from './components/scDesigner/property'
import scDesignerSetting from './components/scDesigner/setting'
import scDesignerTaskDrag from './components/scDesigner/taskDrag'
import scDesignerShowForm from './components/scDesigner/showForm'
import scDesignerTableDrag from './components/scDesigner/tableDrag'
import scDesignerHeader from './components/scDesigner/header'
import scDesignerFooter from './components/scDesigner/footer'

import auth from './directives/auth'
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 scIcons from './assets/icons'

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

		//注册全局组件
		app.component('scSelect', scSelect);
		app.component('scDialog', scDialog);
		app.component('scDesigner', scDesigner);
		app.component('scDesignerDrag', scDesignerDrag);
		app.component('scDesignerForm', scDesignerForm);
		app.component('scDesignerStyle', scDesignerStyle);
		app.component('scDesignerPattern', scDesignerPattern);
		app.component('scDesignerProperty', scDesignerProperty);
		app.component('scDesignerSetting', scDesignerSetting);
		app.component('scDesignerTaskDrag', scDesignerTaskDrag);
		app.component('scDesignerShowForm', scDesignerShowForm);
		app.component('scDesignerTableDrag', scDesignerTableDrag);
		app.component('scDesignerHeader', scDesignerHeader);
		app.component('scDesignerFooter', scDesignerFooter);

		//注册全局指令
		app.directive('auth', auth)
		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])
		}
		//统一注册sc-icon图标
		for(let icon in scIcons){
			app.component(`ScIcon${icon}`, scIcons[icon])
		}

		//关闭async-validator全局控制台警告
		window.ASYNC_VALIDATOR_NO_WARNING = 1

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