import Vue from 'vue'
import PortalVue from 'portal-vue'

import SdPickerSourceList from '@/common/components/sd-picker-source-list.vue'
import SdPickerSourceTree from '@/common/components/sd-picker-source-tree.vue'
import SdAttachmentEx from '@/common/components/sd-attachment-ex.vue'
import SdDataTable from '@/common/components/sd-table/sd-data-table-mixin'
import SdHeader from '@/common/components/sd-header.vue'
import SdHeaderUserAction from '@/common/components/sd-header-user-action.vue'
import '@/common'
import '@/login'
import loginService from '@/login/login-service'
import { sdSessionStorage } from '@/common/services/storage-service'
import antd from '../node_modules/ant-design-vue'

import './flow-service-mock'
// 即使是生产环境，也允许使用调试工具
Vue.config.devtools = true

Vue.use(PortalVue)
Vue.use(antd)
// 以下几个组件找不到，手动注册一下
Vue.component('sd-picker-source-list', SdPickerSourceList)
Vue.component('sd-picker-source-tree', SdPickerSourceTree)
Vue.component('sd-attachment-ex', SdAttachmentEx)
Vue.component('sd-header', SdHeader)
Vue.component('sd-header-user-action', SdHeaderUserAction)
// mock 路由数据，避免组件报错
Vue.prototype.$route = {
  fullPath: '/sd-webflow/pages/draft/404',
  hash: '',
  params: { type: 'pages', mode: 'draft', id: '404' },
  path: '/sd-webflow/pages/draft/404',
  query: {},
}

// 默认5行，节省空间
SdDataTable.props.pagination.default = () => ({ pageSize: 5 })

// 设置token过期后的用户名
sdSessionStorage.setItem('loginName', 'baiwei')

const loginPromise = loginService
  .doLogin('baiwei', '1')
  .then(() => Promise.all([loginService.getUserInfo(), loginService.getUserPerms()]))

export { loginPromise }
