<template>

    <header>
        <div class="header-container w1500">
            <div class="logo-wrap">
                <router-link :to="{ path: '/' }" class="logo"><img :src="logo" alt=""></router-link>
            </div>
            <div class="nav-wrap">
                <nav>
                    <ul>
                        <li v-if="$store.state.roles[0]?.authority === 'ROLE_ADMIN'">기록물</li>
                        <li v-if="$store.state.roles[0]?.authority === 'ROLE_ADMIN'">언론에서 바라본 구미시</li>
                        <li v-if="$store.state.roles[0]?.authority === 'ROLE_ADMIN'">회원관리</li>
                        <li v-if="$store.state.roles[0]?.authority === 'ROLE_ADMIN'">카테고리 관리</li>

                        <li v-if="$store.state.roles[0]?.authority === 'ROLE_USER'">기록물</li>
                        <li v-if="$store.state.roles[0]?.authority === 'ROLE_USER'">언론에서 바라본 구미시</li>
                    </ul>
                </nav>
            </div>
            <div class="auth-area">
                <ul v-if="$store.state.userId != null">
                    <li><img src="../../resources/images/icon/user-settings-line.png" alt="">
                        <router-link :to="{ path: '/MyInfo.page' }">{{ $store.state.userNm }}</router-link>
                    </li>
                    <li>
                        <div class="line"></div>
                    </li>
                    <li><img src="../../resources/images/icon/logout-box-line.png" alt="">
                        <a href="#" @click.prevent="logout">로그아웃</a>
                    </li>
                </ul>
                <a href="#" class="all-menu"><img src="../../resources/images/allmenu.png" alt=""></a>
            </div>
        </div>
    </header>
</template>
<script>
import { logOutProc } from "../../resources/api/user"
export default {
    data() {
        return {
            // Define the image sources
            logo: 'client/resources/images/logo.png',
        };
    },
    methods: {
        logout() {
            // 백엔드 로그아웃 API 호출
            logOutProc()
                .then(() => {
                    console.log('로그아웃 성공 - 서버 측 쿠키 삭제 완료');
                    this.$store.commit('setStoreReset'); // 로그아웃 성공 후 스토어 초기화
                    this.$router.push({ path: '/Login.page' }); // 로그인 페이지로 리다이렉트
                })
                .catch(err => {
                    console.error('로그아웃 처리 중 오류:', err);
                    this.$store.commit('setStoreReset'); // 오류가 있어도 스토어는 초기화
                    this.$router.push({ path: '/Login.page' }); // 로그인 페이지로 리다이렉트
                });
        }
    },
    watch: {},
    computed: {},
    components: {},
    mounted() { },
};
</script>