<template>
  <div class="page-wiki">
    <LayoutPageHero
      :title="data?.title || '呼籁旅行'"
      :subtitle="data?.subtitle"
      :breadcrumbs="[{ text: '关于我们', to: '/about' }, { text: '呼籁旅行' }]"
      background-image="/images/brand/photo-01.jpeg"
    />

    <!-- 摘要 + 信息卡 -->
    <section class="section" aria-label="品牌概述">
      <div class="container">
        <div class="wiki-header">
          <div class="wiki-summary">
            <div class="wiki-summary-inner">
              <h2 class="wiki-summary-heading">品牌简介</h2>
              <p class="wiki-summary-text">{{ data?.summary }}</p>
            </div>
          </div>
          <div v-if="data?.infoBox" class="wiki-infobox">
            <div class="wiki-infobox-logo">
              <img :src="data.logo" :alt="data.title" />
            </div>
            <div class="wiki-infobox-body">
              <div v-for="(value, key) in data.infoBox" :key="key" class="wiki-infobox-row">
                <span class="wiki-infobox-label">{{ key }}</span>
                <span class="wiki-infobox-value">{{ value }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>

    <!-- 各段落 -->
    <template v-for="(section, idx) in data?.sections" :key="idx">
      <!-- 品牌历史（子段落） -->
      <section v-if="section.subsections" class="section" :class="{ 'section--gray': idx % 2 === 1 }">
        <div class="container">
          <h2 class="wiki-section-title">{{ section.title }}</h2>
          <div v-for="(sub, si) in section.subsections" :key="si" class="wiki-subsection">
            <h3 class="wiki-subsection-title">{{ sub.title }}</h3>
            <p class="wiki-text">{{ sub.content }}</p>
          </div>
        </div>
      </section>

      <!-- 产品及服务 -->
      <section v-if="section.products" class="section" :class="{ 'section--gray': idx % 2 === 1 }">
        <div class="container">
          <h2 class="wiki-section-title">{{ section.title }}</h2>
          <p v-if="section.intro" class="wiki-text">{{ section.intro }}</p>
          <div class="wiki-products">
            <div v-for="(prod, pi) in section.products" :key="pi" class="wiki-product-card">
              <h3 class="wiki-product-name">{{ prod.name }}</h3>
              <p class="wiki-product-desc">{{ prod.description }}</p>
            </div>
          </div>
        </div>
      </section>

      <!-- 服务流程 -->
      <section v-if="section.steps" class="section" :class="{ 'section--gray': idx % 2 === 1 }">
        <div class="container">
          <h2 class="wiki-section-title">{{ section.title }}</h2>
          <div class="wiki-steps">
            <div v-for="(s, si) in section.steps" :key="si" class="wiki-step">
              <div class="wiki-step-number">{{ s.step }}</div>
              <div class="wiki-step-body">
                <h4 class="wiki-step-name">{{ s.name }}</h4>
                <p class="wiki-step-detail">{{ s.detail }}</p>
              </div>
            </div>
          </div>
        </div>
      </section>

      <!-- 品牌文化（items列表） -->
      <section v-if="section.items" class="section" :class="{ 'section--gray': idx % 2 === 1 }">
        <div class="container">
          <h2 class="wiki-section-title">{{ section.title }}</h2>
          <div class="wiki-culture-list">
            <div v-for="(item, ii) in section.items" :key="ii" class="wiki-culture-item">
              <span class="wiki-culture-label">{{ item.label }}</span>
              <p class="wiki-culture-value">{{ item.value }}</p>
            </div>
          </div>
        </div>
      </section>

      <!-- 普通文本段落（含可选图片） -->
      <section v-if="section.content && !section.subsections && !section.products && !section.steps && !section.items" class="section" :class="{ 'section--gray': idx % 2 === 1 }">
        <div class="container">
          <h2 class="wiki-section-title">{{ section.title }}</h2>
          <p class="wiki-text">{{ section.content }}</p>
          <div v-if="section.image" class="wiki-logo-img">
            <img :src="section.image" :alt="section.title" />
          </div>
        </div>
      </section>
    </template>

    <!-- 图库 -->
    <section v-if="data?.gallery?.length" class="section section--gray" aria-label="品牌图库">
      <div class="container">
        <h2 class="wiki-section-title">品牌图库</h2>
        <div class="wiki-gallery">
          <div v-for="(img, gi) in data.gallery" :key="gi" class="wiki-gallery-item">
            <img :src="img" :alt="`${data.title} 图片 ${gi + 1}`" loading="lazy" />
          </div>
        </div>
      </div>
    </section>

    <!-- CTA -->
    <CommonSectionCTA
      title="想了解更多？"
      description="查看我们的旅行产品或直接联系定制师"
      :links="[
        { to: '/products', text: '查看旅行产品' },
        { to: '/contact', text: '联系定制师' },
      ]"
    />
  </div>
</template>

<script setup>
import { useBreadcrumbSchema } from '~/composables/useJsonLd'

const { data } = await usePublicApi('brand-wiki')

useSEO('brand-wiki', {
  title: data.value?.seo?.title || '呼籁旅行 - 专注呼伦贝尔的家庭旅行品牌',
  description: data.value?.seo?.description || '',
})

useBreadcrumbSchema([
  { text: '首页', to: '/' },
  { text: '关于我们', to: '/about' },
  { text: '呼籁旅行' },
])

useScrollReveal()
</script>

