<script setup lang="ts">
import { useRoute, RouterLink } from 'vue-router'

const route = useRoute()

function isNavActive(path: string) {
  if (path === '/m') return route.path === '/m'
  return route.path.startsWith(path)
}
</script>

<template>
  <nav class="bottom-nav">
    <RouterLink
      to="/m"
      class="nav-item"
      :class="{ active: isNavActive('/m') }"
    >
      <van-icon name="home-o" :size="22" />
      <span>首页</span>
    </RouterLink>
    <RouterLink
      to="/m/messages"
      class="nav-item"
      :class="{ active: isNavActive('/m/messages') }"
    >
      <van-icon name="chat-o" :size="22" />
      <span>消息</span>
    </RouterLink>
    <RouterLink to="/m/seller/listings/create" class="nav-item nav-publish">
      <div class="publish-pill">+</div>
      <span>发布</span>
    </RouterLink>
    <RouterLink
      to="/m/orders"
      class="nav-item"
      :class="{ active: isNavActive('/m/orders') }"
    >
      <van-icon name="orders-o" :size="22" />
      <span>订单</span>
    </RouterLink>
    <RouterLink
      to="/m/profile"
      class="nav-item"
      :class="{ active: isNavActive('/m/profile') }"
    >
      <van-icon name="manager-o" :size="22" />
      <span>我的</span>
    </RouterLink>
  </nav>
</template>

<style scoped>
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  background: #fff;
  border-top: 1px solid #eee;
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(50px + env(safe-area-inset-bottom));
  box-sizing: border-box;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: #999;
  font-size: 10px;
  text-decoration: none;
}

.nav-item.active {
  color: #1477ff;
}

.nav-item span {
  font-weight: 600;
}

.publish-pill {
  width: 36px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: #ff6a00;
  color: #fff;
  font-size: 18px;
  font-weight: 900;
}

.nav-publish span {
  color: #ff6a00;
}

/* 响应式适配 */
@media (min-width: 520px) {
  .bottom-nav {
    left: calc((100vw - 430px) / 2);
    right: calc((100vw - 430px) / 2);
  }
}
</style>
