<template>
  <header class="topbar">
    <div class="title-group">
      <div class="eyebrow">Smart Expense Operations</div>
      <h1>{{ currentView.title }}</h1>
      <p>{{ currentView.desc }}</p>
    </div>

    <div class="top-actions">
      <span class="search-wrap">
        <i class="pi pi-search search-icon"></i>
        <input :value="search" type="search" :placeholder="isChat ? '搜索单号、申请人、目的地' : '搜索申请人、单号、费用类型'" @input="emit('update:search', $event.target.value)" />
      </span>

      <div v-if="!isChat" class="date-chip">
        <i class="pi pi-calendar"></i>
        <span>2024-07-06 ~ 2024-07-12</span>
      </div>

      <template v-if="isChat">
        <button class="top-btn primary" type="button" @click="emit('newApplication')">
          <i class="pi pi-plus"></i>
          <span>新建出差申请</span>
        </button>
      </template>
      <template v-else>
        <button class="top-btn primary" type="button" @click="emit('openChat')">
          <i class="pi pi-sparkles"></i>
          <span>AI 助手</span>
        </button>
      </template>
    </div>
  </header>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  currentView: { type: Object, required: true },
  search: { type: String, default: '' },
  activeView: { type: String, default: '' }
})

const emit = defineEmits(['update:search', 'batchApprove', 'openChat', 'newApplication'])

const isChat = computed(() => props.activeView === 'chat')
</script>

<style scoped>
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 16px;
  background: #fff;
}

.title-group {
  min-width: 0;
}

.topbar p {
  margin-top: 4px;
  max-width: 720px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.search-wrap {
  position: relative;
  width: 256px;
}

.search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 14px;
}

.search-wrap input {
  width: 100%;
  height: 40px;
  padding: 0 14px 0 38px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 14px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.search-wrap input:focus {
  border-color: #10b981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.16);
  outline: none;
}

.date-chip {
  height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 32px 0 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-weight: 400;
}

.date-chip .pi {
  color: #94a3b8;
}

.top-btn {
  height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  transition: background 160ms ease;
}

.top-btn.primary {
  background: var(--primary);
  color: #fff;
}

.top-btn.primary:hover {
  background: #0ea672;
}

@media (max-width: 760px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    padding: 18px 16px;
  }

  .top-actions,
  .search-wrap,
  .date-chip {
    width: 100%;
  }
}
</style>
