import Vue from 'vue'
import App from './App.vue'
import 'element-ui/lib/theme-chalk/index.css';
import VueRouter from 'vue-router'
import OverView from './modules/overview/Homepage'
import LogManage from './modules/log/LogList'
import ServerManage from './modules/server/ServerList'
import ProjectManage from './modules/project/ProjectList'
import DataPackage from "./modules/dataPackage/DataPackage";
// import TaskManage from './modules/task/MainFrame'
import CommonTaskTab from "@/modules/task/CommonTaskList";
import SingleWebsiteTaskTab from "@/modules/task/SingleWebsiteTaskList";
// import TargetManage from './modules/targets/MainFrame'
// import TemplateManage from './modules/rules/MainFrame'
import TargetWebsiteSettings from './modules/targets/WebsiteSetting'
import WebsiteTab from "@/modules/targets/WebsiteList";
import SocialUserManage from "@/modules/targets/SocialList";
import SensitiveTab from "@/modules/targets/SensitiveList";
import ParserTab from "@/modules/rules/ParserTab";
import FilterTab from "@/modules/rules/FilterTab";
import ApiTab from "@/modules/targets/ApiList";
import login from './modules/login'
import Index from './modules/Index'
import store from './js'
import cookieUtil from './util/CookieUtil'
import LogDetail from './modules/log/LogDetail'
// import SystemSettings from './modules/settings/MainFrame'
import MetaDataTab from "@/modules/settings/MetaDataList";
import MetaDictTab from "@/modules/settings/MetaDictList";
import WordBankTab from "@/modules/settings/WordBankList";
import {library} from '@fortawesome/fontawesome-svg-core'
import {faWeibo, faTwitter, faFacebook} from '@fortawesome/free-brands-svg-icons'
import {faRetweet, faDatabase, faFilePdf} from "@fortawesome/free-solid-svg-icons";
import {faMessage, faThumbsUp, faStar, faPenToSquare, faTrashCan} from "@fortawesome/free-regular-svg-icons";
import {FontAwesomeIcon} from '@fortawesome/vue-fontawesome'
import ApiWebsiteSetting from "@/modules/targets/ApiWebsiteSetting.vue";

library.add(faWeibo, faTwitter, faFacebook)
library.add(faRetweet, faMessage, faThumbsUp, faStar, faDatabase, faPenToSquare, faFilePdf, faTrashCan)
Vue.component('font-awesome-icon', FontAwesomeIcon)
Vue.use(VueRouter)
Vue.config.productionTip = false
const routes = [
    {
        path: '/oscm', component: Index,
        children: [
            {path: '', component: OverView, meta: {keepAlive: true}},
            {path: 'home', component: OverView, meta: {keepAlive: true}},
            {path: 'server', component: ServerManage, meta: {keepAlive: true}},
            {path: 'project', component: ProjectManage, meta: {keepAlive: true}},
            // {path: 'task', component: TaskManage, meta: {keepAlive: true}},
            {path: 'task/common', component: CommonTaskTab, meta: {keepAlive: true}},
            {path: 'task/single', component: SingleWebsiteTaskTab, meta: {keepAlive: true}},
            {path: 'log/:taskid', component: LogManage, meta: {keepAlive: true}, props: true},
            {path: 'log', component: LogManage, meta: {keepAlive: true}},
            // {path: 'target', component: TargetManage, meta: {keepAlive: true}},
            {path: 'target/website', component: WebsiteTab, meta: {keepAlive: true}},
            {path: 'target/social', component: SocialUserManage, meta: {keepAlive: true}},
            {path: 'target/sensitive', component: SensitiveTab, meta: {keepAlive: true}},
            {path: 'target/api', component: ApiTab, meta: {keepAlive: true}},
            {path: 'target/website/settings', component: TargetWebsiteSettings, meta: {keepAlive: true}},
            {path: 'target/api/settings', component: ApiWebsiteSetting, meta: {keepAlive: true}},
            // {path: 'rules', component: TemplateManage, meta: {keepAlive: true}},
            {path: 'rules/parser', component: ParserTab, meta: {keepAlive: true}},
            {path: 'rules/filter', component: FilterTab, meta: {keepAlive: true}},
            {path: 'log/detail/:jobid', component: LogDetail, meta: {keepAlive: false}, props: true},
            // {path: 'settings', component: SystemSettings, meta: {keepAlive: true}},
            {path: 'settings/metaData', component: MetaDataTab, meta: {keepAlive: true}},
            {path: 'settings/metaDict', component: MetaDictTab, meta: {keepAlive: true}},
            {path: 'settings/wordBank', component: WordBankTab, meta: {keepAlive: true}},
            {path: 'data-package', component: DataPackage, meta: {keepAlive: true}}
        ]
    },
    {path: '/oscm/login', component: login}
]
const router = new VueRouter({
    mode: 'history',
    // mode: 'hash',
    routes
})
router.beforeEach((to, from, next) => {
    let isLogin = false
    let userInfo = cookieUtil.getCookie("oscm_user")
    if (userInfo && userInfo.length > 0) {
        isLogin = true
    }
    if (to.path === '/oscm/login') {
        next();
        return;
    }
    if (isLogin) {
        next()
    } else {
        next({path: '/oscm/login'});
    }


    // if(isLogin){
    //   if(to.path == '/oscm/login'){
    //     next({ path: '/oscm/' })
    //   }else{
    //     next()
    //   }
    // }else{
    //   if(to.path == '/oscm/login'){
    //     next()
    //   }else{
    //     next({ path: '/oscm/login' })
    //   }
    // }
})
new Vue({
    render: h => h(App),
    router,
    store
}).$mount('#app')
