<template>
  <div>
    <!-- Draft Inbox Popup (non-modal, bottom-right) -->
    <div 
      v-if="visible" 
      class="draft-popup"
      @click.stop
    >
      <div class="draft-popup-header">
        <span class="draft-popup-title">草稿箱</span>
        <el-button 
          type="text" 
          icon="el-icon-close" 
          size="mini"
          @click="handleClose"
          class="draft-popup-close"
        ></el-button>
      </div>
      <div class="draft-popup-body">
        <div class="draft-list">
          <div 
            v-for="alert in draftAlerts" 
            :key="alert.id"
            class="draft-item"
            @click="handleSelect(alert)"
          >
            <div class="draft-header">
              <span class="draft-no">{{ alert.alertNo }}</span>
              <span class="draft-time">{{ alert.time }}</span>
            </div>
            <div class="draft-summary">{{ alert.summary || '暂无摘要' }}</div>
            <div class="draft-meta">
              <el-tag size="mini" effect="plain">{{ alert.channel }}</el-tag>
            </div>
          </div>
          <el-empty v-if="draftAlerts.length === 0" description="暂无草稿" :image-size="80"></el-empty>
        </div>
      </div>
    </div>

    <!-- Click outside backdrop (invisible, non-blocking) -->
    <div 
      v-if="visible"
      class="draft-popup-backdrop"
      @click="handleClose"
    ></div>
  </div>
</template>

<script>
export default {
  name: 'DraftInboxPopup',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    draftAlerts: {
      type: Array,
      default: () => []
    }
  },
  methods: {
    handleClose() {
      this.$emit('close')
    },
    handleSelect(alert) {
      this.$emit('select', alert)
    }
  }
}
</script>

<style lang="scss" scoped>
.draft-popup {
  position: fixed;
  bottom: 100px;
  right: 30px;
  width: 400px;
  height: 500px;  /* 改为固定高度，与 AlertFormDialog 类似 */
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 2001;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.draft-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #ebeef5;
  background: #f5f7fa;
  flex-shrink: 0;  /* 防止头部被压缩 */
}

.draft-popup-title {
  font-weight: 600;
  font-size: 16px;
  color: #303133;
}

.draft-popup-close {
  padding: 0;
  color: #909399;
}

.draft-popup-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;  /* 防止水平滚动 */
  padding: 8px;
}

.draft-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.draft-item {
  padding: 12px;
  border: 1px solid #ebeef5;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
}

.draft-item:hover {
  border-color: #409eff;
  background: #f0f9ff;
}

.draft-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.draft-no {
  font-weight: 600;
  color: #303133;
  font-size: 14px;
}

.draft-time {
  color: #909399;
  font-size: 12px;
}

.draft-summary {
  color: #606266;
  font-size: 13px;
  margin-bottom: 8px;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.draft-meta {
  display: flex;
  gap: 8px;
}

.draft-popup-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
  background: transparent;
}
</style>