<template>
    <div class="main">
        <div class="main-head">
            <!-- <span class="main-head-title"> {{ logo }} OOIN智能知识库</span> -->
            <div class="main-head-title">
                <img src="../../assets/company-logo.svg" alt="COIN Logo" class="header-logo">
                 <span>OOIN智能知识库</span>
            </div>
            <!-- <img src="../../assets/logo-icon.png" alt="" class="logo"> -->
            <div class="right">
                <!-- <a-icon type="search" class="icon-ball" />
                <a-icon type="bell" class="icon-ball" /> -->
                <img src="../../assets/avatar.png" alt="" class="icon-user">
                <a-dropdown>
                    <a class="ant-dropdown-link" @click="e => e.preventDefault()">
                        {{ userName }}
                        <!-- Marci Fumons  -->
                        <!-- <a-icon type="down" /> -->
                    </a>

                    <a-menu slot="overlay">
                        <a-menu-item>
                            <a href="javascript:;" @click="handleLogout">退出登陆</a>
                        </a-menu-item>
                    </a-menu>

                   <!--<a-menu slot="overlay">
                        <a-menu-item>
                            <a href="javascript:;">退出登陆</a>
                        </a-menu-item>
                        <a-menu-item>
                            <a href="javascript:;">消息</a>
                        </a-menu-item>
                    </a-menu> -->
                </a-dropdown>
            </div>
        </div>
        <div class="main-con">
            <div class="main-left">
                <div class="main-menu">
                    <a-menu style="width: 100%" :default-selected-keys="['1']" :default-open-keys="['sub1']"
                        mode="inline" :selected-keys="[current]" @click="handleClick">
                        <a-menu-item key="1" @click="changeMenu('list')">
                            <div class="icon icon-profile" :class="current == '1' ? 'active' : ''"></div>
                            <!-- <a-icon type="profile" /> -->
                            知识库
                        </a-menu-item>
                        <a-menu-item key="2" @click="changeMenu('setting')">
                            <div class="icon icon-setting" :class="current == '2' ? 'active' : ''"></div>
                            设置
                        </a-menu-item>
                    </a-menu>
                </div>
                <!-- <div class="main-left-footer">
                    <img src="../../assets/logout.png" class="logout"/>
                    <p class="logout-title">退出</p>
                </div> -->
            </div>

            <div class="main-con-right">
                <router-view />
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            current: '1',
            logo: process.env.NODE_LOGO,
            userName: '',
            userRole: '',
            userToken: ''
        }
    },
    created() {
        // Get user info from localStorage
        this.userName = localStorage.getItem('userName') || '';
        this.userRole = localStorage.getItem('userRole') || '';
        this.userToken = localStorage.getItem('userToken') || '';
        
        // If no user info, redirect to login
        if (!this.userToken) {
            this.$router.push('/login');
        }
    },
    methods: {
        changeMenu(route) {
            if (this.$route.path !== route) {
                this.$router.push(route)
            }
        },
        handleClick(e) {
            console.log('click ', e);
            this.current = e.key;
        },
        handleLogout() {
            // Clear user info from localStorage
            localStorage.removeItem('userToken');
            localStorage.removeItem('userName');
            localStorage.removeItem('userRole');
            
            // Redirect to login page
            this.$router.push('/login');
        }
    },
}
</script>

<!-- <script>
export default {
    data() {
        return {
            current: '1',
            logo:process.env.NODE_LOGO
        }
    },
    created() {
    },
    methods: {
        //路由内容切换
        changeMenu(route) {
            if (this.$route.path !== route) {
                //获取路由对象并切换
                this.$router.push(route)
            }
        },
        handleClick(e) {
            console.log('click ', e);
            this.current = e.key;
        },
    },
}
</script> -->

