<script setup lang="ts">
definePageMeta({
    layout: 'home',
    pageTransition: {
        name: 'slide',
        mode: 'out-in',
    },
})
const menuList = ref([]);

const getMenuListFetch = async () => {
    const { data, pending, error } = await useFetch('/api/blog/blogMenu');
    if (error.value) {
        consola.error('数据获取失败:', error.value);
    }
    menuList.value = data.value?.filter(i => i.pid === '0')
}


// SSR运行
await getMenuListFetch()
onMounted(() => {
    consola.log(menuList.value)

})
</script>

<template>
    <div class="homeBlog">
        <ResizeContent class="left">
            <div class="blogMenuContainer">
                <header class="contentBox">
                    <div class="title">博客目录</div>
                    <div class="bar star-blogIconFont awaitShow">&#xe67f;</div>
                </header>
                <div class="line"/>
                <div class="blogMenuContent">
                    <div class="contentBox blogMenuItem" v-for="(item, index) in menuList" :key="item.id">
                        <div class="addIcon star-blogIconFont  a11 allCenter hoverBar">&#xe608;</div>
                        <div class="text oneLineOverMore">{{item.name}}</div>
                        <div class="bar" :class="item.pid === '0' && 'awaistShows'">
                            <div class="star-blogIconFont a11 allCenter hoverBar">&#xe73a;</div>
                            <div class="star-blogIconFont a11 allCenter hoverBar">&#xe608;</div>
                        </div>
                    </div>
                </div>
                <footer></footer>
            </div>
        </ResizeContent>
        <div class="main"></div>
        <div class="right"></div>
    </div>
</template>

<style scoped lang="scss">
.homeBlog {
    position: relative;
    display: flex;
    width: 100%;
    height: 100%;
    overflow: hidden;
    & > div{
        position: relative;
        height: 100%;
        overflow: auto;
    }
    & > div.left{
        flex-shrink: 0;
        overflow: hidden;
        background: var(--blog-menu-background-color);
        border-right: 1px solid var(--bg-color-be);
        .blogMenuContainer{
            position: relative;
            width: 100%;
            height: 100%;
            overflow: hidden;
            font-family: sans-serif;
            display: flex;
            flex-direction: column;
            box-sizing: border-box;
            padding: .5rem;
            & > *{
                position: relative;
                width: 100%;
            }

            .awaitShow{
                height: 0;
                width: 0;
                opacity: 0;
                transition: opacity .3s;
                overflow: hidden;
            }
            &:hover{
                .awaitShow{
                    height: 100%;
                    width: auto;
                    opacity: 1;
                }
            }
            & > header{
                flex-shrink: 0;
                display: flex;
                width: 100%;
                & > div.title{
                    position: relative;
                    flex: 1;
                    color: var(--font-color-top3-h1);
                }
                & > div.bar{
                    position: relative;
                    flex-shrink: 0;
                    height: 100%;
                    aspect-ratio: 1;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    font-size: 1.3rem;
                    color: var(--font-color-top3-h2);
                    transform: rotate(180deg);
                    transition: color .5s, opacity .5s;
                    &:hover{
                        color: var(--font-color-top3-h1);
                    }
                }
            }
            & > footer{
                flex-shrink: 0;
            }
            & > div.line{
                position: relative;
                width: 100%;
                height: 3px;
                margin: 0.5rem auto;
                background-color: var(--bg-color-be);
                border-radius: .25rem;
            }
            & > div.blogMenuContent{
                position: relative;
                flex: 1;
                overflow: hidden;
                & > div.blogMenuItem{
                    position: relative;
                    font-size: 0.9rem;
                    display: flex;
                    & > div{
                        position: relative;
                    }
                    & > div.addIcon{
                        font-size: 1rem;
                        margin-right: .5rem;
                    }
                    & > div.text{
                        height: 100%;
                        flex: 1;
                    }
                    & > div.bar{
                        margin-left: .2rem;
                        height: 100%;
                        //height: 0;
                        //width: 0;
                        //opacity: 0;
                        transition: opacity .3s;
                        overflow: hidden;
                        display: flex;
                    }
                    &:hover div.bar{
                        height: 100%;
                        width: auto;
                        opacity: 1;
                    }
                }
            }

            .hoverBar{
                border-radius: .25rem;
                transition: background-color .3s;
                &:hover{
                    background-color: #00000015;
                }
            }
            .contentBox{
                position: relative;
                height: 2rem;
                box-sizing: border-box;
                padding: .2rem .5rem;
                border-radius: .25rem;
                color: var(--font-color-top3-h2);
                user-select: none;
                cursor: pointer;
                &:hover{
                    background: var(--font-color-top3-hover);
                }
                &.active{
                    color: var(--font-color-top3-h1);
                    background: var(--font-color-top3-active);
                }
            }
        }
    }
    & > div.right{
        flex-shrink: 0;
    }
    & > div.main{
        flex: 1;
    }
}
@media (max-width: 767px){

}
@media (min-width: 768px){

}
</style>
