<script setup lang="ts">
import { icons } from '../../composables/icons'

defineProps<{
  connected?: boolean
  statusLabel?: string
}>()

defineEmits<{
  'toggle-sidebar': []
}>()
</script>

<template>
  <header class="topbar">
    <!-- Hamburger (mobile only) -->
    <button class="hamburger" @click="$emit('toggle-sidebar')" v-html="icons.list || ''"></button>

    <!-- Search -->
    <div class="search">
      <span class="search-icon" v-html="icons.search || ''"></span>
      <span class="search-placeholder">Operationen, Agents oder Tasks suchen…</span>
    </div>

    <!-- Spacer -->
    <div class="spacer"></div>

    <!-- Status Pill -->
    <span :class="['pill', connected ? 'live' : 'preview']">
      <span class="status-dot" :class="connected ? 'on' : 'off'"></span>
      {{ connected ? (statusLabel || 'OpenClaw verbunden') : 'Preview' }}
    </span>

    <!-- Ask Iris Button -->
    <button class="btn btn-primary ask-iris-btn">
      <span class="btn-icon" v-html="icons.spark || ''"></span>
      <span class="ask-label">Ask Iris</span>
    </button>
  </header>
</template>

<style scoped>
.topbar {
  height: 62px;
  flex: 0 0 62px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(8,6,20,.5);
  backdrop-filter: blur(14px);
}

.search {
  flex: 1;
  max-width: 560px;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 38px;
  padding: 0 14px;
  border-radius: 11px;
  background: rgba(124,108,255,.06);
  border: 1px solid var(--line);
  color: var(--tx-3);
  font-size: 13.5px;
  font-family: 'Manrope', sans-serif;
}

.search-icon :deep(svg) {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.search-placeholder {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spacer {
  flex: 1;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 11px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  font-family: 'Manrope', sans-serif;
  border: 1px solid var(--line-2);
  background: rgba(124,108,255,.07);
  color: var(--tx-2);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.status-dot.on {
  background: var(--st-work);
  box-shadow: 0 0 0 0 rgba(61,220,151,.5);
  animation: pulse-work 1.8s infinite;
}

.status-dot.off {
  background: var(--st-idle);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  font-family: 'Manrope', sans-serif;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  border: none;
  transition: filter .16s;
}

.btn-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: var(--glow-purple);
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-icon :deep(svg) {
  width: 15px;
  height: 15px;
}

.hamburger {
  display: none;
}

@media (max-width: 767px) {
  .topbar {
    padding: 0 14px;
  }

  .search {
    flex: 1;
    max-width: none;
  }

  .hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    border: none;
    background: transparent;
    color: var(--tx-2);
    cursor: pointer;
    flex: 0 0 auto;
  }

  .hamburger:hover {
    background: rgba(124,108,255,.1);
    color: var(--tx);
  }

  .hamburger :deep(svg) {
    width: 20px;
    height: 20px;
  }

  .pill {
    display: none;
  }

  .ask-iris-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    display: grid;
    place-items: center;
    border-radius: 9px;
    flex: 0 0 auto;
  }

  .ask-label {
    display: none;
  }

  .ask-iris-btn .btn-icon {
    display: flex;
  }
}

</style>
