<template>
    <div class="header-container">
        <div class="left">
            <div class="date">
                <div>{{ currentTime }}</div>
                <div class="week">{{ weekText }}</div>
            </div>
            <div class="binary-strip">{{ binaryText }}</div>
        </div>
        <div class="application-title">两江鱼复智能网联新能源汽车产业基地数字化平台</div>
        <div class="right">
            <div class="binary-strip">{{ binaryText }}</div>
            <div class="btn-container">
                <button class="nav-btn"  :class="{ active: activePage === 'home' }" @click="handleBtn('home')">地图总览</button>
                <button class="nav-btn"  :class="{ active: activePage === 'monitoring' }" @click="handleBtn('monitoring')">智能监控</button>
                <button class="nav-btn"  :class="{ active: activePage === 'manualTakeover' }" @click="handleBtn('manualTakeover')">人工接管</button>
            </div>
        </div>
    </div>
</template>
<script setup>
import { onMounted, onUnmounted } from 'vue';

const emits = defineEmits(['activePage'])

const currentTime = ref('')
const weekText = ref('')

const binaryText = ref('13513034532438213')

const weekNames = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
const updateClock = () => {
    const now = new Date();
    const y = now.getFullYear();
    const mo = String(now.getMonth()+1).padStart(2,'0');
    const d = String(now.getDate()).padStart(2,'0');
    const h = String(now.getHours()).padStart(2,'0');
    const mi = String(now.getMinutes()).padStart(2,'0');
    const s = String(now.getSeconds()).padStart(2,'0');
    currentTime.value = `${y}-${mo}-${d} ${h}:${mi}:${s}`
    weekText.value = weekNames[now.getDay()]
}

const genBinary = (len) => {
    let str = '';
    for (let i = 0; i < len; i++) str += Math.round(Math.random()).toString();
    return str;
}

const animateBinary = () => {
    binaryText.value = genBinary(30)
}

const activePage = ref('home')
const handleBtn = (page) => {
    activePage.value = page
    emits("activePage", page);
}

let clockTimer, binaryTimer;
onMounted(() => {
    updateClock();
    clockTimer = setInterval(updateClock, 1000);
    animateBinary()
    binaryTimer = setInterval(animateBinary, 400);
})

onUnmounted(() => {
    clearInterval(clockTimer)
    clearInterval(binaryTimer)
})

</script>
<style lang="scss" scoped>
.header-container {
    // width: 100%;
    height: 100%;
    display: flex;
    gap: 20px;
    margin: 0 20px;
}

.left { 
    flex: 1;
    display: flex;
    justify-content: space-evenly;

    .date {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 20px;
        color: #00c2ff;
        font-size: 16px;
        font-weight: 600;
        letter-spacing: 2px;

        .week {
            font-size: 18px;
        }
    }
}

.application-title { 
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 700;
    text-align: center;
    color: #00c2ff;
    letter-spacing: 4px;
    white-space: nowrap;
}

.right {
    flex: 1;
    display: flex;
    justify-content: space-evenly;

    .btn-container {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px ;

        .nav-btn {
            background: rgba(0, 60, 140, 0.5);
            border: 1px solid rgba(0, 194, 255, 0.35);
            color: #a0d8f0;
            padding: 6px 20px;
            border-radius: 3px;
            font-size: 14px;
            cursor: pointer;
            transition: all 0.2s;
            white-space: nowrap;
        }

        .active {
            background: rgba(0, 120, 220, 0.7);
            border-color: #00c2ff;
            color: #fff;
            box-shadow: 0 0 10px rgba(0, 194, 255, 0.5);
        }
    }
}

 .binary-strip {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Orbitron', monospace;
    font-size: 10px;
    color: rgba(0, 194, 255, 0.3);
    letter-spacing: 2px;
    white-space: nowrap;
    overflow: hidden;
}

</style>