<template>
  <div class="device-monitor">
    <!-- 顶部标题栏 -->
    <div class="header">
      <div class="header_title">
        <h2>上海站</h2>
      </div>
      <button class="close-btn" @click="closePanel">×</button>
    </div>
    
    <!-- 标签页导航 -->
    <div class="tabs">
      <div class="tab-btn_forward"></div>
      <div class="tab-btn" :class="{ active: activeTab === 'info' }" @click="activeTab = 'info'">基本信息</div>
      <div class="tab-btn" :class="{ active: activeTab === 'devices' }" @click="activeTab = 'devices'">设备情况</div>
      <div class="tab-btn_backward"></div>
    </div>
    
    <!-- 设备列表内容区 -->
    <div class="content" v-if="activeTab === 'devices'">
      <!-- 设备列表头部 -->
      <div class="table-header">
        <div class="col device-name">设备名称</div>
        <div class="col status">状态</div>
      </div>
      
      <!-- 设备列表 -->
      <div class="device-list">
        <!-- 普通设备项 -->
        <div 
          class="device-item" 
          v-for="(device, index) in devices" 
          :key="index" 
          :class="{ 
            'has-error': device.status === 'error',
            expanded: device.expanded 
          }"
        >
          <!-- 主设备行 -->
          <div class="device-row" :class="device.status === 'error' ? 'has-error' : ''" @click="toggleExpand(device)">
            <div class="col device-name">
              <span 
                v-if="device.status === 'error'" 
                class="toggle-icon"
              >
                {{ device.expanded ? '▾' : '▸' }}
              </span>
              {{ device.name }}
            </div>
            <div class="col status">
              <span class="status-indicator" :class="device.status"></span>
              <span class="status-text">
                {{ device.status === 'normal' ? '正常' : '故障' }}
              </span>
            </div>
          </div>
          
          <!-- 故障详情 -->
          <div 
            class="error-details-container" 
            v-if="device.status === 'error' && device.expanded && device.errorDetails"
          >
            <div class="error-details">
              {{ device.errorDetails }}
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="content content_info" v-else>
      <span>补充基本信息</span>
      <!-- 设备列表头部 -->
      <!-- <div class="table-header">
        <div class="col device-name">设备名称12</div>
        <div class="col status">状态</div>
      </div> -->
      
      <!-- 设备列表 -->
      <!-- <div class="device-list">
        普通设备项
        <div 
          class="device-item" 
          v-for="(device, index) in devices" 
          :key="index" 
          :class="{ 
            'has-error': device.status === 'error',
            expanded: device.expanded 
          }"
        >
          主设备行
          <div class="device-row" :class="device.status === 'error' ? 'has-error' : ''" @click="toggleExpand(device)">
            <div class="col device-name">
              <span 
                v-if="device.status === 'error'" 
                class="toggle-icon"
              >
                {{ device.expanded ? '▾' : '▸' }}
              </span>
              {{ device.name }}
            </div>
            <div class="col status">
              <span class="status-indicator" :class="device.status"></span>
              <span class="status-text">
                {{ device.status === 'normal' ? '正常' : '故障' }}
              </span>
            </div>
          </div>
          
          故障详情
          <div 
            class="error-details-container" 
            v-if="device.status === 'error' && device.expanded && device.errorDetails"
          >
            <div class="error-details">
              {{ device.errorDetails }}
            </div>
          </div>
        </div>
      </div> -->
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';

const props = defineProps(['devices'])
const emits = defineEmits(['errorDialoghandleClose'])

// 状态管理
const activeTab = ref('devices'); // 默认显示设备情况标签页
const devices = ref([
  {
    name: 'KU Anti1',
    status: 'normal',
    errorDetails: null
  },
  {
    name: 'KU Anti2',
    status: 'error',
    expanded: false,
    errorDetails: '上行功放过流保护；基站主控板异常；SCTP链路断开；基站去激活'
  },
  {
    name: '测控基带N',
    status: 'error',
    expanded: false,
    errorDetails: '上行功放过流保护；基站主控板异常；SCTP链路断开；基站去激活'
  },
  {
    name: 'DTE-T',
    status: 'normal',
    errorDetails: null
  },
  {
    name: '光端机',
    status: 'normal',
    errorDetails: null
  },
  {
    name: 'KU Ant1',
    status: 'normal',
    errorDetails: null
  }
]);

// 方法
const toggleExpand = (device) => {
  if (device.status === 'error') {
    device.expanded = !device.expanded;
  }
};

const closePanel = () => {
  emits('errorDialoghandleClose')
};
</script>

<style scoped>
/* 基础样式 */
.device-monitor {
  width: 280px;
  height: 380px;
  background-color: #1e1e2d;
  border-radius: 10px;
  /* box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4); */
  color: #e0e0e0;
  /* font-family: 'Consolas', monospace;  */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999;

}

/* 顶部标题栏 */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 20px;
  /* background: linear-gradient(90deg, #1a237e, #283593); */
  border-bottom: 1px solid #383850;
  position: relative;

}

.header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(56, 56, 80, 0.8), transparent);
}

