<template>
  <div class="dashboard-container">
   

    <!-- 主内容区 -->
    <main class="main-content">
      <!-- 左侧区域 (三部分) -->
      <div class="left-section">
        <!-- 左侧上部分 (又分为左右两部分) -->
        <div class="left-top">
          <!-- 左侧上左：区域信息概览 -->
          <div class="info-card region-overview">
            <div class="card-header">
              <h2>区域信息概览</h2>
            </div>
            <div class="info-grid" >
              <div class="info-item" v-for="(item,index) in OverviewRegionalInformation" :key="index">
                <span class="label">{{item.label}}:</span>
                <span class="value">{{item.value}}</span>
              </div>
            
            </div>
          </div>

          <!-- 左侧上右：区域地图 -->
          <div class="info-card region-map">
            <img src="../../static//image/login_bg.png" alt="阳光花园小区航拍图" class="map-image" />
          </div>
        </div>

        <!-- 左侧下部分：历史火情统计和传感器警报 -->
        <div class="info-card stats-alerts">
          <div class="card-tabs">
            <span class="tab-btn" >历史火情统计</span>
    
          </div>
          
          <!-- 历史火情统计面板 -->
          <div  class="tab-content history-stats">
            <div class="time-filter">
              <el-select v-model="historyFireSelectTime" placeholder="选择数据查看范围" style="width: 240px" class="filter-select" @change="historyFireSelectTimeFn">
                    <el-option
                        v-for="item in historyFireTimeData"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    />
              </el-select>
              
            </div>
            <div class="chart-container" >
                <div id="historyChart" class="chart" style="width: 100%; height: 100%"></div>
            </div>
          </div>
          
        
        </div>
      </div>

      <!-- 右侧区域 (一个部分) -->
      <div class="right-section">
        <div class="info-card current-situation">
          <div class="card-header">
            <h2>当前火情</h2>
            <button class="more-btn">更多 <i class="icon-more"></i></button>
          </div>
          
          <div class="situation-list ">
            <!-- 火情项目 1 - 紧急 -->
            <div class="situation-item emergency">
              <div class="situation-icon">
                <i class="icon-fire-red"></i>
              </div>
              <div class="situation-content">
                <p><span class="location">金色家园小区 四单元 七号搂 3楼</span></p>
                <p><span class="severity">火情等级: 四级 (大规模)</span></p>
                <p><span class="status">处理状态: 消防人员已到达现场</span></p>
                <p><span class="time">2025年8月7日 11:14 发现</span></p>
              </div>
            </div>
            
            <!-- 火情项目 2 - 重要 -->
            <div class="situation-item important">
              <div class="situation-icon">
                <i class="icon-fire-orange"></i>
              </div>
              <div class="situation-content">
                <p><span class="location">金象嘉园小区 四单元 十七号搂 3楼</span></p>
                <p><span class="severity">火情等级: 四级 (大规模)</span></p>
                <p><span class="status">处理状态: 消防人员已到达现场</span></p>
                <p><span class="time">2025年8月7日 11:11 发现</span></p>
              </div>
            </div>
            
            <!-- 火情项目 3 - 已控制 -->
            <div class="situation-item controlled">
              <div class="situation-icon">
                <i class="icon-fire-yellow"></i>
              </div>
              <div class="situation-content">
                <p><span class="location">幸福里小区 五单元 二号搂 12楼</span></p>
                <p><span class="severity">火情等级: 四级 (大规模)</span></p>
                <p><span class="status">处理状态: 火势已得到控制</span></p>
                <p><span class="time">2025年8月7日 10:45 发现</span></p>
              </div>
            </div>
            
          </div>
        </div>
        <div class="info-card current-situation1">  
            <div class="card-header">
            <h2>传感器报警</h2>
            <button class="more-btn">更多 <i class="icon-more"></i></button>
          </div>
        </div>
      </div>
    </main>
  </div>
</template>

