<script setup lang="ts">
import { useRoute, useRouter } from 'vue-router'
import { computed } from 'vue'
import { useAuthStore } from '@/stores/auth'

const route = useRoute()
const router = useRouter()
const auth = useAuthStore()

const tabs = [
  { path: '/m', label: '首页', icon: 'HomeFilled' },
  { path: '/m/visit/new', label: '今日拜访', icon: 'Edit' },
  { path: '/m/note/new', label: '今日纪要', icon: 'Notebook' },
]
const activeTab = computed(() => {
  if (route.path === '/m') return '/m'
  if (route.path.includes('/visit')) return '/m/visit/new'
  if (route.path.includes('/note')) return '/m/note/new'
  return route.path
})
</script>

<template>
  <div class="mobile-layout">
    <header class="mobile-header">
      <span class="header-title">企迹</span>
      <div style="display:flex; align-items:center; gap:8px">
        <el-button text size="small" style="color:white" @click="router.push('/')">💻 PC</el-button>
        <span class="header-user">{{ auth.name }}</span>
      </div>
    </header>
    <main class="mobile-main">
      <router-view />
    </main>
    <nav class="mobile-tabbar">
      <div
        v-for="tab in tabs" :key="tab.path"
        class="tab-item" :class="{ active: activeTab === tab.path }"
        @click="router.push(tab.path)"
      >
        <el-icon><component :is="tab.icon" /></el-icon>
        <span>{{ tab.label }}</span>
      </div>
    </nav>
  </div>
</template>

<style scoped>
.mobile-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: #f5f7fa;
}
.mobile-header {
  background: linear-gradient(135deg, #1a73e8, #4080ff);
  color: white;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
}
.mobile-main {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}
.mobile-tabbar {
  display: flex;
  background: white;
  border-top: 1px solid #e4e7ed;
  padding: 6px 0;
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0;
  color: #909399;
  font-size: 12px;
  cursor: pointer;
}
.tab-item.active {
  color: #1a73e8;
}
.tab-item .el-icon {
  font-size: 22px;
  margin-bottom: 2px;
}
</style>
