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

const route = useRoute()

const breadcrumbs = computed(() => {
  const matched = route.matched.filter((r) => r.meta?.title)
  return matched.map((r, idx) => ({
    title: r.meta.title as string,
    isLast: idx === matched.length - 1
  }))
})
</script>

<template>
  <el-breadcrumb separator="/" class="breadcrumb">
    <el-breadcrumb-item v-for="b in breadcrumbs" :key="b.title">
      <span :class="{ 'is-last': b.isLast }">{{ b.title }}</span>
    </el-breadcrumb-item>
  </el-breadcrumb>
</template>

<style lang="scss" scoped>
.breadcrumb {
  font-size: 14px;

  :deep(.is-last) {
    color: $color-text-primary;
    font-weight: 500;
  }
}
</style>