.header_title h2 {
  margin: 3px;
  padding-left: 5px;
  font-size: 17px;
  font-weight: 500;
  color: #ffffff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.header_title {
  width: 100%;
  height: 100%;
  background-image: url('@/assets/images/lefts/errorHeader.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.close-btn {
  width: 15px;
  height: 15px;
  background: #1E1E2D; 
  border: none;
  color: #aaa;
  font-size: 24px;
  cursor: pointer;
  transition: all 0.2s;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  position: relative;
  top: -4px;
}

.close-btn:hover {
  color: #ffffff;

}

/* 标签页样式 */
.tabs {
  display: flex;
  background: linear-gradient(to bottom, #25253a, #1e1e2d);
  border-bottom: 1px solid #383850;
  justify-content: space-between;
  position: relative;
}

.tabs::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(56, 56, 80, 0.8), transparent);
}

.tab-btn_forward {
  width: 50px;
  padding: 2px 15px;
  background-image: url('@/assets/images/lefts/UnionLeft.png');
  background-size: auto;
  background-repeat: no-repeat;
  background-position: center;
}

.tab-btn_backward {
  width: 50px;
  background-image: url('@/assets/images/lefts/UnionRight.png');
  background-size: auto;
  background-repeat: no-repeat;
  background-position: center;
}

.tab-btn {
  padding: 5px 15px;
  /* width: 100px; */
  cursor: pointer;
  transition: all 0.3s;
  font-size: 15px;
  opacity: 0.8;
  /* border-radius: 6px; */
  position: relative;
  color: #b0b0b0;
  font-weight: 500;
  background: rgba(82, 82, 82, 0.38);
}

.tab-btn.active {
  background: linear-gradient(to bottom, rgba(68, 136, 245, 0.8), rgba(15, 23, 42, 0.8));
  color: #ffffff;
  opacity: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, #4488f5, transparent);
}

.tab-btn:hover:not(.active) {
  color: #e0e0e0;
  opacity: 1;
}

/* 内容区样式 */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  background: linear-gradient(to bottom, #1e1e2d, #191925);
}
.content_info{
  background-color: #4488f5;
}
/* 表格头部 */
.table-header {
  display: flex;
  padding: 5px 25px;
  /* background: linear-gradient(to bottom, #25253a, #1e1e2d); */
  font-weight: 500;
  font-size: 15px;
  color: #a0a0a0;
  border-bottom: 1px solid #383850;
  position: sticky;
  top: 0;
  z-index: 10;
}

.col {
  flex: 1;
}

.device-name {
  flex: 1;
}

.status {
  flex: 1;
  right: 10px;
  text-align: right;
}

/* 设备列表样式 */
.device-list {
  padding: 0 10px;
  max-height: calc(100% - 50px);
  overflow-y: auto;
  z-index: 20;
}

.device-item {
  margin-bottom: 1px;
  border-radius: 6px;
  overflow: hidden;
  transition: all 0.2s;
  /* background-color: rgba(255, 255, 255, 0.02); */
  /* border: 1px solid rgba(255, 255, 255, 0.05); */
}

.device-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
}



.device-row {
  display: flex;
  padding: 8px 15px;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.2s;
}



.has-error .device-row {
  position: relative;
  left: -20px;
  width: 106%;
  /* background-color: rgba(248, 113, 113, 0.05); */
}


/* 展开/折叠图标 */
.toggle-icon {
  display: inline-block;
  width: 18px;
  text-align: center;
  font-size: 14px;
  /* color: #f87171; */
  /* margin-right: 6px; */
  transition: transform 0.2s;
}

.device-item.expanded .toggle-icon {
  transform: rotate(120deg);
}

/* 状态指示样式 */
.status-indicator {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
  box-shadow: 0 0 6px currentColor;
}

.status-indicator.normal {
  background-color: #4ade80;
  color: #4ade80;
}

.status-indicator.error {
  background-color: #ff0000;
  color: #ff0000;
}

.status-text {
  vertical-align: middle;
  font-size: 14px;
  font-weight: 500;
}

/* 故障详情区域 */
.error-details-container {
  background-color: #25253a;
  border-radius: 0 0 6px 6px;
  overflow: hidden;
  animation: fadeIn 0.3s ease-out;
  border-top: 1px solid rgba(248, 113, 113, 0.2);
}

.error-details {
  padding: 12px 20px;
  font-size: 13px;
  color: #e2e8f0;
  background-color: rgba(45, 45, 68, 0.7);
  line-height: 1.6;
}

.error-detail-item {
  margin-bottom: 6px;
  display: flex;
  align-items: flex-start;
}

.error-bullet {
  /* color: #f87171; */
  margin-right: 8px;
  font-size: 16px;
  line-height: 1.3;
}

/* 滚动条样式 */
.content::-webkit-scrollbar {
  width: 8px;
}

.content::-webkit-scrollbar-track {
  background: #25253a;
  border-radius: 4px;
}

.content::-webkit-scrollbar-thumb {
  background: #444460;
  border-radius: 4px;
}

.content::-webkit-scrollbar-thumb:hover {
  background: #555570;
}

.device-list::-webkit-scrollbar {
  width: 6px;
}

.device-list::-webkit-scrollbar-track {
  background: transparent;
}

.device-list::-webkit-scrollbar-thumb {
  background: #444460;
  border-radius: 3px;
}

.device-list::-webkit-scrollbar-thumb:hover {
  background: #555570;
}

/* 动画效果 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 响应式调整 */
@media (max-width: 480px) {
  .device-monitor {
    width: 100%;
    height: 100%;
    border-radius: 0;
  }
}
</style>