import { getArrValue } from 'js-fast-way'

export default class HcTopMenu {

    // 基础菜单
    static baseMenu = [
        'home', 'home-index', 'home-index-static', 'home-config', 'order-service', 'user-index', '403', '404', '500',
    ]

    static initMenu({ routes, menu, load, change }) {
        const topName = routes.matched[0]?.name
        if (this.baseMenu.includes(topName)) {
            load(topName)
            return false
        }
        for (let i = 0; i < menu.length; i++) {
            if (menu[i].code === topName) {
                change(topName, menu[i])
            }
        }
    }

    static async setMenuItem(item) {
        return getArrValue(item?.children)
    }
}
