<template>
  <div class="science-plan-container">
    <div class="science-plan-content">
      <div class="left-sidebar">
        <div class="sidebar-card">
          <div class="sidebar-header">
            <span class="title">科研计划与国际合作</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 sciencePlanList" 
              :key="item.id"
              class="menu-item"
              :class="{ active: currentIndex === index }"
              @click="handleTitleClick(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">{{ currentTitle }}</span>
          </div>
          <div class="content-body" v-html="currentContent || '<p>暂无内容</p>'"></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getSciencePlanList } from '@/api/portal/sciencePlan'

export default {
  name: 'SciencePlan',
  data() {
    return {
      loading: true,
      sciencePlanList: [],
      currentIndex: 0
    }
  },
  computed: {
    currentTitle() {
      return this.sciencePlanList[this.currentIndex]?.title || '未设置'
    },
    currentContent() {
      return this.sciencePlanList[this.currentIndex]?.content || ''
    }
  },
  created() {
    this.getSciencePlanData()
  },
  methods: {
    getSciencePlanData() {
      this.loading = true
      getSciencePlanList().then(response => {
        if (response.data) {
          this.sciencePlanList = response.data
        }
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    handleTitleClick(index) {
      this.currentIndex = index
    }
  }
}
</script>

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

.science-plan-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 {
      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: #1e3c72;
        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;
  }

  .content-header {
    padding: 30px 30px 0;

    .title {
      font-size: 20px;
      font-weight: 600;
      color: #1e3c72;
      margin: 0;
    }
  }

  .content-body {
    padding: 30px;
    padding-top: 0;
    line-height: 1.8;
    color: #333333;
    overflow: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;

    :deep(h1),
    :deep(h2),
    :deep(h3),
    :deep(h4),
    :deep(h5),
    :deep(h6) {
      color: #1e3c72;
      margin-top: 24px;
      margin-bottom: 16px;
    }

    ::v-deep p{
      margin-bottom: 16px;
      max-width: 100%;
      overflow: hidden;
      font-family: Microsoft YaHei, Microsoft YaHei;
      font-weight: 400;
      font-size: 18px;
      color: #090909;
      line-height: 30px;
      text-align: left;
      font-style: normal;
      text-transform: none;
    }

    ::v-deep img {
      margin: 0 auto ;
      width: 606px !important;
      height: auto !important;
      border-radius: 4px;
      display: block;
      box-sizing: border-box;
    }

    :deep(a) {
      color: #1e3c72;
      text-decoration: none;

      &:hover {
        text-decoration: underline;
      }
    }

    :deep(ul),
    :deep(ol) {
      margin-left: 24px;
      margin-bottom: 16px;
    }

    :deep(li) {
      margin-bottom: 8px;
    }
  }
}

@media (max-width: 992px) {
  .science-plan-content {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .left-sidebar {
    order: 2;

    .sidebar-menu {
      display: flex;
      overflow-x: auto;
      white-space: nowrap;

      .menu-item {
        border-left: none;
        border-bottom: 3px solid transparent;
        display: inline-block;
        margin-right: 8px;
        border-radius: 4px 4px 0 0;

        &.active {
          border-left: none;
          border-bottom-color: #1e3c72;
        }
      }
    }
  }

  .right-content {
    order: 1;
  }
}

@media (max-width: 768px) {
  .science-plan-content {
    padding: 0 20px;
  }

  .right-content {
    .content-card {
      min-height: 500px;
    }

    .content-header {
      padding: 20px 20px 0;
    }

    .content-body {
      padding: 20px;
    }
  }

  .left-sidebar {
    .sidebar-header {
      padding: 20px 20px;

      h2 {
        font-size: 20px;
      }
    }

    .sidebar-menu {
      .menu-item {
        padding: 12px 20px;
        font-size: 14px;
      }
    }
  }
}
</style>