<style lang="less" scoped>
.wiki-header {
  display: flex;
  gap: @space-2xl;
  align-items: flex-start;

  @media (max-width: 768px) {
    flex-direction: column;
    gap: @space-xl;
  }
}

.wiki-summary {
  flex: 1;
  min-width: 0;
}

.wiki-summary-inner {
  padding: @space-xl @space-2xl;
  background: @color-bg-warm;
  border-radius: @border-radius-lg;
  border-left: 4px solid @color-primary;
}

.wiki-summary-heading {
  font-size: @font-size-xl;
  font-weight: @font-weight-bold;
  color: @color-primary;
  margin-bottom: @space-md;
}

.wiki-summary-text {
  font-size: @font-size-base;
  line-height: 2;
  color: @color-text-primary;
  margin: 0;
}

.wiki-infobox {
  flex-shrink: 0;
  width: 360px;
  background: @color-bg-white;
  border-radius: @border-radius-lg;
  overflow: hidden;
  box-shadow: @shadow-card;

  @media (max-width: 768px) {
    width: 100%;
  }
}

.wiki-infobox-logo {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: @space-xl @space-lg;
  background: @color-primary-bg;
  border-bottom: 1px solid @color-divider;

  img {
    max-width: 160px;
    height: auto;
  }
}

.wiki-infobox-body {
  padding: @space-sm 0;
}

.wiki-infobox-row {
  display: flex;
  padding: @space-sm @space-lg;
  border-bottom: 1px solid @color-divider;
  gap: @space-md;

  &:last-child {
    border-bottom: none;
  }
}

.wiki-infobox-label {
  flex-shrink: 0;
  width: 80px;
  font-size: @font-size-sm;
  font-weight: @font-weight-medium;
  color: @color-text-muted;
  padding-top: 1px;
}

.wiki-infobox-value {
  flex: 1;
  font-size: @font-size-sm;
  line-height: 1.6;
  color: @color-text-primary;
}

.wiki-section-title {
  font-size: @font-size-2xl;
  font-weight: @font-weight-bold;
  color: @color-text-primary;
  margin-bottom: @space-lg;
  padding-bottom: @space-sm;
  border-bottom: 2px solid @color-primary;
  display: inline-block;
}

.wiki-text {
  font-size: @font-size-base;
  line-height: 1.8;
  color: @color-text-primary;
  max-width: 800px;
}

.wiki-logo-img {
  margin-top: @space-lg;
  text-align: center;

  img {
    max-width: 160px;
    height: auto;
  }
}

.wiki-subsection {
  margin-bottom: @space-lg;

  &:last-child {
    margin-bottom: 0;
  }
}

.wiki-subsection-title {
  font-size: @font-size-lg;
  font-weight: @font-weight-bold;
  color: @color-primary;
  margin-bottom: @space-sm;
}

.wiki-products {
  display: grid;
  grid-template-columns: 1fr;
  gap: @space-md;
  margin-top: @space-lg;

  .respond-md({
    grid-template-columns: repeat(2, 1fr);
  });
}

.wiki-product-card {
  padding: @space-lg;
  background: @color-bg-white;
  border: 1px solid @color-border;
  border-radius: @border-radius-lg;
}

.wiki-product-name {
  font-size: @font-size-lg;
  font-weight: @font-weight-bold;
  color: @color-primary;
  margin-bottom: @space-sm;
}

.wiki-product-desc {
  font-size: @font-size-sm;
  line-height: 1.7;
  color: @color-text-secondary;
  margin: 0;
}

.wiki-steps {
  display: flex;
  flex-direction: column;
  gap: @space-md;
  margin-top: @space-lg;
}

.wiki-step {
  display: flex;
  gap: @space-md;
  align-items: flex-start;
}

.wiki-step-number {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  background: @color-primary;
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: @font-weight-bold;
  font-size: @font-size-sm;
}

.wiki-step-body {
  flex: 1;
  padding-top: 4px;
}

.wiki-step-name {
  font-size: @font-size-base;
  font-weight: @font-weight-bold;
  color: @color-text-primary;
  margin-bottom: @space-xs;
}

.wiki-step-detail {
  font-size: @font-size-sm;
  line-height: 1.7;
  color: @color-text-secondary;
  margin: 0;
}

.wiki-culture-list {
  display: flex;
  flex-direction: column;
  gap: @space-lg;
}

.wiki-culture-item {
  padding: @space-lg;
  background: @color-bg-white;
  border-left: 4px solid @color-primary;
  border-radius: 0 @border-radius-lg @border-radius-lg 0;
  box-shadow: @shadow-sm;
}

.wiki-culture-label {
  display: block;
  font-size: @font-size-sm;
  font-weight: @font-weight-bold;
  color: @color-primary;
  margin-bottom: @space-xs;
}

.wiki-culture-value {
  font-size: @font-size-base;
  line-height: 1.8;
  color: @color-text-primary;
  margin: 0;
}

.wiki-gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: @space-md;
  margin-top: @space-lg;

  .respond-md({
    grid-template-columns: repeat(3, 1fr);
  });

  .respond-lg({
    grid-template-columns: repeat(4, 1fr);
  });
}

.wiki-gallery-item {
  border-radius: @border-radius-lg;
  overflow: hidden;
  aspect-ratio: 16 / 10;

  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
  }

  &:hover img {
    transform: scale(1.05);
  }
}
</style>
