<template>
  <nav v-if="items.length" class="breadcrumb" aria-label="面包屑导航">
    <ol class="breadcrumb-list">
      <li class="breadcrumb-item">
        <NuxtLink to="/" class="breadcrumb-link">首页</NuxtLink>
      </li>
      <li v-for="(item, index) in items" :key="index" class="breadcrumb-item">
        <span class="breadcrumb-sep" aria-hidden="true">/</span>
        <NuxtLink v-if="item.to" :to="item.to" class="breadcrumb-link">{{ item.text }}</NuxtLink>
        <span v-else class="breadcrumb-current" aria-current="page">{{ item.text }}</span>
      </li>
    </ol>
  </nav>
</template>

<script setup>
defineProps({
  items: { type: Array, default: () => [] },
})
</script>

<style lang="less" scoped>
.breadcrumb-list {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: @space-xs;
}

.breadcrumb-item {
  display: flex;
  align-items: center;
  gap: @space-xs;
}

.breadcrumb-sep {
  color: @color-text-muted;
  font-size: @font-size-sm;
}

.breadcrumb-link {
  font-size: @font-size-sm;
  color: @color-text-muted;
  text-decoration: none;

  &:hover {
    color: @color-primary;
  }
}

.breadcrumb-current {
  font-size: @font-size-sm;
  color: @color-text-secondary;
}
</style>
