<template>
  <div class="notice-and-rules-container">
    <div class="container-title">
      <span class="line"></span>
      <span class="title">管理规定与通知</span>
      <el-icon class="more" @click="handleJumpToMoreInfo"><DArrowRight /></el-icon>
    </div>
    <div class="notice-lists" v-loading="loading">
      <div v-if="noticeLists.length === 0" class="empty-style">
        <img class="empty-img" src="@/assets/images/empty.png" alt="" />
        <span>暂无数据</span>
      </div>
      <div v-for="(item, index) in noticeLists" :key="index" class="notice-item" @click="handleJumpToDetail(item.id)">
        <img src="@/assets/svg/bell.svg" alt="" />
        <div class="notice-title">{{ item.title }}</div>
        <div class="notice-info">
          <span>{{ item.pushTime }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { onMounted, ref } from 'vue';
  import { useRouter } from 'vue-router';
  import { ElIcon } from 'element-plus';
  import { DArrowRight } from '@element-plus/icons-vue';
  import { NoticeAndRulesRes, getNoticeAndRules } from '@/api/disaster-overview';

  const router = useRouter();

  const loading = ref(true);
  const noticeLists = ref<NoticeAndRulesRes[]>([]);

  const handleJumpToMoreInfo = () => {
    router.push({
      path: '/disaster-prevention/disaster-warning/defense-notice',
    });
  };

  const handleJumpToDetail = (id: number) => {
    router.push({
      path: '/disaster-prevention/disaster-warning/defense-notice-item',
      query: {
        id: id,
      },
    });
  };

  onMounted(async () => {
    loading.value = true;
    noticeLists.value = await getNoticeAndRules();
    loading.value = false;
  });
</script>

<style lang="scss" scoped>
  .notice-and-rules-container {
    padding: 10px 0;
    display: flex;
    flex-direction: column;

    .container-title {
      height: 24px;
      display: flex;
      align-items: center;
      font-weight: 500;
      font-size: 16px;
      color: #000000;

      .line {
        width: 3px;
        height: 16px;
        background: #1777ff;
        margin-right: 10px;
      }

      .title {
        margin-right: 12px;
      }

      .more {
        margin-left: auto;
        margin-right: 10px;
        cursor: pointer;
        font-size: 14px;
      }
      .more:hover {
        color: #1777ff;
      }
    }

    .notice-lists {
      flex: 1;
      display: flex;
      flex-direction: column;
      // justify-content: space-evenly;
      padding: 0 13px;
      margin-top: 10px;
      overflow: auto;

      .notice-item {
        margin-bottom: 10px;
        display: flex;
        align-items: center;
        cursor: pointer;

        img {
          width: 18px;
          height: 17px;
          margin-right: 10px;
        }

        .notice-title {
          width: 60%;
          font-size: 14px;
          color: rgba(0, 0, 0, 0.85);
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }

        .notice-info {
          font-size: 12px;
          color: rgba(0, 0, 0, 0.45);
          margin-left: auto;
          display: flex;
        }
      }

      .notice-item:hover {
        .notice-title {
          color: #1777ff;
        }
      }
    }
  }

  .empty-style {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 12px;
    color: rgba(0, 0, 0, 0.5);

    .empty-img {
      height: 80%;
      object-fit: contain;
    }
  }
</style>
