<template>
  <div class="home-page">
    <BannerCarousel />
    <section class="intro-section">
      <div class="intro-content" v-loading="loading">
        <div class="intro-left" v-if="overview">
          <div class="media-container">
            <img v-if="overview.image" :src="overview.image" alt="概况图片" />
            <video v-if="overview.video" :src="overview.video" controls></video>
          </div>
        </div>
        <div class="intro-right" v-if="overview">
          <span class="title">{{ overview.title }}</span>
          <span class="summary">{{ overview.summary }}</span>
        </div>
      </div>
    </section>

    <section class="data-section">
      <div class="data-section-body">
        <div class="data-content" v-loading="loading">
          <div class="data-left" v-if="introduction">
            <div class="intro-text">
              <div class="title"></div>
              <span class="summary">{{ introduction.summary }}</span>
            </div>
          </div>
          <div class="data-right" v-if="introduction && introduction.images">
            <div class="image-grid">
              <div
                class="top-image"
                v-if="introduction.images.split(',').length > 0"
              >
                <img :src="introduction.images.split(',')[0]" alt="图片1" />
              </div>
              <div class="bottom-images">
                <div
                  class="image-item"
                  v-for="(img, index) in introduction.images
                    .split(',')
                    .slice(1, 4)"
                  :key="index"
                >
                  <img :src="img" :alt="'图片' + (index + 2)" />
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>

    <section class="news-section">
      <div class="section-header">
        <div class="divider"></div>
      </div>
      <div class="news-content" v-loading="loading">
        <div
          class="news-card"
          v-for="(item, index) in valueList"
          :key="index"
          :class="'card-' + (index + 1)"
          @click="goToValueDetail(item.valueId)"
        >
          <div
            class="card-bg"
            :style="{ backgroundImage: 'url(' + item.image + ')' }"
          ></div>
          <div class="card-content">
            <span class="title" v-if="index === 0 || index === 1">{{
              item.title
            }}</span>
            <span class="title" v-if="index === 2">{{ item.title }}</span>
            <span class="summary">{{ item.summary }}</span>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
import BannerCarousel from "@/components/portal/BannerCarousel";
import { getHomeData } from "@/api/portal/home";

