<template>
    <div class="title-box flex justify-between mb40">
        <p class="title">{{ bookDetails ? bookDetails.book_nm : 'Loading...' }}</p>
        <select name="" id="">
            <option value="">A 반</option>
        </select>
    </div>
    <div class="board-wrap">
        <label for="" class="title1">단원</label>
        <div class="unit-pagination flex mt10" style="gap: 10px;">
            <button class="selected-btn">1</button>
            <button>2</button>
            <button>3</button>
        </div>
        <hr>
        <div class="bookmanage-btn mb20 flex justify-between align-center" @click="goToPage('C_TextList')">
            <label for="" class="title1">지문</label>
            <div class="flex align-center " style="gap: 10px;">
                <p>00개</p>
                <button><img src="../../../resources/img/btn33_101t_normal.png" alt=""></button>
            </div>
        </div>
        <div class="bookmanage-btn mb20 flex justify-between align-center" @click="goToPage('C_QuestionList')">
            <label for="" class="title1">문제</label>
            <div class="flex align-center " style="gap: 10px;">
                <p>00개</p>
                <button><img src="../../../resources/img/btn33_101t_normal.png" alt=""></button>
            </div>
        </div>
        <div class="bookmanage-btn mb20 flex justify-between align-center" @click="goToPage('C_Voca_List')">
            <label for="" class="title1">단어</label>
            <div class="flex align-center " style="gap: 10px;">
                <p>00개</p>
                <button><img src="../../../resources/img/btn33_101t_normal.png" alt=""></button>
            </div>
        </div>
        <div class="bookmanage-btn mb20 flex justify-between align-center" @click="goToPage('C_ExamList')">
            <label for="" class="title1">중간 평가</label>
            <div class="flex align-center " style="gap: 10px;">
                <p>00개</p>
                <button><img src="../../../resources/img/btn33_101t_normal.png" alt=""></button>
            </div>
        </div>
        <div class="bookmanage-btn flex justify-between align-center" @click="goToPage('C_ExamList')">
            <label for="" class="title1">최종 평가</label>
            <div class="flex align-center " style="gap: 10px;">
                <p>00개</p>
                <button><img src="../../../resources/img/btn33_101t_normal.png" alt=""></button>
            </div>
        </div>
    </div>
    <div class="flex justify-end mt30" style="gap: 10px;">
        <!-- <button type="button" title="" class="new-btn" @click="showConfirm('delete')">
            추가
        </button> -->
        <button type="button" title="" class="new-btn" @click="goToPage('RoadMap')">
            로드맵
        </button>
        <button type="button" title="" class="new-btn" @click="showConfirm('delete')">
            삭제
        </button>
    </div>
</template>

<script>
import SvgIcon from '@jamescoyle/vue-icon';
import { mdiMagnify, mdilArrowRight } from '@mdi/js';
import ProgressBar from '../../component/ProgressBar.vue';
import axios from 'axios';

export default {
    data() {
        return {
            mdiMagnify: mdiMagnify,
            mdilArrowRight: mdilArrowRight,
            timer: "00:00",
            progress: 20,
            selectedBookId: this.$route.query.book_Id,
            bookDetails: null,
        }
    },
    methods: {
        goToPage(page) {
            this.$router.push({ name: page });
        },
        increaseProgress() {
            if (this.progress < 100) {
                this.progress += 10;
            }
        },
        showConfirm(type) {
            let message = '';
            if (type === 'delete') {
                message = '삭제하시겠습니까?';
            } else if (type === 'reset') {
                message = '초기화하시겠습니까?';
            } else if (type === 'save') {
                message = '등록하시겠습니까?';
            }

            if (confirm(message)) {
                this.goBack();
            }
        },
        fetchBookDetails() {
            axios({
                url: "/book/find.json",
                method: "post",
                headers: {
                    "Content-Type": "application/json; charset=UTF-8",
                },
                data: {
                    book_id: this.$route.query.book_id
                }
            })
            .then(response => {
                console.log('Book details:', response.data);
                this.bookDetails = response.data;
            })
            .catch(error => {
                console.error('Error fetching book details:', error);
            });
        }  
    },
    watch: {

    },
    computed: {

    },
    components: {
        SvgIcon,
        ProgressBar
    },
    mounted() {
        console.log('Mounted with book_id:', this.$route.query.book_id);
        this.fetchBookDetails();
    }
}
</script>
<style scoped>
.bookmanage-btn:hover{background-color: #FFF3D7;}
</style>