import Vue from 'vue'
import App from './App.vue'
import router from './router'
import 'element-ui/lib/theme-chalk/index.css';
import './assets/css/element-variables.scss'
import './assets/css/common.scss'
import echarts from './utils/echartsUi'
import Keycloak from './utils/keycloak/keycloak'
// import Keycloak from 'keycloak-js'


import {
  Menu,
  Submenu,
  MenuItem,
  Table,
  TableColumn,
  Input,
  Button,
  Pagination,
  DatePicker,
  Row,
  Col,
  Select,
  Option,
  Dialog,
  Message,
  MessageBox,
  Tabs,
  TabPane,
  Tooltip,
  Upload,
  Checkbox,
  CheckboxGroup,
  Popover,
  Tag,
  Popconfirm,
  Alert,
  Form,
  FormItem
} from 'element-ui'

import * as filters from './utils/filters.js'
Object.keys(filters).forEach(key=>{
  Vue.filter(key,filters[key])//插入过滤器名和对应方法
})

Vue.use(Form);
Vue.use(FormItem);
Vue.use(Tabs);
Vue.use(TabPane);
Vue.use(Dialog);
Vue.use(Menu)
Vue.use(Submenu)
Vue.use(MenuItem)
Vue.use(Table)
Vue.use(TableColumn)
Vue.use(Input)
Vue.use(Button)
Vue.use(Pagination)
Vue.use(DatePicker)
Vue.use(Row);
Vue.use(Col);
Vue.use(Select);
Vue.use(Option);
Vue.use(Tooltip);
Vue.use(Upload);
Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Popover);
Vue.use(Tag);
Vue.use(Popconfirm);
Vue.use(Alert);
Vue.config.productionTip = false
Vue.prototype.$message = Message;
Vue.prototype.$confirm = MessageBox.confirm;
Vue.prototype.$prompt = MessageBox.prompt;
Vue.prototype.$echarts = echarts;

// keycloak init options
// const initOptions = {
//   url: 'https://idp.qs.cloudidp.vgcserv.com.cn/auth',
//   realm: 'vgcmfa',
//   clientId: 'EHR-FRONT-QS',
//   onLoad:'login-required'
// }
const initOptions = {
  url: 'http://139.217.94.179:8080/auth',
  realm: 'demo',
  clientId: 'vue-demo',
  onLoad:'login-required'
}

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')


// const keycloak = Keycloak(initOptions);
// keycloak.init({ onLoad: initOptions.onLoad,pkceMethod:'S256',  promiseType: 'native' }).then((authenticated) =>{
//   if(!authenticated) {
//     window.location.reload();
//   } else {
//     Vue.prototype.$keycloak = keycloak;
//   }
//   let token = "Bearer "+ keycloak.token
//   localStorage.setItem('token',  token)
//   setTimeout(() => {
   
//   }, 2000);

// }).catch(error => {
//   console.log('Authenticated Failed', error)
// })


