<template>
  <div class="app-body">
    <router-view v-slot="{ Component }">
      <keep-alive :include="['home', 'orders', 'messages', 'mine', 'wall']">
        <component :is="Component" />
      </keep-alive>
    </router-view>

    <!-- 底部导航（含中间凸起发单按钮） -->
    <nav v-if="showTab" class="tabbar">
      <button
        v-for="item in leftTabs"
        :key="item.name"
        class="tabbar__item"
        :class="{ 'is-active': active === item.name }"
        @click="go(item.path)"
      >
        <span class="tabbar__text">{{ item.text }}</span>
      </button>

      <button class="tabbar__fab" @click="go('/wall')">
        <span class="tabbar__fab-icon"><AppIcon name="heart" :size="24" /></span>
        <span class="tabbar__fab-text">表白墙</span>
      </button>

      <button
        v-for="item in rightTabs"
        :key="item.name"
        class="tabbar__item"
        :class="{ 'is-active': active === item.name }"
        @click="go(item.path)"
      >
        <span class="tabbar__text">{{ item.text }}</span>
      </button>
    </nav>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'

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

const leftTabs = [
  { name: 'home', text: '首页', path: '/home' },
  { name: 'orders', text: '订单', path: '/orders' }
]
const rightTabs = [
  { name: 'messages', text: '消息', path: '/messages' },
  { name: 'mine', text: '我的', path: '/mine' }
]

const active = computed(() => route.name)
const showTab = computed(() => route.meta.tab === true)

function go(path) {
  router.push(path)
}
</script>

<style scoped>
.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 480px;
  height: calc(56px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #ffffff;
  border-top: 1px solid var(--brand-border);
  box-shadow: 0 -2px 12px rgba(20, 46, 92, 0.05);
  display: flex;
  align-items: stretch;
  z-index: 100;
}
.tabbar__item {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brand-text-secondary);
  font-size: 14px;
  cursor: pointer;
}
.tabbar__item.is-active {
  color: var(--brand-primary);
  font-weight: 600;
}
.tabbar__fab {
  flex: 0 0 64px;
  position: relative;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  cursor: pointer;
}
.tabbar__fab-icon {
  position: absolute;
  top: -18px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff6b9d, #ff8f6b);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(255, 107, 157, 0.45);
  border: 3px solid #fff;
}
.tabbar__fab-text {
  margin-top: 38px;
  font-size: 11px;
  font-weight: 600;
  color: #ff5c8a;
}
</style>
