<template>
  <div class="main-box display p_10" style="box-sizing: border-box">
    <div class="nav-menu">
      <div
        v-for="(item, index) in menuItems"
        :key="index"
        class="nav-item"
        :class="{ active: activeIndex === index }"
        @click="activeIndex = index"
      >
        <div class="nav-icon">
          <!-- <i :class="item.icon"></i> -->
          <img :src="activeIndex === index ? item.icon1 : item.icon" alt="" />
        </div>
        <div class="nav-label">{{ item.label }}</div>
      </div>
    </div>
    <!-- 气象预警监测表格 -->
    <div class="weather-warning-wrapper" style="padding-left: 6px">
      <div class="weather-warning-panel">
        <img
          class="clear-icon"
          src="../../assets/RiskWarning_img/清除icon@2x.png"
          alt=""
        />
        <div class="panel-header">
          <div class="header-title">气象预警监测</div>
          <div class="filter-tags">
            <label class="tag">
              <input type="checkbox" v-model="filters.red" />
              <span class="">红色预警</span>
            </label>
            <label class="tag">
              <input type="checkbox" v-model="filters.blue" />
              <span class="">蓝色预警</span>
            </label>
            <label class="tag">
              <input type="checkbox" v-model="filters.orange" />
              <span class="">橙色预警</span>
            </label>
            <label class="tag">
              <input type="checkbox" v-model="filters.yellow" />
              <span class="">黄色预警</span>
            </label>
          </div>
        </div>
        <div class="table-container">
          <el-table
            :data="filteredData"
            height="100%"
            style="width: 100%; background: transparent"
            :header-cell-style="headerCellStyle"
            :cell-style="cellStyle"
            :row-class-name="rowClassName"
          >
            <el-table-column prop="time" label="预警时间" min-width="140" />
            <el-table-column prop="type" label="类型" min-width="80" align="center" />
            <el-table-column label="预警等级" min-width="100" align="center">
              <template #default="{ row }">
                <!-- <span class="warning-level" :class="row.levelClass">
                  <i class="level-icon"></i>
                  {{ row.level }}
                </span> -->
                <div class="warning-level">
                  <img
                    :src="
                      row.levelClass === 'red'
                        ? redIcon
                        : row.levelClass === 'blue'
                        ? blueIcon
                        : row.levelClass === 'orange'
                        ? orangeIcon
                        : yellowIcon
                    "
                    alt=""
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="district" label="预警区县" min-width="80" />
          </el-table>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from "vue";
import { ElTable } from "element-plus";
import orangeIcon from "../../assets/RiskWarning_img/橙色@2x.png";
import yellowIcon from "../../assets/RiskWarning_img/黄色@2x.png";
import redIcon from "../../assets/RiskWarning_img//红色@2x.png";
import blueIcon from "../../assets/RiskWarning_img/蓝色@2x.png";

import warningIconIcon from "../../assets/RiskWarning_img/风险预警icon@2x.png";
import tunnelIconIcon from "../../assets/RiskWarning_img/隧道icon@2x.png";
import slopeIconIcon from "../../assets/RiskWarning_img/边坡icon@2x.png";
import bridgeIconIcon from "../../assets/RiskWarning_img/桥梁icon@2x.png";
import roadIconIcon from "../../assets/RiskWarning_img/线路路段icon@2x.png";

import warningIconIcon1 from "../../assets/RiskWarning_img/风险预警icon1@2x.png";
import tunnelIconIcon1 from "../../assets/RiskWarning_img/隧道icon1@2x.png";
import slopeIconIcon1 from "../../assets/RiskWarning_img/边坡icon1@2x.png";
import bridgeIconIcon1 from "../../assets/RiskWarning_img/桥梁icon1@2x.png";
import roadIconIcon1 from "../../assets/RiskWarning_img/线路路段icon1@2x.png";

const activeIndex = ref(0);

const menuItems = [
  {
    label: "项目",
    icon: "icon-warning",
    iconClass: "warning",
    icon: warningIconIcon,
    icon1: warningIconIcon1,
  },
  {
    label: "隧道",
    icon: "icon-tunnel",
    iconClass: "tunnel",
    icon: tunnelIconIcon,
    icon1: tunnelIconIcon1,
  },
  {
    label: "边坡",
    icon: "icon-slope",
    iconClass: "slope",
    icon: slopeIconIcon,
    icon1: slopeIconIcon1,
  },
  {
    label: "桥梁",
    icon: "icon-bridge",
    iconClass: "bridge",
    icon: bridgeIconIcon,
    icon1: bridgeIconIcon1,
  },
  {
    label: "路段",
    icon: "icon-road",
    iconClass: "road",
    icon: roadIconIcon,
    icon1: roadIconIcon1,
  },
];

// 筛选状态
const filters = ref({
  red: false,
  blue: false,
  orange: false,
  yellow: false,
});

// 预警数据
const warningData = ref([
  {
    time: "2025-11-18 09:24:81",
    type: "暴雨",
    level: "蓝色预警",
    levelClass: "blue",
    district: "合川区",
  },
  {
    time: "2025-11-12 09:24:81",
    type: "冰雪",
    level: "红色预警",
    levelClass: "red",
    district: "万州区",
  },
  {
    time: "2025-11-12 09:24:81",
    type: "大雾",
    level: "橙色预警",
    levelClass: "orange",
    district: "涪陵区",
  },
  {
    time: "2025-11-12 09:24:81",
    type: "大风",
    level: "黄色预警",
    levelClass: "yellow",
    district: "城口县",
  },
]);

