<template>
  <div class="page-wiki">
    <LayoutPageHero
      :title="data?.title || '呼籁文旅集团'"
      :subtitle="data?.subtitle"
      :breadcrumbs="[{ text: '关于我们', to: '/about' }, { text: '呼籁文旅集团' }]"
      background-image="/images/company/photo-03.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.timeline" class="section" :class="{ 'section--gray': idx % 2 === 1 }">
        <div class="container">
          <h2 class="wiki-section-title">{{ section.title }}</h2>
          <div class="wiki-timeline">
            <div v-for="(item, ti) in section.timeline" :key="ti" class="wiki-timeline-item">
              <div class="wiki-timeline-marker">
                <div class="wiki-timeline-dot" />
              </div>
              <div class="wiki-timeline-card">
                <h4 class="wiki-timeline-year">{{ item.year }}</h4>
                <p class="wiki-timeline-text">{{ item.content }}</p>
              </div>
            </div>
          </div>
        </div>
      </section>

      <!-- 普通文本段落 -->
      <section v-if="section.content && !section.timeline && !section.subsidiaries && !section.businesses && !section.items && !section.images" 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>

      <!-- 组织架构（子公司列表） -->
      <section v-if="section.subsidiaries" 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>
          <ul class="wiki-subsidiary-list">
            <li v-for="(sub, si) in section.subsidiaries" :key="si" class="wiki-subsidiary-item">
              {{ sub }}
            </li>
          </ul>
        </div>
      </section>

      <!-- 管理团队（带图片） -->
      <section v-if="section.content && section.images" 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.images?.length" class="wiki-team-images">
            <img v-for="(img, ii) in section.images" :key="ii" :src="img" :alt="`${section.title} ${ii + 1}`" loading="lazy" />
          </div>
        </div>
      </section>

      <!-- 主要业务 -->
      <section v-if="section.businesses" class="section" :class="{ 'section--gray': idx % 2 === 1 }">
        <div class="container">
          <h2 class="wiki-section-title">{{ section.title }}</h2>
          <div class="wiki-businesses">
            <div v-for="(biz, bi) in section.businesses" :key="bi" class="wiki-business-card">
              <h3 class="wiki-business-name">{{ biz.name }}</h3>
              <p class="wiki-business-desc">{{ biz.description }}</p>
              <p v-if="biz.extra" class="wiki-business-extra">{{ biz.extra }}</p>
            </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>
    </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: '/brand', text: '了解呼籁旅行' },
        { to: '/contact', text: '联系我们' },
      ]"
    />
  </div>
</template>

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

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

useSEO('company-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: 110px;
  font-size: @font-size-xs;
  font-weight: @font-weight-medium;
  color: @color-text-muted;
  padding-top: 2px;
  white-space: nowrap;
}

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

.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-timeline {
  position: relative;
  max-width: 800px;
  margin: @space-lg 0 0;
  padding-left: @space-xl;

  &::before {
    content: '';
    position: absolute;
    left: 5px;
    top: 8px;
    bottom: 0;
    width: 2px;
    background: @color-primary-lighter;
  }
}

.wiki-timeline-item {
  position: relative;
  padding-bottom: @space-lg;

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

.wiki-timeline-marker {
  position: absolute;
  left: ~"calc(-@{space-xl} + 1px)";
  top: 6px;
}

.wiki-timeline-dot {
  width: 10px;
  height: 10px;
  background: @color-primary;
  border-radius: 50%;
}

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

.wiki-timeline-year {
  font-size: @font-size-base;
  font-weight: @font-weight-bold;
  color: @color-primary;
  margin-bottom: @space-xs;
}

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

.wiki-subsidiary-list {
  list-style: none;
  padding: 0;
  margin: @space-lg 0 0;
  display: flex;
  flex-direction: column;
  gap: @space-sm;
}

.wiki-subsidiary-item {
  padding: @space-md @space-lg;
  background: @color-bg-white;
  border: 1px solid @color-border;
  border-left: 3px solid @color-primary;
  border-radius: 0 @border-radius-md @border-radius-md 0;
  font-size: @font-size-sm;
  line-height: 1.6;
  color: @color-text-primary;
}

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

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

  img {
    width: 100%;
    border-radius: @border-radius-lg;
    object-fit: cover;
  }
}

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

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

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

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

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

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

.wiki-business-extra {
  margin-top: @space-xs;
}

.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>
