<script setup lang="ts">
import { onMounted, ref } from 'vue'
import http from '../api/http'

const currentYear = new Date().getFullYear()
const frontendVersion = __APP_VERSION__
const backendVersion = ref<string>()

onMounted(async () => {
  try {
    const { data } = await http.get<{ version?: string }>('/system/version')
    backendVersion.value = data.version?.trim() || undefined
  } catch {
    // 页脚版本信息不应影响业务页面，也不应为暂时的网络异常额外弹出提示。
  }
})
</script>

<template>
  <footer class="site-footer" aria-label="网站版权信息">
    <div class="site-footer-inner">
      <p>© {{ currentYear }} 明序教务 · 版权所有</p>
      <div class="footer-meta">
        <span class="footer-note">教务管理与学业服务平台</span>
        <span class="footer-versions" aria-live="polite">
          前端 v{{ frontendVersion }} · 后端 v{{ backendVersion ?? '—' }}
        </span>
      </div>
    </div>
  </footer>
</template>

<style scoped>
.site-footer {
  position: relative;
  z-index: 1;
  border-top: 1px solid rgba(255, 255, 255, .1);
  color: #d9e0f2;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, .025) 1px, transparent 1px),
    linear-gradient(112deg, #152550 0%, #1d326c 72%, #176a70 130%);
  background-size: 28px 28px, auto;
}

.site-footer-inner {
  min-height: 58px;
  max-width: 1540px;
  margin: 0 auto;
  padding: 11px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.site-footer p {
  margin: 0;
  font-size: 12px;
  letter-spacing: .04em;
}

.footer-meta { display: flex; align-items: center; gap: 14px; }
.footer-note { color: #aeb9d8; font-size: 11px; }
.footer-versions { color: #c3cce5; font-size: 11px; font-variant-numeric: tabular-nums; }

@media (max-width: 600px) {
  .site-footer-inner {
    min-height: 72px;
    padding: 10px 14px;
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    gap: 7px;
  }

  .footer-meta { align-items: flex-start; flex-direction: column; gap: 4px; }
  .footer-note, .footer-versions { font-size: 10px; }
}
</style>