<script  setup>
    import * as echarts from 'echarts';
    import { ref, onMounted, computed } from 'vue';

    // 定义一个OverviewRegionalInformation变量，用于存储小区信息
    const OverviewRegionalInformation = ref([
        {label: "小区名称",value: "阳光花园"}, // 小区名称为阳光花园
        {label: "小区建筑数量",value: "12栋"}, // 小区建筑数量为12栋
        {label: "配备无人机数量",value: "5台"}, // 配备无人机数量为5台
        {label: "当前可用无人机数量",value: "3台"}, // 当前可用无人机数量为3台
        {label: "最近火情发生时间",value: "2023-05-15 14:30"}, // 最近火情发生时间为2023-05-15 14:30
        {label: "配备无人机数量",value: "5台"}, // 配备无人机数量为5台
        {label: "当前可用无人机数量",value: "3台"}, // 当前可用无人机数量为3台
        {label: "最近火情发生时间",value: "2023-05-15 14:30"}]
    );
    // 定义一个响应式的变量，用于存储历史数据的时间选择
    const historyFireSelectTime = ref('')
    const historyFireTimeData = ref([
        {label:"近一个月",value: 30},
        {label:"近三个月",value: 90},
        {label:"近半年",value: 180},
        {label:"近一年",value: 365}
    ])
    const historyFireSelectTimeFn = () => {
       
        console.log(historyFireSelectTime.value,"0000000000000000000")

    }

    const initFireHistoryChart = () => {
        var chartDom = document.getElementById('historyChart');
        var myChart = echarts.init(chartDom);
        var option;

        option = {
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
            type: 'value'
        },
        series: [
            {
            data: [820, 932, 901, 934, 1290, 1330, 1320],
            type: 'line',
            areaStyle: {}
            }
        ]
        };
        
        // 监听窗口大小变化，调整图表尺寸
        window.addEventListener('resize', () => {
            myChart.resize();
        });
        option && myChart.setOption(option);
    }

  

    // 挂载时初始化
    onMounted(() => {
        initFireHistoryChart()
 
    });

  
</script>

<style scoped>
/* 基础样式 */
.dashboard-container {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: #f5f7fa;
  min-height: 100vh;
  color: #333;
  /* background-color: #10b981; */
  max-height: 100%;      /* 设置最大高度 */
  overflow-y: auto;       /* 内容超出时显示垂直滚动条 */
  
  /* 美化滚动条样式 */
  scrollbar-width: thin;  /* Firefox */
  scrollbar-color: #c1c1c1 #f1f1f1;  /* Firefox */
}

/* 主内容区样式 */
.main-content {
  display: flex;
  gap: 1rem;
  padding: 0.4rem;
  max-width: 1920px;
  max-height: 100%;      /* 设置最大高度 */
  overflow-y: auto;       /* 内容超出时显示垂直滚动条 */
  
  /* 美化滚动条样式 */
  scrollbar-width: thin;  /* Firefox */
  scrollbar-color: #c1c1c1 #f1f1f1;  /* Firefox */
  /* margin: 0 auto; */
}

/* 左侧区域样式 */
.left-section {
  flex: 2;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: 100%;
}

.left-top {
  display: flex;
  gap: 1rem;
  height: 350px;
}

/* 卡片通用样式 */
.info-card {
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  padding: 1rem;
  position: relative;        /* 确保卡片有定位上下文 */
  width: 100%;   

    height: 100%;
    
  
}

.info-card.hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.info-card.refreshing {
  animation: pulse 1.5s infinite;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  /* margin-bottom: 1rem; */
  /* padding-bottom: 0.5rem; */
  /* background-color: #10b981; */
  border-bottom: 1px solid #f1f1f1;

}

.card-header h2 {
  font-size: 1.2rem;
  color: #1e40af;
  margin: 0;
}

