<template>
    <div class="leftMenu">
        <a-menu
            theme="dark"
            mode="inline"
            class="left-menu"
            v-model:selectedKeys="selectedKeys"
            v-model:openKeys="openKeys"
            @click="menuClick"
        >
            <a-sub-menu v-for="item in menuList" :key="item.key">
                <template #title>
                    <span>
                        <span class="menu-item_title" v-show="!collapsed">{{ item.title }}</span>
                    </span>
                </template>
                <a-menu-item :key="subItem.key" v-for="subItem in item.children">
                    <span>{{ subItem.title }}</span>
                </a-menu-item>
            </a-sub-menu>
        </a-menu>
    </div>
</template>

<script lang="ts">
import { defineComponent, ref, PropType, SetupContext } from 'vue';
import { MenuList } from '@/services/go/ermcp/goodsInfo/interface';

// 菜单栏
const handleMenu = (context: SetupContext, path: string) => {
    const collapsed = ref<boolean>(false);
    const selectedKeys = ref<string[]>(['1-0']);
    const openKeys = ref<string[]>([path]);

    function menuClick(value: any) {
        const is = value.keyPath.includes(path) ? true : false;
        context.emit('chooseMenu', { key: value.key, is });
    }
    return { collapsed, selectedKeys, openKeys, menuClick };
};

export default defineComponent({
    name: 'leftMenu',
    props: {
        menuList: {
            default: [],
            type: Object as PropType<MenuList[]>,
        },
        path: {
            default: 'goods_info_spot_normal',
            type: String,
        },
    },
    components: {},
    setup(props, context) {
        const { collapsed, selectedKeys, openKeys, menuClick } = handleMenu(context, props.path);

        return {
            menuClick,
            collapsed,
            selectedKeys,
            openKeys,
        };
    },
});
</script>

<style lang="less">
.leftMenu {
    height: 100%;
    ul.ant-menu.ant-menu-inline {
        background-color: transparent;
        li.ant-menu-submenu {
            padding-bottom: 0;
            .ant-menu-submenu-title {
                color: @m-grey2;
                font-size: 16px;
                height: 45px;
                line-height: 45px;
                margin-top: 0;
                margin-bottom: 0;
                padding: 0;
                padding-left: 32px !important;
                .icon {
                    font-size: 20px;
                }
                .menu-item_title {
                    display: inline-block;
                    font-size: 16px;
                    color: @m-grey2;
                }
                .ant-menu-submenu-arrow {
                    left: 12px;
                    color: @m-white0;
                }
            }
            .ant-menu-inline.ant-menu-sub {
                background-color: transparent !important;
                box-shadow: none;
                .ant-menu-item {
                    padding-left: 64px !important;
                    height: 30px;
                    line-height: 30px;
                    color: @m-grey2;
                    font-size: 14px;
                    margin-top: 0;
                    margin-bottom: 0;
                    padding-right: 0;
                }
            }
        }
        li.ant-menu-submenu-open {
            .ant-menu-submenu-title {
                color: @m-white0;
                .icon {
                    color: @m-white0;
                }
            }
            .ant-menu-sub {
                .ant-menu-item.ant-menu-item-selected {
                    color: @m-blue0;
                    background-color: transparent;
                }
            }
        }
    }
}
.ant-menu-vertical {
    .ant-menu-submenu-vertical {
        height: 60px;
        line-height: 60px;
        padding: 5px 0;
        .ant-menu-submenu-title {
            height: 50px;
            line-height: 50px;
            .icon {
                font-size: 20px;
            }
        }
    }
    .ant-menu-submenu {
        .ant-menu-submenu-title {
            .menu-item_title {
                display: none;
            }
        }
    }
}
</style
>;
