<template>
  <div v-if="visible">
    <!-- 浮动弹窗（右下角） -->
    <div 
      class="alert-form-dialog"
      @click.stop
    >
      <!-- 头部 -->
      <div class="alert-form-dialog-header">
        <span class="alert-form-dialog-title">{{ title }}</span>
        <el-button 
          type="text" 
          icon="el-icon-close" 
          size="mini"
          @click="handleClose"
          class="alert-form-dialog-close"
        ></el-button>
      </div>
      
      <!-- 内容区域（可滚动） -->
      <div class="alert-form-dialog-body">
        <AlertForm
          ref="alertForm"
          :form-data="formData"
          :source-channels="sourceChannels"
          :alert-levels="alertLevels"
          :editing-alert-id="editingAlertId"
          :editing-alert-status="editingAlertStatus"
          :submitting="submitting"
          :compact="false"
          @open-location-picker="handleOpenLocationPicker"
          @save-draft="handleSaveDraft"
          @submit="handleSubmit"
          @update="handleUpdate"
        />
      </div>
    </div>

    <!-- 透明背景遮罩（点击外部关闭） -->
    <div 
      class="alert-form-dialog-backdrop"
      @click="handleClose"
    ></div>
  </div>
</template>

<script>
import AlertForm from './AlertForm.vue'

export default {
  name: 'AlertFormDialog',
  components: {
    AlertForm
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    formData: {
      type: Object,
      required: true
    },
    sourceChannels: {
      type: Array,
      default: () => []
    },
    alertLevels: {
      type: Array,
      default: () => []
    },
    editingAlertId: {
      type: [String, Number],
      default: null
    },
    editingAlertStatus: {
      type: String,
      default: null
    },
    submitting: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    title() {
      return this.editingAlertId ? '编辑警情' : '接警录入'
    }
  },
  methods: {
    handleClose() {
      this.$emit('close')
    },
    handleOpenLocationPicker() {
      this.$emit('open-location-picker')
    },
    handleSaveDraft() {
      this.$emit('save-draft')
    },
    handleSubmit() {
      this.$emit('submit')
    },
    handleUpdate() {
      this.$emit('update')
    }
  }
}
</script>

<style lang="scss" scoped>
.alert-form-dialog {
  position: fixed;
  bottom: 100px;  /* 与 DraftInboxPopup 保持一致 */
  right: 30px;    /* 与 DraftInboxPopup 保持一致 */
  width: 400px;
  height: 700px;
  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;
}

.alert-form-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #ebeef5;
  background: #f5f7fa;
  flex-shrink: 0;
}

.alert-form-dialog-title {
  font-weight: 600;
  font-size: 16px;
  color: #303133;
}

.alert-form-dialog-close {
  padding: 0;
  color: #909399;
}

.alert-form-dialog-close:hover {
  color: #303133;
}

.alert-form-dialog-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
}

.alert-form-dialog-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
  background: transparent;  /* 透明背景，与 DraftInboxPopup 一致 */
}
</style>