/* 区域信息概览 */
.region-overview {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.info-grid {
  display: flex;
  flex-direction: column;  /* 竖排排列 */
  justify-content: center; /* 垂直居中 */
  gap: 1rem;  

  padding-right: 10px;

   overflow-y: auto;       /* 内容超出时显示垂直滚动条 */
  /* 美化滚动条样式 */
  scrollbar-width: thin;  
  scrollbar-color: #c1c1c1 #f1f1f1;
   
}

.info-item {
  display: flex;          /* 水平排列 */
  justify-content: space-between; /* 两端对齐，使label左对齐，value右对齐 */
  align-items: center;    /* 垂直居中 */
  /* padding: 5px 0;         */
  border-bottom: 1px solid #eee; /* 底部边框 */

}

.info-item .label {
  font-size: 0.9rem;
  color: #666;
  margin-bottom: 0.3rem;
}

.info-item .value {
  font-size: 0.9rem;
  font-weight: 600;

}

.available-count {
  color: #10b981;
}

/* 区域地图 */
.region-map {
  flex: 2;
  padding: 0;
  position: relative;
  overflow: hidden;
}

.map-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.region-map:hover .map-image {
  transform: scale(1.02);
}




/* 左侧下部分：历史统计和传感器警报 */
.stats-alerts {
  flex-grow: 1;
  min-height: 380px;
  /* overflow: auto; */
  /* min-height: 400px; */
}

.card-tabs {
  display: flex;
  border-bottom: 1px solid #f1f1f1;
  margin-bottom: 0.5rem;
  font-size: 1.2rem;
  color: #1e40af;
  /* margin: 0; */
}


.tab-content {
  height: calc(100% - 60px);
}

/* 历史火情统计 */
.history-stats {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.time-filter {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.chart-container{
    background-color: #10b981;
    height: 76%;
    width: 100%;
    position: relative;
    margin: 0 auto;
    padding: 0;
    box-sizing: border-box;
    /* overflow: auto; */
}
.chart{
  width: 100%;          /* 宽度占满容器 */
  height: 100%;         /* 高度占满容器 */
  position: absolute;   /* 绝对定位 */
  top: 0;               /* 顶部对齐 */
  left: 0;              /* 左侧对齐 */
    background-color: #10b981;
}
.filter-select {
  /* padding: 0.4rem 0.6rem; */
  border-radius: 4px;
  /* border: 1px solid #ddd; */
  background-color: white;
}



/* 传感器警报 */
.sensor-alerts {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* 右侧区域样式 */
.right-section {
  flex: 1;
  /* background-color: #1e40af; */
}

.current-situation {
  height: 47%;
  display: flex;
  flex-direction: column;
  margin-bottom: 1rem;
  /* background-color: #10b981; */
}
.current-situation1 {
  height: 51%;
  display: flex;
  flex-direction: column;
  /* margin-bottom: 1%; */
  /* background-color: #10b981; */
}

.situation-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
  flex-grow: 1;
  padding-right: 0.5rem;
  /* position: fixed */
}

/* 火情项目样式 */
.alert-item, .situation-item {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  border-radius: 6px;
  background-color: #f9f9f9;
  border-left: 4px solid transparent;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.alert-item:hover, .situation-item:hover {
  transform: translateX(4px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.alert-item.resolved, .situation-item.controlled {
  border-left-color: #10b981;
}

.alert-item.warning, .situation-item.important {
  border-left-color: #f59e0b;
}

.situation-item.emergency {
    /* position: fixed; */
  border-left-color: #ef4444;
  background-color: rgba(239, 68, 68, 0.03);
}

.alert-icon, .situation-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.situation-item.emergency .situation-icon {
  background-color: rgba(239, 68, 68, 0.1);
}

.situation-item.important .situation-icon {
  background-color: rgba(245, 158, 11, 0.1);
}

.situation-item.controlled .situation-icon {
  background-color: rgba(16, 185, 129, 0.1);
}

.alert-content, .situation-content {
  flex-grow: 1;
}

.alert-content h4, .situation-content h4 {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  color: #333;
}

.alert-item .alert-status {
  flex-shrink: 0;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 500;
}

.alert-status {
  background-color: #10b981;
  color: white;
}

.alert-status.warning {
  background-color: #f59e0b;
  color: white;
}

.situation-content p {
  margin: 0.2rem 0;
  font-size: 0.9rem;
  color: #444;
}

.situation-content .location {
  font-weight: 500;
  color: #1e40af;
}

.situation-content .severity {
  color: #ef4444;
}

.situation-content .status {
  color: #10b981;
}

.situation-content .time {
  color: #666;
  font-size: 0.85rem;
}

.load-more {
  background: none;
  border: 1px dashed #ddd;
  color: #666;
  padding: 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.load-more:hover {
  border-color: #1e40af;
  color: #1e40af;
}

/* 图标样式 */
.icon-refresh-small {
  color: #999;
  cursor: pointer;
  transition: color 0.2s ease;
}

.icon-refresh-small:hover {
  color: #1e40af;
}

/* 动画效果 */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.7; }
  100% { opacity: 1; }
}

/* 响应式调整 */
@media (max-width: 1400px) {
  .main-content {
    flex-direction: column;
  }
  
  .left-top {
    height: auto;
  }
}

@media (max-width: 992px) {
  .left-top {
    flex-direction: column;
    height: auto;
  }
  
  .info-grid {
    grid-template-columns: 1fr;
  }
}

/* 自定义滚动条 */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}

::-webkit-scrollbar-thumb {
  background: #bbb;
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: #999;
}
</style>