// 过滤后的数据
const filteredData = computed(() => {
  const hasFilter =
    filters.value.red ||
    filters.value.blue ||
    filters.value.orange ||
    filters.value.yellow;
  if (!hasFilter) return warningData.value;

  return warningData.value.filter((item) => {
    if (filters.value.red && item.levelClass === "red") return true;
    if (filters.value.blue && item.levelClass === "blue") return true;
    if (filters.value.orange && item.levelClass === "orange") return true;
    if (filters.value.yellow && item.levelClass === "yellow") return true;
    return false;
  });
});

// el-table 样式
const headerCellStyle = () => ({
  background: "transparent",
  color: "rgba(255, 255, 255, 0.6)",
  fontWeight: "normal",
  borderBottom: "1px solid rgba(64, 169, 255, 0.2)",
  padding: "10px 8px",
});

const cellStyle = () => ({
  background: "transparent",
  color: "rgba(255, 255, 255, 0.9)",
  borderBottom: "1px solid rgba(64, 169, 255, 0.1)",
  padding: "12px 8px",
});

const rowClassName = ({ rowIndex }) => {
  return rowIndex % 2 === 0 ? "even-row" : "odd-row";
};
</script>

<style lang="scss" scoped>
.main-box {
  position: relative;
}
.nav-menu {
  width: 50px;
  display: flex;
  flex-direction: column;
  justify-content: end;
  align-items: center;
  gap: 5px;

  .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;

    &:hover,
    &.active {
      .nav-icon {
        background: rgba(64, 169, 255, 0.3);
        border-color: rgba(64, 169, 255, 0.6);
      }

      .nav-label {
        color: #40a9ff;
      }
    }

    .nav-icon {
      width: 50px;
      height: 50px;
      margin-bottom: 5px;
      background: rgba(64, 169, 255, 0.1);
      border: 1px solid rgba(64, 169, 255, 0.3);
      border-radius: 8px;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.3s ease;
      img {
        width: 50px;
        width: 50px;
      }

      i {
        font-size: 24px;
        color: #40a9ff;
      }

      // 使用 emoji 作为图标占位
      &.warning::before {
        content: "📍";
        font-size: 24px;
      }

      &.tunnel::before {
        content: "🚇";
        font-size: 24px;
      }

      &.slope::before {
        content: "⛰️";
        font-size: 24px;
      }

      &.bridge::before {
        content: "🌉";
        font-size: 24px;
      }

      &.road::before {
        content: "🛣️";
        font-size: 24px;
      }
    }

    .nav-label {
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 12px;
      color: #fff;
      transition: all 0.3s ease;
    }
  }
}

// 气象预警监测包装器
.weather-warning-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  width: 90%;
}

// 气象预警监测面板样式
.weather-warning-panel {
  height: 60%;
  background: linear-gradient(
    180deg,
    rgba(21, 41, 59, 0.95) 0%,
    rgba(13, 28, 42, 0.95) 100%
  );
  border: 1px solid rgba(64, 169, 255, 0.3);
  border-radius: 8px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  position: relative;
  .clear-icon {
    position: absolute;
    top: -50px;
    right: 0px;
    width: 40px !important;
    height: 40px !important;
  }

  .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;

    .header-title {
      font-size: 18px;
      font-weight: bold;
      color: #40a9ff;
      position: relative;
      padding-left: 12px;

      &::before {
        content: "";
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 4px;
        height: 16px;
        background: linear-gradient(180deg, #40a9ff 0%, #1890ff 100%);
        border-radius: 2px;
      }
    }

    .filter-tags {
      display: flex;
      gap: 15px;

      .tag {
        display: flex;
        align-items: center;
        gap: 5px;
        cursor: pointer;

        input {
          width: 14px;
          height: 14px;
          accent-color: #40a9ff;
        }

        span {
          font-size: 12px;
          color: rgba(255, 255, 255, 0.8);

          &.tag-red {
            color: #ff4d4f;
          }

          &.tag-blue {
            color: #40a9ff;
          }

          &.tag-orange {
            color: #ff7a45;
          }

          &.tag-yellow {
            color: #ffc53d;
          }
        }
      }
    }
  }

  .table-container {
    flex: 1;
    overflow: hidden;

    :deep(.el-table__body-wrapper) {
      scrollbar-width: none;
      -ms-overflow-style: none;

      &::-webkit-scrollbar {
        display: none;
      }
    }
  }

  // el-table 样式
  :deep(.el-table) {
    background: transparent;

    &::before {
      display: none;
    }

    .el-table__inner-wrapper {
      background: transparent;
    }
    .el-table__inner-wrapper:before {
      width: 0%;
    }

    .el-table__header-wrapper {
      background: transparent;
    }

    .el-table__body-wrapper {
      background: transparent;
    }

    tr {
      background: transparent;

      &:hover {
        background: rgba(64, 169, 255, 0.05) !important;
      }
    }

    th.el-table__cell {
      background: transparent;
    }

    td.el-table__cell {
      background: transparent;
    }
  }

  .warning-level {
    // display: inline-flex;
    // align-items: center;
    // gap: 5px;
    // padding: 4px 10px;
    // border-radius: 4px;
    // font-size: 12px;
    // width: 15px;
    // height: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    img {
      width: 15px;
      height: 15px;
    }

    // .level-icon {
    //   width: 0;
    //   height: 0;
    //   border-left: 6px solid transparent;
    //   border-right: 6px solid transparent;
    //   border-bottom: 10px solid currentColor;
    // }

    &.red {
      color: #ff4d4f;
      background: rgba(255, 77, 79, 0.1);
    }

    &.blue {
      color: #40a9ff;
      background: rgba(64, 169, 255, 0.1);
    }

    &.orange {
      color: #ff7a45;
      background: rgba(255, 122, 69, 0.1);
    }

    &.yellow {
      color: #ffc53d;
      background: rgba(255, 197, 61, 0.1);
    }
  }
}
</style>
