<script setup lang="ts">
import { RouterLink } from 'vue-router';
import type { AdminBreadcrumbItem } from '../utils/admin-breadcrumb';

defineProps<{
  crumbs?: AdminBreadcrumbItem[];
  title: string;
  subtitle?: string;
}>();
</script>

<template>
  <header class="admin-subnav">
    <nav v-if="crumbs?.length" class="admin-subnav__crumbs" aria-label="Breadcrumb">
      <template v-for="(item, i) in crumbs" :key="`${item.label}-${i}`">
        <RouterLink
          v-if="item.to && i < crumbs.length - 1"
          :to="item.to"
          class="admin-subnav__link"
        >
          {{ item.label }}
        </RouterLink>
        <span v-else class="admin-subnav__current">{{ item.label }}</span>
        <span v-if="i < crumbs.length - 1" class="admin-subnav__sep" aria-hidden="true">/</span>
      </template>
    </nav>
    <div class="admin-subnav__main">
      <div class="admin-subnav__titles">
        <h1 class="admin-subnav__title">{{ title }}</h1>
        <span v-if="subtitle" class="admin-subnav__subtitle">{{ subtitle }}</span>
      </div>
      <div v-if="$slots.extra" class="admin-subnav__extra">
        <slot name="extra" />
      </div>
    </div>
  </header>
</template>

<style scoped>
.admin-subnav {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
  flex-shrink: 0;
}
.admin-subnav__crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 6px;
  font-size: 12px;
  line-height: 1.4;
}
.admin-subnav__link {
  color: #737373;
  font-weight: 500;
  transition: color 0.15s;
}
.admin-subnav__link:hover {
  color: #f5f5f5;
}
.admin-subnav__current {
  color: #737373;
}
.admin-subnav__sep {
  color: #444;
  user-select: none;
}
.admin-subnav__main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.admin-subnav__titles {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 12px;
  min-width: 0;
}
.admin-subnav__title {
  margin: 0;
  font-size: 18px;
  font-weight: 500;
  color: #f5f5f5;
  letter-spacing: 0;
}
.admin-subnav__subtitle {
  font-size: 13px;
  color: #777;
}
.admin-subnav__extra {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
</style>
