<template>
  <header class="topbar" :class="`topbar--${tagClass}`">
    <div class="topbar-brand">
      <slot name="logo" />
      <span v-if="title" class="topbar-title">{{ title }}</span>
      <slot name="left" />
    </div>
    <div v-if="showSearchBox" class="topbar-search">
      <slot name="search" />
    </div>
    <div v-if="showMenu" class="topbar-menu">
      <slot name="menu" />
    </div>
    <div class="topbar-right">
      <slot name="right-content" />
    </div>
  </header>
</template>

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

const props = withDefaults(defineProps<{
  title?: string
  tag?: 'After Login' | 'Before Login'
  showMenu?: boolean
  showSearchBox?: boolean
}>(), {
  tag: 'After Login',
  showMenu: false,
  showSearchBox: false,
})

const tagClass = computed(() => (props.tag === 'Before Login' ? 'before-login' : 'after-login'))
</script>

<style scoped>
.topbar {
  display: flex;
  align-items: center;
  padding: var(--sp-xs) var(--sp-m);
  background: var(--bg-topbar);
  border: 1px solid var(--line-deep);
  gap: var(--topbar-section-gap);
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
}
.topbar--after-login { height: var(--topbar-height); }
.topbar--before-login { height: var(--topbar-height); }
.topbar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-m);
  flex-shrink: 0;
}
.topbar-title {
  font: var(--text-style-pop-title);
  color: var(--text-heading);
  white-space: nowrap;
}
.topbar-search,
.topbar-menu {
  display: flex;
  align-items: center;
  gap: var(--sp-xxl);
  flex: 1;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-xs);
  flex-shrink: 0;
  /* Mirror Figma: Right_content is always anchored to the far edge. The Figma
     bar keeps an always-present flex:1 middle region; when search/menu are both
     hidden no such spacer is rendered here, so margin-left:auto reclaims the
     free space and keeps the right region flush right (fixes Before Login's
     "Try it now" hugging the logo). No-op when a flex:1 menu/search is present. */
  margin-left: auto;
}
.topbar--before-login .topbar-right {
  gap: var(--sp-l);
}
</style>
