<template>
    <hc-body padding="0px" scrollbar>
        <el-menu :collapse="isCollapse" :default-active="curKey" class="hc-aside-menu" unique-opened text-color="#fff">
            <MenuItem :collapse="isCollapse" :cur="curKey" :datas="datas" :msg-count="msgCount" @change="MenuClick" />
        </el-menu>
    </hc-body>
</template>

<script setup>
import { ref, watch } from 'vue'
import MenuItem from './MenuItem.vue'

const props = defineProps({
    datas: {
        type: Array,
        default: () => ([]),
    },
    cur: {
        type: String,
        default: 'home-index',
    },
    collapse: {
        type: Boolean,
        default: false,
    },
    msgCount: {
        type: Object,
        default: () => ({}),
    },
})

//事件
const emit = defineEmits(['change'])

//初始变量
const curKey = ref(props.cur)
const isCollapse = ref(props.collapse)

//监听
watch(() => [
    props.cur,
    props.collapse,
], ([cur, collapse]) => {
    curKey.value = cur
    isCollapse.value = collapse
})

//处理菜单数据
const setMenuItem = async (item) => {
    curKey.value = item?.code || ''
    emit('change', item)
}

//菜单被点击
const MenuClick = (item) => {
    setMenuItem(item)
}
</script>
