<template>
    <el-menu class="hc-aside-menu" :default-active="curKey" :collapse="isCollapse" unique-opened>
        <el-menu-item index="home-index">
            <div class="hc-aside-menu-item">
                <HcIcon name="home" class="hc-menu-icon" :ui="curKey === 'home-index'?'fill':''"/>
                <div class="name">首页</div>
            </div>
        </el-menu-item>
        <MenuItem :datas="datas" :cur="curKey" @change="MenuClick"/>
    </el-menu>
</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
    },
})

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

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

//事件
const emit = defineEmits(['change'])
const MenuClick = (item) => {
    curKey.value = item?.key || '';
    emit('change', item)
}
</script>

<style lang="scss">
.hc-aside-menu.el-menu {
    --el-menu-bg-color: #333333;
    --el-menu-text-color: #ffffff;
    --el-menu-active-color: #ffffff;
    --el-menu-hover-text-color: var(--el-color-primary);
    --el-menu-hover-bg-color: initial;
    --el-menu-item-font-size: 16px;
    --el-menu-item-height: 48px;
    border-right: 0;
    padding: 8px 0;
    &.el-menu--vertical:not(.el-menu--collapse):not(.el-menu--popup-container) .el-menu-item,
    &.el-menu--vertical:not(.el-menu--collapse):not(.el-menu--popup-container) .el-menu-item-group__title,
    &.el-menu--vertical:not(.el-menu--collapse):not(.el-menu--popup-container) .el-sub-menu__title {
        white-space: nowrap;
        padding-left: 0;
    }
    .el-sub-menu__title {
        padding: 0;
    }
    .el-menu-item, .el-sub-menu {
        padding: 15px 0 0 20px !important;
        min-width: initial;
        transition: 0.2s;
        .hc-aside-menu-item {
            flex: 1;
            position: relative;
            border-radius: 50px 0 0 50px;
            padding: 0 16px;
            display: flex;
            align-items: center;
            transition: 0.2s;
            .hc-menu-icon {
                font-size: 22px;
                margin-right: 10px;
            }
            .name {
                flex: 1;
                width: 0;
            }
            .el-badge, .el-badge .el-badge__content {
                vertical-align: initial;
            }
        }
    }
    .el-sub-menu .el-icon {
        display: none;
    }
    .el-sub-menu .el-icon.material-symbols-rounded {
        position: relative;
        display: inline-block;
        font-size: 38px;
        right: 10px;
        top: initial;
        height: initial;
        width: initial;
        margin-top: 0;
        vertical-align: initial;
    }
    .el-sub-menu .el-sub-menu__title .hc-aside-menu-item:hover,
    .el-menu-item:not(.is-active) .hc-aside-menu-item:hover {
        color: var(--el-color-primary);
    }
    .el-sub-menu.is-active > .el-sub-menu__title > .hc-aside-menu-item {
        color: var(--el-color-primary);
    }
    .el-menu-item.is-active {
        .hc-aside-menu-item {
            --radius-size: 20px;
            background-color: var(--el-color-primary);
            box-shadow: 4px 4px 8px 0 rgba(0, 0, 0, 0.3), 0 -6px 8px 0 #707070;
            &::before, &::after {
                content: '';
                display: block;
                height: var(--radius-size);
                width: var(--radius-size);
                position: absolute;
                background: radial-gradient(
                        var(--radius-size) at var(--radius-size) 0px,
                        transparent var(--radius-size),
                        var(--el-color-primary) var(--radius-size)
                );
            }
            &::before {
                right: 0;
                transform: scaleX(-1);
                top: calc(-1 * var(--radius-size));
                z-index: 999;
            }
            &::after {
                right: 0;
                bottom: calc(-1 * var(--radius-size));
                transform: scale(-1);
                z-index: 999;
            }
        }
    }
}
.hc-aside-menu.el-menu--collapse {
    width: 120px;
    .el-sub-menu__title {
        height: inherit;
        line-height: initial;
        width: 120px;
        justify-content: center;
        transition: 0.2s;
    }
    .el-menu-item, .el-sub-menu {
        padding: 0 !important;
        height: 60px;
        line-height: initial;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 120px;
        transition: 0.2s;
        .hc-aside-menu-item {
            display: block;
            align-items: initial;
            width: 60px;
            height: 60px;
            text-align: center;
            border-radius: 10px;
            padding: 5px;
            flex: initial;
            transition: 0.2s;
            .hc-menu-icon {
                margin-right: 0;
            }
            .name {
                flex: initial;
                width: 100%;
            }
            .el-badge, .el-badge .el-badge__content {
                vertical-align: initial;
            }
            .el-badge {
                position: absolute;
                top: -12px;
                right: -10px;
            }
        }
    }
    .el-sub-menu .el-icon.material-symbols-rounded {
        display: none;
    }
    .el-menu-item + .el-menu-item,
    .el-menu-item + .el-sub-menu,
    .el-sub-menu + .el-menu-item,
    .el-sub-menu + .el-sub-menu {
        margin-top: 24px;
    }
    .el-sub-menu:not(.is-active):hover,
    .el-menu-item:not(.is-active):hover {
        .hc-aside-menu-item {
            background-color: var(--el-color-primary-light-9);
            color: var(--el-color-primary);
        }
    }
    .el-menu-item.is-active, .el-sub-menu.is-active {
        .hc-aside-menu-item {
            background-color: var(--el-color-primary);
            box-shadow: 3px 3px 6px 0 rgba(0, 0, 0, 0.5), -3px -3px 6px 0 rgba(153, 153, 153, 0.8);
            &::before, &::after {
                content: '';
                display: none;
            }
        }
    }
}
.el-popper.is-light {
    border: 0 !important;
}
.el-popper .el-menu--vertical .el-menu {
    --el-menu-bg-color: #333333;
    --el-menu-text-color: #ffffff;
    --el-menu-active-color: #ffffff;
    --el-menu-hover-bg-color: initial;
    --el-menu-item-font-size: 16px;
    .el-sub-menu__title {
        padding: 0;
        justify-content: center;
        transition: 0.2s;
    }
    .el-menu-item, .el-sub-menu {
        color: #fff;
        padding: 0;
        transition: 0.2s;
        .hc-aside-menu-item {
            flex: 1;
            position: relative;
            padding: 0 16px;
            display: flex;
            align-items: center;
            transition: 0.2s;
            .hc-menu-icon {
                font-size: 22px;
                margin-right: 10px;
            }
            .name {
                flex: 1;
                width: 0;
            }
            .el-badge, .el-badge .el-badge__content {
                vertical-align: initial;
            }
        }
    }
    .el-sub-menu .el-icon {
        display: none;
    }
    .el-sub-menu .el-icon.material-symbols-rounded {
        position: relative;
        display: inline-block;
        font-size: 38px;
        right: 10px;
        top: initial;
        height: initial;
        width: initial;
        margin-top: 0;
        vertical-align: initial;
    }
    .el-sub-menu:not(.is-active) .el-sub-menu__title:hover {
        background-color: var(--el-color-primary-light-9);
        color: var(--el-color-primary);
    }
    .el-menu-item:not(.is-active):hover {
        .hc-aside-menu-item {
            background-color: var(--el-color-primary-light-9);
            color: var(--el-color-primary);
        }
    }
    .el-menu-item.is-active {
        .hc-aside-menu-item {
            background-color: var(--el-color-primary);
        }
    }
    .el-sub-menu.is-active .el-sub-menu__title {
        background-color: var(--el-color-primary-light-9);
        color: var(--el-color-primary);
    }
}
</style>