export default {
  name: "Home",
  components: {
    BannerCarousel,
  },
  data() {
    return {
      loading: false,
      overview: null,
      introduction: null,
      valueList: [],
      dataCards: [
        { number: "100+", label: "合作机构" },
        { number: "500+", label: "科研项目" },
        { number: "1000+", label: "科研人员" },
        { number: "50+", label: "国家地区" },
      ],
      newsList: [
        {
          day: "15",
          month: "01",
          title: "国际大科学计划取得重大突破",
          summary: "在可持续发展目标监测方面取得重要进展",
        },
        {
          day: "12",
          month: "01",
          title: "新增国际合作项目签约",
          summary: "与多个国际科研机构签署合作协议",
        },
        {
          day: "08",
          month: "01",
          title: "科研成果荣获国际奖项",
          summary: "相关研究成果获得国际科学界认可",
        },
        {
          day: "05",
          month: "01",
          title: "举办国际学术研讨会",
          summary: "汇聚全球专家学者共话未来发展",
        },
      ],
    };
  },
  created() {
    this.loadHomeData();
  },
  methods: {
    loadHomeData() {
      this.loading = true;
      getHomeData()
        .then((response) => {
          if (response.data && response.data.overview) {
            this.overview = response.data.overview;
          }
          if (response.data && response.data.introduction) {
            this.introduction = response.data.introduction;
          }
          if (response.data && response.data.valueList) {
            this.valueList = response.data.valueList;
          }
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    goToValueDetail(valueId) {
      if (valueId) {
        this.$router.push({
          path: '/portal/value/detail',
          query: { id: valueId }
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.home-page {
  width: 100%;
  display: flex;
  flex-direction: column;
}

.page-container {
  margin: 0 auto;
  // padding: 0 30px;
}

section {
  padding: 60px 0;
}

.section-header {
  // text-align: center;
  margin-bottom: 48px;
  // position: relative;
  width: 194px;
  height: 71px;
  background-image: url("../../assets/images/sts-title-2-bg.png");
  background-size: cover;
}

.intro-section {
  height: 618px;
  padding: 0;
  padding-top: 137px;
  padding-left: 89px;
  .intro-content {
    height: 481px;
    width: 1636px;
    display: flex;
    gap: 54px;
    background-image: url("../../assets/images/intro-content-bg.png");
    background-size: cover;
    padding-top: 44px;
    padding-left: 201px;
  }

  .intro-left {
    width: 591px;
    height: 331px;

    .media-container {
      width: 100%;
      border-radius: 8px;
      overflow: hidden;
      box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);

      img {
        width: 100%;
        height: auto;
        display: block;
        object-fit: cover;
      }

      video {
        width: 100%;
        display: block;
      }
    }
  }

  .intro-right {
    flex: 1;
    display: flex;
    // padding: 20px 0;
    padding-right: 95px;
    gap: 34px;
    padding-top: 47px;
    flex-direction: column;
    .title {
      font-family: Microsoft YaHei, Microsoft YaHei;
      font-weight: bold;
      font-size: 26px;
      color: #090909;
      line-height: 28px;
      text-align: left;
      font-style: normal;
      text-transform: none;
    }

    .summary {
      font-family: Microsoft YaHei, Microsoft YaHei;
      font-weight: 400;
      font-size: 18px;
      color: #090909;
      line-height: 28px;
      text-align: left;
      font-style: normal;
      text-transform: none;
    }
  }
}

.data-section {
  // background-color: #E6EFE8;
  padding: 0;
  height: 723px;

  background-color: #519737;
  padding-top: 75px;
  padding-left: 290px;
  padding-right: 187px;
  .data-section-body {
    width: 100%;
    height: 100%;
    background-image: url("../../assets/images/data-section-bg.png");
    background-size: cover;
  }

  .section-header h2 {
    color: #1e3c72;
  }

  .data-content {
    display: flex;
    gap: 40px;
    margin-top: 30px;
  }

  .data-left {
    flex: 1;

    .intro-text {
      display: flex;
      flex-direction: column;
      gap: 63px;
      .title {
        width: 173px;
        height: 71px;
        background-image: url("../../assets/images/sts-title-bg.png");
        background-size: cover;
      }

      .summary {
        font-family: Microsoft YaHei, Microsoft YaHei;
        font-weight: 400;
        font-size: 18px;
        color: #ffffff;
        line-height: 30px;
        text-align: left;
        font-style: normal;
        text-transform: none;
      }
    }
  }

  .data-right {
    flex: 1;

    .image-grid {
      display: flex;
      flex-direction: column;
      gap: 15px;
    }

    .top-image {
      img {
        width: 100%;
        height: auto;
        object-fit: cover;
        border-radius: 8px;
      }
    }

    .bottom-images {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 15px;
    }

    .image-item {
      img {
        width: 100%;
        height: 150px;
        object-fit: cover;
        border-radius: 8px;
      }
    }
  }
}

.news-section {
  height: 759px;
  background-color: #ffffff;
  padding-top: 113px;
  padding-left: 290px;
  .news-content {
    display: flex;
    gap: 30px;
    margin-top: 30px;
  }

  .news-card {
    // flex: 1;
    position: relative;
    width: 427px;
    height: 452px;
    // border-radius: 12px;
    overflow: hidden;
    // box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    cursor: pointer;

    &:hover {
      transform: translateY(-5px);
      box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    }

    .card-bg {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-size: cover;
      background-position: center;
      background-repeat: no-repeat;
    }

    .card-content {
      position: relative;
      z-index: 1;
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      // padding: 25px;
      background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0) 0%,
        rgba(0, 0, 0, 0.6) 100%
      );

      .title {
        text-align: center;
        font-family: Microsoft YaHei, Microsoft YaHei;
        font-weight: bold;
        font-size: 22px;
        color: #ffffff;
        line-height: 40px;
        text-shadow: 0px 3px 12px rgba(0, 0, 0, 0.68);
        font-style: normal;
        text-transform: none;
      }

      .summary {
        display: flex;
        padding: 0 40px;
        font-family: Microsoft YaHei, Microsoft YaHei;
        font-weight: 400;
        font-size: 16px;
        color: #ffffff;
        line-height: 28px;
        text-shadow: 0px 3px 12px rgba(0, 0, 0, 0.68);
        text-align: left;
        font-style: normal;
        text-transform: none;
      }
    }

    &.card-1 {
      .card-content {
        justify-content: flex-start;
        padding-top: 51px;
        .summary {
          margin-top: 28px;
        }
      }
    }

    &.card-2 {
      .card-content {
        justify-content: flex-start;
        .title {
          display: flex;
          align-items: center;
          height: 100px;
          // line-height: 100px;
          padding: 0 25px;
          background-color: #feb614;
        }
        .summary {
          margin-top: 28px;
        }
      }
    }

    &.card-3 {
      .card-content {
        justify-content: flex-end;
        .title {
          display: flex;
          align-items: center;
          height: 100px;
          // line-height: 100px;
          padding: 0 25px;
          background-color: #1ea8c5;
          position: absolute;
          bottom: 0;
          right: 0;
        }
        .summary {
          position: absolute;
          top: 50%;
          transform: translateY(-50%);
          left: 0;
        }
      }
    }
  }
}

@media (max-width: 1024px) {
  .news-content {
    flex-wrap: wrap;
  }

  .news-card {
    flex: 1 1 calc(50% - 15px);
  }
}

@media (max-width: 768px) {
  .page-container {
    padding: 0 20px;
  }

  .intro-content {
    flex-direction: column;
  }

  .intro-left {
    max-width: 100%;
  }

  .data-content {
    flex-direction: column;
  }

  .news-content {
    flex-direction: column;
  }

  .news-card {
    flex: 1 1 100%;
    height: 250px;
  }
}
</style>
