<template>
  <div class="main-content">
    <div class="left">
      <!-- <div class="select-box">
					<div class="select-box-header">
						<div class="icon"></div>
						<div class="title">{{ "报告类型" }}</div>
					</div>
					<div class="select-main">
						<div class="checkbox-group">
							<el-checkbox v-for="type in reportTypeList" :key="type.id" v-model="selectedReportTypeList"
								:label="type.id" class="filter-checkbox" @change="handleGetThinkDynamicsReport()">
								{{ type.typeName }}
							</el-checkbox>
						</div>
					</div>
				</div> -->
      <div class="select-research-box">
        <div class="select-box-header">
          <div class="icon"></div>
          <div class="title">{{ "研究类型" }}</div>
        </div>
        <div class="select-main">
          <div class="checkbox-group">
            <el-checkbox label="全部领域" class="filter-checkbox"></el-checkbox>
            <el-checkbox v-for="type in researchTypeList" :key="type.id" v-model="selectedResearchTypeList"
              :label="type.id" class="filter-checkbox" @change="handleGetThinkDynamicsReport()">
              {{ type.name }}
            </el-checkbox>
          </div>
        </div>
      </div>
      <div class="select-time-box">
        <div class="select-box-header">
          <div class="icon"></div>
          <div class="title">{{ "发布时间" }}</div>
        </div>
        <div class="select-main">
          <div class="checkbox-group">
            <el-checkbox label="全部时间"></el-checkbox>
            <el-checkbox v-for="type in researchTimeList" :key="type.id" v-model="selectedResearchTypeList"
              :label="type.id" class="filter-checkbox" @change="handleGetThinkDynamicsReport()">
              {{ type.name }}
            </el-checkbox>
          </div>
        </div>
        <!-- <div class="input-main">
						<el-input placeholder="输入作者名字" v-model="author" @input="handleGetThinkDynamicsReport()" />
					</div> -->
      </div>
    </div>
    <div class="right">
      <div class="card-box">
        <div class="footer-card" v-for="(item, index) in curFooterList" :key="index"
          @click="handleToReportDetail(item)">
          <div class="footer-card-top">
            <img :src="item.imageUrl" alt="" />
          </div>
          <div class="footer-card-title">
            {{ item.name }}
          </div>
          <div class="footer-card-footer">
            <div class="time">{{ item.times }}</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="handleCurrentChange" :current-page="currentPage" />
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, toRefs, watch } from "vue";

const props = defineProps({
  researchTypeList: {
    type: Array,
    default: () => []
  },
  researchTimeList: {
    type: Array,
    default: () => []
  },
  selectedResearchTypeList: {
    type: Array,
    default: () => []
  },
  curFooterList: {
    type: Array,
    default: () => []
  },
  total: {
    type: Number,
    default: 0
  },
  currentPage: {
    type: Number,
    default: 1
  }
});

const emit = defineEmits([
  "update:selectedResearchTypeList",
  "filter-change",
  "page-change",
  "report-click"
]);

// 解构 props，保持模板里变量名不变
const { researchTypeList, researchTimeList, curFooterList, total, currentPage } = toRefs(props);

// 用本地 ref 替代 computed，el-checkbox 会直接修改数组，需要可变的 ref
const selectedResearchTypeList = ref([...(props.selectedResearchTypeList || [])]);

// 父组件更新时同步到子组件
watch(
  () => props.selectedResearchTypeList,
  val => {
    selectedResearchTypeList.value = val ? [...val] : [];
  },
  { immediate: true, deep: true }
);

// 子组件勾选变化时通知父组件，flush: 'sync' 确保在 @change 触发前父组件已更新，否则 filter-change 时父组件拿到的还是旧值
watch(
  selectedResearchTypeList,
  val => {
    emit("update:selectedResearchTypeList", val);
  },
  { deep: true, flush: "sync" }
);

// 保持模板里的方法名不变，但改成通知父组件，直接传入当前选中值避免时序问题
const handleGetThinkDynamicsReport = () => {
  emit("update:selectedResearchTypeList", [...selectedResearchTypeList.value]);
  emit("filter-change", [...selectedResearchTypeList.value]);
};

const handleCurrentChange = page => {
  emit("page-change", page);
};

const handleToReportDetail = item => {
  emit("report-click", item);
};
</script>
<style lang="scss" scoped>
.main-content {
  display: flex;
  gap: 16px;

  .left {
    width: 360px;
    height: 541px;
    padding-bottom: 36px;
    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-research-box {
      width: 360px;
      height: 284px;
      margin-top: 21px;

      .select-box-header {
        display: flex;
        gap: 17px;
        margin-bottom: 12px;

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

        .title {
          height: 26px;
          color: var(--color-main-active);
          font-family: Microsoft YaHei;
          font-size: 20px;
          font-weight: 700;
          line-height: 26px;
          letter-spacing: 1px;
          text-align: left;
        }
      }

      .select-main {

        margin-left: 25px;

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

          .filter-checkbox {
            width: 160px;
            height: 24px;

          }
        }

      }

      .select-main1 {
        width: 100px;
      }

      .input-main {
        margin: 10px auto;
        width: 250px;
        height: 34px;
        border-radius: 10px;
        border: 1px solid rgba(230, 231, 232, 1);
      }
    }

    .select-time-box {
      margin-top: 21px;
      width: 360px;
      height: 156px;

      .select-box-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: 26px;
          color: var(--color-main-active);
          font-family: Microsoft YaHei;
          font-size: 20px;
          font-weight: 700;
          line-height: 26px;
          letter-spacing: 1px;
          text-align: left;
        }
      }

      .select-main {

        margin-left: 25px;

        .checkbox-group {
          display: grid;
          grid-template-columns: repeat(2, 1fr);

        }

      }

      .select-main1 {
        width: 100px;
      }

      .input-main {
        margin: 10px auto;
        width: 250px;
        height: 34px;
        border-radius: 10px;
        border: 1px solid rgba(230, 231, 232, 1);
      }
    }
  }

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

    .card-box {
      width: 1226px;
      height: 1248px;
      display: flex;

      flex-wrap: wrap;
      gap: 13px;

      .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);
        transition: transform 0.3s ease, box-shadow 0.3s ease;
        position: relative;

        &:hover {
          transform: translateY(-3px);
          box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
        }

        cursor: pointer;

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

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

        .footer-card-title {
          margin: 0 auto;
          margin-top: 12px;
          width: 360px;

          color: rgb(59, 65, 75);
          font-family: "Source Han Sans CN";
          font-size: 18px;
          font-weight: 700;
          line-height: 24px;
          // 多行省略 + 自动换行（兼容写法）
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box; // webkit 私有：开启弹性盒模型
          display: box; // 标准写法（兜底）
          -webkit-line-clamp: 2; // webkit 私有：限制行数
          line-clamp: 2; // 标准属性：解决兼容性提示
          -webkit-box-orient: vertical; // webkit 私有：垂直排列
          box-orient: vertical; // 标准写法（兜底）

          // 基础换行属性（确保文字能换行）
          word-wrap: break-word;
          word-break: break-all;
          white-space: normal;

        }

        .footer-card-footer {
          position: absolute;
          left: 50%;
          bottom: 15px;
          transform: translateX(-50%);
          margin: 0;
          width: 360px;
          height: 22px;
          display: flex;
          justify-content: space-between;
          color: rgb(95, 101, 108);
          font-family: "Source Han Sans CN";
          font-size: 14px;
          font-weight: 400;
          line-height: 22px;
        }
      }
    }

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

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

:deep(.el-checkbox) {
  margin-right: 0 !important;

}
</style>