<template>
  <div class="header-section" :style="headerStyle">
    <div class="header-info left">
      <slot name="left">
        <HeaderDateTime />
      </slot>
    </div>

    <div class="header-title">
      <img
        v-if="isImageTitle"
        :src="title"
        alt="页面标题"
        class="title-image"
      />
      <h1 v-else class="main-title">{{ displayTitle }}</h1>
    </div>

    <div class="header-info right">
      <slot name="right" />
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import HeaderDateTime from './HeaderDateTime.vue'

const props = defineProps({
  title: {
    type: String,
    default: '智慧活畜交易大数据中心'
  },
  titleBackground: {
    type: String,
    default: '/images/标题背景.png'
  }
})

const isImageTitle = computed(() => props.title?.startsWith('/'))

const displayTitle = computed(() => props.title || '智慧活畜交易大数据中心')

const headerStyle = computed(() => ({
  backgroundImage: `url('${props.titleBackground}')`
}))
</script>

<style scoped>
.header-section {
  width: 100%;
  height: 96px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 40px;
  background-position: center center;
  background-repeat: no-repeat;
  background-size: 2340px 95px;
  border-radius: 12px;
  position: relative;
  z-index: 10;
  flex-shrink: 0;
  box-sizing: border-box;
}

.header-title {
  flex: 2;
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
  height: 100%;
  padding: 8px 0;
}

.title-image {
  max-width: min(1200px, 70%);
  max-height: 72px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

.main-title {
  margin: 0;
  font-size: 36px;
  font-weight: 700;
  background: linear-gradient(180deg, #ffffff 0%, #ffffff 50%, #44c1ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
  letter-spacing: 3px;
  filter: drop-shadow(0 0 12px rgba(64, 158, 255, 0.45));
  white-space: nowrap;
}

.header-info {
  display: flex;
  align-items: center;
  gap: 24px;
  flex: 1;
  min-width: 0;
}

.header-info.left {
  justify-content: flex-start;
}

.header-info.right {
  justify-content: flex-end;
}
</style>
