<template>
  <!-- 调查项目：与智库报告相同的「全部」互斥逻辑 -->
  <div class="home-main-footer-main">
    <div class="left">
      <div class="select-box">
        <div class="header">
          <div class="icon"></div>
          <div class="title">{{ "科技领域" }}</div>
        </div>
        <div class="select-main">
          <el-checkbox-group class="checkbox-group" :model-value="selectedAreaList" @change="handleAreaGroupChange">
            <el-checkbox class="filter-checkbox all-checkbox" :label="RESOURCE_FILTER_ALL_AREA">
              {{ RESOURCE_FILTER_ALL_AREA }}
            </el-checkbox>
            <el-checkbox v-for="research in areaList" :key="research.id" class="filter-checkbox" :label="research.id">
              {{ research.name }}
            </el-checkbox>
          </el-checkbox-group>
        </div>
      </div>

      <div class="select-box">
        <div class="header">
          <div class="icon"></div>
          <div class="title">{{ "发布时间" }}</div>
        </div>
        <div class="select-main">
          <el-checkbox-group class="checkbox-group" :model-value="selectedPubTimeList" @change="handleTimeGroupChange">
            <el-checkbox class="filter-checkbox all-checkbox" :label="RESOURCE_FILTER_ALL_TIME">
              {{ RESOURCE_FILTER_ALL_TIME }}
            </el-checkbox>
            <el-checkbox v-for="time in pubTimeList" :key="time.id" class="filter-checkbox" :label="time.id">
              {{ time.name }}
            </el-checkbox>
          </el-checkbox-group>
        </div>
      </div>
    </div>

    <div class="right">
      <div class="card-box">
        <div class="footer-card" v-for="(item, index) in curFooterList" :key="index"
          @click="emit('report-click', item)">
          <div class="footer-card-top">
            <img :src="item.projectCoverImgUrl" alt="" />
          </div>
          <div class="footer-card-title">
            {{ item.projectNameZh }}
          </div>
          <div class="footer-card-footer">
            <div class="time">{{ formatDate(item.startDate) }}</div>
            <div class="from">{{ item.thinktankName }}</div>
          </div>
        </div>
      </div>
      <div class="right-footer">
        <div class="info">共 {{ total }} 篇智库报告</div>
        <div class="page-box">
          <el-pagination :page-size="12" background layout="prev, pager, next" :total="total"
            @current-change="emit('page-change', $event)" :current-page="currentPage" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import {
  RESOURCE_FILTER_ALL_AREA,
  RESOURCE_FILTER_ALL_TIME,
  normalizeExclusiveAllOption
} from "../utils/resourceLibraryFilters";

defineProps({
  areaList: { type: Array, default: () => [] },
  selectedAreaList: { type: Array, default: () => [] },
  pubTimeList: { type: Array, default: () => [] },
  selectedPubTimeList: { type: Array, default: () => [] },
  curFooterList: { type: Array, default: () => [] },
  total: { type: Number, default: 0 },
  currentPage: { type: Number, default: 1 }
});
const formatDate = (str) => {
  if (!str) return ''
  const [y, m, d] = str.split('T')[0].split('-')
  return `${y}年${+m}月${+d}日`
};
const emit = defineEmits([
  "update:selectedAreaList",
  "update:selectedPubTimeList",
  "filter-change",
  "report-click",
  "page-change"
]);

const handleAreaGroupChange = (val) => {
  emit("update:selectedAreaList", normalizeExclusiveAllOption(val, RESOURCE_FILTER_ALL_AREA));
  emit("filter-change");
};

const handleTimeGroupChange = (val) => {
  emit("update:selectedPubTimeList", normalizeExclusiveAllOption(val, RESOURCE_FILTER_ALL_TIME));
  emit("filter-change");
};
</script>

<style lang="scss" scoped>
/* 复制 HomeMainFooterMain 的样式，保证完全不影响外观 */
.home-main-footer-main {
  margin: 0 auto;
  margin-top: 36px;
  width: 1600px;
  display: flex;
  gap: 16px;

  .left {
    width: 360px;
    height: 100%;
    padding-bottom: 24px;
    box-sizing: border-box;
    border: 1px solid rgba(234, 236, 238, 1);
    border-radius: 10px;
    box-shadow: 0px 0px 20px 0px rgba(94, 95, 95, 0.1);
    background: rgba(255, 255, 255, 1);
    position: relative;

    .select-box {
      margin-top: 16px;

      .header {
        display: flex;
        gap: 17px;

        .icon {
          margin-top: 4px;
          width: 8px;
          height: 16px;
          background: var(--color-main-active);
          border-radius: 0 4px 4px 0;
        }

        .title {
          height: 24px;
          color: var(--color-main-active);
          font-family: "Source Han Sans CN";
          font-size: 16px;
          font-weight: 700;
          line-height: 24px;
          letter-spacing: 1px;
          text-align: left;
        }
      }

      .select-main {
        margin-left: 24px;
        margin-top: 12px;

        .checkbox-group {
          display: grid;
          grid-template-columns: repeat(2, 160px);
          gap: 8px 4px;
        }
      }

      .select-main1 {
        width: 100px;
      }
    }
  }

  .right {
    width: 1284px;
    max-height: 1377px;

    .card-box {
      width: 1226px;
      max-height: 1248px;
      min-height: 616px;
      display: flex;
      flex-wrap: wrap;
      gap: 16px 16px;


      .footer-card {
        width: 398px;
        height: 300px;
        border-radius: 10px;
        box-shadow: 0px 0px 20px 0px rgba(25, 69, 130, 0.1);
        background: rgba(255, 255, 255, 1);
        cursor: pointer;

        .footer-card-top {
          width: 364px;
          height: 180px;
          margin: 0 auto;
          margin-top: 15px;

          img {
            width: 100%;
            height: 100%;
          }
        }

        .footer-card-title {
          margin: 0 auto;
          margin-top: 13px;
          width: 376px;
          height: 48px;
          color: rgba(59, 65, 75, 1);
          font-family: Microsoft YaHei;
          font-size: 18px;
          font-weight: 700;
          line-height: 24px;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }

        .footer-card-footer {
          margin: 0 auto;
          margin-top: 5px;
          width: 376px;
          height: 22px;
          display: flex;
          justify-content: space-between;
          color: rgba(95, 101, 108, 1);
          font-family: Microsoft YaHei;
          font-size: 14px;
          font-weight: 400;
          line-height: 22px;
        }
      }
    }

    .right-footer {
      height: 50px;
      margin-top: 43px;
      display: flex;
      justify-content: space-between;

      .info {
        height: 19px;
        color: rgba(132, 136, 142, 1);
        font-family: Microsoft YaHei;
        font-size: 14px;
        font-weight: 400;
        line-height: 18px;
        letter-spacing: 0px;
        text-align: left;
      }
    }
  }
}

.all-checkbox {
  width: 160px;
  height: 24px;
  margin: 0;
}

.filter-checkbox {
  width: 160px;
  height: 24px;
  margin: 0;
}
</style>