<style lang="less" scoped>
.main {
    background-color: #000000; //添加整体背景颜色
    height: 100%;
    width: 100%;

    .main-head {
        display: flex;
        justify-content: space-between;
        border-bottom: 1px solid #27272a; //添加底部边框
        padding: 0 50px;
        box-sizing: border-box;
        height: 60px;
        background-color: #18181b; //添加header背景颜色
        .main-head-title{
            display: flex;
            align-items: center;
            font-size: 32px;
            font-weight: 600;
            color: #ef4444; //更改标题颜色
            line-height: 60px;

            .header-logo {
            width: 110px;  
            height: 110px;  
            margin-right: 12px;
            }
        }

        .logo {
            // background: url('../../assets/logo-icon.png') no-repeat center center;
            // background-size: 100% 100%;
            width: 110px;
            height: 34px;
            margin-top: 13px;
        }

        .right {
            margin-top: 14px;

            .icon-ball {
                font-size: 16px;
                margin-right: 28px;
            }

            .icon-user {
                width: 32px;
                height: 32px;
                border-radius: 50%;
                margin-right: 12px;
            }

        }
    }

    .main-con {
        display: flex;
        flex: 1;
        // flex-direction: column;
        height: 100%;
        height: calc(100% - 60px);
        background-color: #18181b; //添加主要版块背景颜色

        .main-left {
            height: 100%;
            width: 283px;
            display: flex;
            border-right: 1px solid #27272a; //添加右侧边框
            flex-direction: column;
            background-color: #18181b; //添加左侧背景颜色

            //add new styles
            /deep/ .ant-menu {
                background-color: #18181b !important;
            }
            /deep/ .ant-menu-item {
                color: #a1a1aa !important;

                &:hover {
                    color: #ffffff !important;
                    background-color: #27272a !important;
                }

                &.ant-menu-item-selected {
                    background-color: #27272a !important;
                    color: #ef4444 !important;
                }
            }

            // /deep/ .ant-menu-item {
            //     color: #a1a1aa !important;
            //     background-color: #27272a !important;
            // }

            .main-menu {
                flex: 1;
                padding-top: 52px;
                width: 283px;
                text-align: left;
                .ant-menu-inline .ant-menu-item {
                    width: 100%;
                    border: none !important;
                    font-family: Poppins, Poppins;
                    font-weight: 500;
                    font-size: 16px;
                    color: #a1a1aa; //更改字体颜色
                    line-height: 24px;
                    height: 24px;
                    display: flex;
                    align-items: center;
                    padding-left: 58px !important;
                    background: transparent; //更改背景颜色
                    margin-bottom: 14px;

                    .anticon {
                        font-size: 16px !important;
                    }

                    .icon {
                        width: 20px;
                        height: 20px;
                        margin-right: 12px;
                        cursor: pointer;
                    }

                    .icon-profile {
                        background: url('../../assets/dateset.png') no-repeat center center;
                        background-size: 100% 100%;

                        &.active,
                        &:hover {
                            background: url('../../assets/dateset-active.png') no-repeat center center;
                            background-size: 100% 100%;
                        }
                    }

                    .icon-setting {
                        background: url('../../assets/settings.png') no-repeat center center;
                        background-size: 100% 100%;

                        &.active,
                        &:hover {
                            background: url('../../assets/settings-active.png') no-repeat center center;
                            background-size: 100% 100%;
                        }
                    }
                }

                .ant-menu-item-active {
                    color: #ef4444 !important; //更改选中颜色
                }

                .ant-menu-item-selected {
                    color: #ef4444 !important; //更改选中颜色
                    height: 24px !important;
                    border-right: #27272a !important; //更改选中边框颜色
                }
            }

            .main-left-footer {
                height: 40px;
                display: flex;
                align-items: center;
                margin:0 auto 40px;
                cursor: pointer;
                .logout{
                    width: 24px;
                    height: 24px;
                    margin-right: 8px;
                }
                .logout-title{
                    font-family: Poppins, Poppins;
                    font-weight: 500;
                    font-size: 16px;
                    color: #CE4F51; //changed color
                    line-height: 24px;
                    text-align: left;
                    font-style: normal;
                    margin:0
                }
                
            }
        }



        .main-con-right {
            flex: 1;
            padding: 0 56px 0 30px;
            background-color: #000000; //添加右侧背景颜色
        }
    }
}
</style>