<template>
  <div class="about-sts-container">
    <div class="about-sts-content">
      <div class="left-sidebar">
        <div class="sidebar-card">
          <div class="sidebar-header">
            <span class="title">关于STS</span>
          </div>
          <div class="sidebar-decorator">
            <div
              class="decorator-segment"
              style="background-color: #4b9f37"
            ></div>
            <div
              class="decorator-segment"
              style="background-color: #c51a2d"
            ></div>
            <div
              class="decorator-segment"
              style="background-color: #e37221"
            ></div>
            <div
              class="decorator-segment"
              style="background-color: #0298db"
            ></div>
            <div
              class="decorator-segment"
              style="background-color: #f8c72e"
            ></div>
            <div
              class="decorator-segment"
              style="background-color: #d0103a"
            ></div>
            <div
              class="decorator-segment"
              style="background-color: #028542"
            ></div>
            <div
              class="decorator-segment"
              style="background-color: #bf8b2e"
            ></div>
            <div
              class="decorator-segment"
              style="background-color: #0b97d9"
            ></div>
          </div>
          <div class="sidebar-menu">
            <div
              v-for="(item, index) in titleList"
              :key="item.id"
              class="menu-item"
              :class="{ active: activeIndex === index }"
              @click="switchContent(index)"
            >
              {{ item.title || "未设置" }}
            </div>
          </div>
        </div>
      </div>

      <div class="right-content">
        <div class="content-card" v-loading="loading">
          <div class="content-header">
            <span class="title">{{ activeTitle }}</span>
          </div>
          <div
            class="rich-text-rendering"
            v-html="activeContent || '<p>暂无内容</p>'"
          ></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getAboutSts } from "@/api/portal/about";

export default {
  name: "AboutSTS",
  data() {
    return {
      loading: true,
      aboutStsList: [],
      activeIndex: 0,
      titleList: [],
    };
  },
  computed: {
    activeTitle() {
      return this.titleList[this.activeIndex]?.title || "未设置";
    },
    activeContent() {
      return this.titleList[this.activeIndex]?.content || "";
    },
  },
  created() {
    this.getAboutStsData();
  },
  methods: {
    getAboutStsData() {
      this.loading = true;
      getAboutSts()
        .then((response) => {
          if (response.data && Array.isArray(response.data)) {
            this.aboutStsList = response.data;
            this.initTitleList();
          }
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    initTitleList() {
      this.titleList = this.aboutStsList.filter(
        (item) => item.title || item.content
      );
    },
    switchContent(index) {
      this.activeIndex = index;
    },
  },
};
</script>

<style lang="scss" scoped>
.about-sts-container {
  width: 100%;
  min-height: 100vh;
  background-color: #f5f7fa;
  padding: 40px 0;
}

.about-sts-content {
  max-width: 1390px;
  margin: 0 auto;
  padding: 0 30px;
  display: grid;
  grid-template-columns: 300px 1060px;
  gap: 30px;
  align-items: start;
}

.left-sidebar {
  .sidebar-card {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    overflow: hidden;
  }

  .sidebar-header {
    background: #1ea8c5;
    height: 58px;
    display: flex;
    align-items: center;
    padding-left: 19px;

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

  .sidebar-decorator {
    width: 100%;
    height: 6px;
    display: flex;
    overflow: hidden;

    .decorator-segment {
      width: 80px;
      height: 100%;

      &:first-child {
        margin-left: -40px;
      }

      &:last-child {
        margin-right: -40px;
      }
    }
  }

  .sidebar-menu {
    padding: 16px 0;

    .menu-item {
      font-family: Microsoft YaHei, Microsoft YaHei;
      font-weight: 600;
      font-size: 18px;
      color: #090909;
      // line-height: 51px;
      text-align: left;
      font-style: normal;
      text-transform: none;
      padding: 16px 24px;
      cursor: pointer;
      transition: all 0.3s ease;
      font-size: 16px;
      color: #666666;
      border-left: 3px solid transparent;

      &:hover {
        background-color: #f5f7fa;
        color: #1e3c72;
      }

      &.active {
        background-color: #f0f2f5;
        color: #0080a5;
        font-weight: 600;
        border-left-color: #1e3c72;
      }
    }
  }
}

.right-content {
  .content-card {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    min-height: 600px;
  }
}
</style>
