<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="全部领域"></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 class="select-hearing-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 researchHearingList" :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="card-content">
          <div v-for="(item, index) in displayList" :key="item.id">
            <div class="card-item">
              <img class="card-item-img" src="../images/img congress.png" alt="report image" />
              <div class="card-item-text">
                <div class="card-item-title">

                  {{ item.title }}
                </div>
                <div class="card-item-time">
                  {{ item.time + ' · ' + item.content }}
                  <img src="../images/image open.png" alt="open icon" class="card-open-image" />
                </div>
                <div class="card-item-category"> {{ item.category }}</div>
              </div>

            </div>
            <div class="divider" v-if="index !== displayList.length - 1"></div>
          </div>
        </div>
      </div>
      <div class="right-footer">
        <div class="info">
          共 {{ hearingData.length }} 项
        </div>
        <div class="page-box">
          <el-pagination :page-size="10" background layout="prev, pager, next" :total="hearingData.length"
            @current-change="handleCurrentChange" :current-page="currentPage" />
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, toRefs, watch, computed } from "vue";

const props = defineProps({
  researchTypeList: {
    type: Array,
    default: () => []
  },
  researchTimeList: {
    type: Array,
    default: () => []
  },
  researchHearingList: {
    type: Array,
    default: () => []
  },
  hearingData: {
    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, researchHearingList, hearingData } = toRefs(props);

const pageSize = 10;
// 只展示当前页的 12 条，否则会一页显示全部 20 条
const displayList = computed(() => {
  const list = hearingData.value || [];
  const start = (currentPage.value - 1) * pageSize;
  return list.slice(start, start + pageSize);
});

// 用本地 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: 874px;
    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);

        }

      }

      .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 {
        margin-bottom: 12px;
        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);
      }
    }

    .select-hearing-box {
      margin-top: 21px;
      width: 360px;

      .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;


        }

      }

      .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: 1224px;
    height: 1377px;

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


      background: rgba(255, 255, 255, 1);
      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);

      .card-content {
        width: 1211px;
        height: 1067px;
        margin-top: 33px;

        margin-left: 37px;

        .card-item {
          width: 100%;
          height: 77px;
          display: flex;
          align-items: center;




          .card-item-img {
            width: 56px;
            height: 77px;
            margin-right: 22px;
            flex-shrink: 0;
          }

          .card-item-text {
            flex: 1;
            min-width: 0;

            flex-direction: column;
            justify-content: space-between;

            display: flex;

            .card-item-title {

              color: rgb(59, 65, 75);
              font-family: "Source Han Sans CN";
              font-size: 18px;
              font-weight: 700;
              line-height: 22px;
              letter-spacing: 0px;
              text-align: left;
              margin-bottom: 2px;
              display: inline-flex;
            }

            .card-item-time {
              color: rgb(95, 101, 108);
              font-family: "Source Han Sans CN";
              font-size: 14px;
              font-weight: 400;
              line-height: 22px;
              letter-spacing: 0px;
              margin-bottom: 7px;
              text-align: left;
              display: inline-flex;

              .card-open-image {
                width: 16px;
                height: 16px;
                margin-left: 9px;
                margin-top: 3px;
              }
            }

            .card-item-category {

              padding: 1px 8px;
              box-sizing: border-box;
              border: 1px solid rgb(231, 243, 255);
              border-radius: 4px;
              display: inline-flex;

              background-color: rgb(247, 248, 249);
              color: rgba(132, 136, 142, 1);
              font-family: Microsoft YaHei;
              font-size: 14px;
              font-weight: 400;
              line-height: 20px;
              letter-spacing: 0px;
              text-align: left;
              width: fit-content;
            }
          }


        }

        .divider {
          height: 1px;
          background: rgb(234, 236, 238);
          margin: 16px 0;
        }


      }

    }

    .right-footer {
      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;
      }
    }
  }
}
</style>