<template>
    <el-menu class="hc-aside-menu" :default-active="curKey" :collapse="isCollapse" unique-opened>
        <!-- <el-menu-item index="home-index" @click="MenuClick({code: 'home-index'})">
            <div class="hc-aside-menu-item">
                <div class="menu---item">
                    <HcIcon name="home-3" :fill="curKey === 'home-index'" class="hc-menu-icon"/>
                    <div class="name">数据看板</div>
                </div>
            </div>
        </el-menu-item> -->
        <MenuItem :datas="datas" :cur="curKey" :collapse="isCollapse" @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?.code || '';
    emit('change', item)
}
</script>

<style lang="scss">
.el-menu.hc-aside-menu {
    --el-menu-bg-color: initial;
    --el-menu-text-color: #838791;
    --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;
    margin-left: -10px;
    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 30px !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;
            .menu---item {
                display: contents;
            }
            .hc-menu-icon {
                font-size: 22px;
                margin-right: 10px;
                line-height: initial;
            }
            .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.hc-icon-i {
        position: relative;
        display: inline-block;
        font-size: 16px;
        right: 15px;
        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: 0 2px 8px 0 var(--hc-shadow-color-5);
            &::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 {
    margin-left: 0;
    width: 100px;
    .el-sub-menu__title {
        height: inherit;
        line-height: initial;
        width: 100px;
        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: 100px;
        transition: 0.2s;
        .hc-aside-menu-item {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 60px;
            height: 60px;
            text-align: center;
            border-radius: 10px;
            padding: 5px;
            flex: initial;
            transition: 0.2s;
            .menu---item {
                position: relative;
                display: block;
            }
            .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: -20px;
                right: -24px;
            }
        }
    }
    .el-sub-menu .el-icon.hc-icon-i {
        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 {
            color: #ffffff !important;
            background: linear-gradient(90deg,var(--el-color-primary-light-5), var(--el-color-primary) 100%);
            box-shadow: 0 2px 8px 0 var(--hc-shadow-color-5);
            &::before, &::after {
                content: '';
                display: none;
            }
        }
    }
}
.aside-menu-popper.el-popper.is-light {
    background: initial !important;
    border: 0 !important;
}
.aside-menu-popper.el-popper .el-menu--vertical .el-menu {
    --el-menu-bg-color: #f1f5f8;
    --el-menu-text-color: #838791;
    --el-menu-active-color: #ffffff;
    --el-menu-hover-bg-color: initial;
    --el-menu-item-font-size: 16px;
    background-color: #f1f5f8;
    color: #838791;
    .el-sub-menu__title {
        padding: 0;
        justify-content: center;
        transition: 0.2s;
    }
    .el-menu-item, .el-sub-menu {
        color: inherit;
        padding: 0;
        transition: 0.2s;
        .hc-aside-menu-item {
            flex: 1;
            position: relative;
            padding: 0 16px;
            display: flex;
            align-items: center;
            transition: 0.2s;
            .menu---item {
                display: contents;
            }
            .hc-menu-icon {
                font-size: 22px;
                margin-right: 10px;
                line-height: initial;
            }
            .name {
                flex: 1;
                width: 0;
            }
            .el-badge, .el-badge .el-badge__content {
                vertical-align: initial;
            }
        }
        &.is-active {
            color: white;
        }
    }
    .el-sub-menu .el-icon {
        display: none;
    }
    .el-sub-menu .el-icon.hc-icon-i {
        position: relative;
        display: inline-block;
        font-size: 16px;
        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);
    }
}

.aside-menu-popper.el-popper .el-menu--vertical.home-index .el-menu {
    --el-menu-bg-color: initial;
    --el-menu-text-color: initial;
    color: white;
    background-color: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(4px);
}
</style>
