import { getTokenInfo } from '@/assets/utils/code.js'

// token
let defaultAccessToken = ''
try {
    if (localStorage.teacherToken) {
        defaultAccessToken = localStorage.teacherToken
    }
} catch (e) {}

let userInfo = {}
try {
    if (localStorage.teacherUserInfo) {
        userInfo = JSON.parse(localStorage.teacherUserInfo)
    } else if (defaultAccessToken) {
        let token = getTokenInfo(defaultAccessToken)
        userInfo = { ...token, UserId: token.jti }
    }
} catch (e) {}

// expireTime
let defaultExpireTime = ''
try {
    if (localStorage.teacherExpireTime) {
        defaultExpireTime = localStorage.teacherExpireTime
    }
} catch (e) {}
// openId
let defaultOpenId = 'oiw-oiw-aswIOBMOz0qywTZApOmIVaKg'
try {
    if (localStorage.storeOpenId) {
        defaultOpenId = localStorage.storeOpenId
    }
} catch (e) {}
// companyId
let defaultCompanyId = '60315ee1-a798-4e3a-9116-0c656854578d'
try {
    if (localStorage.storeCompanyId) {
        defaultCompanyId = localStorage.storeCompanyId
    }
} catch (e) {}
// schoolCode
let defaultSchoolCode = '10086'
try {
    if (localStorage.storeSchoolCode) {
        defaultSchoolCode = localStorage.storeSchoolCode
    }
} catch (e) {}
// 教师组织架构存储
let defaultTeahcerOrgList = []
try {
    if (localStorage.teacherOrgList) {
        defaultTeahcerOrgList = localStorage.teacherOrgList
    }
} catch (e) {}

let dailySignUserPermission = {
    is_daily_sign_manager: false,
    is_appeal_manager: false,
    is_open_log: false,
    is_outside_manager: false
}

export default {
    userInfo,
    access_token: defaultAccessToken,
    tokenPayload: getTokenInfo(defaultAccessToken),
    tokenInfo: getTokenInfo(defaultAccessToken, true),
    expireTime: defaultExpireTime,
    openId: defaultOpenId,
    companyId: defaultCompanyId,
    schoolCode: defaultSchoolCode,
    teahcerOrgList: defaultTeahcerOrgList,
    dailySignUserPermission
}
