<template>
  <div v-if="visible" class="dialog-mask" @click.self="handleClose">
    <div class="dialog">
      <div class="dialog-header">
        <span class="dialog-title">修改预警距离</span>
        <img class="dialog-close" :src="closeIcon" alt="close" @click="handleClose" />
      </div>

      <div class="dialog-body">
        <div class="form-row">
          <span class="form-label">告警距离调整：</span>
          <input v-model="form.vehicleDistance" class="form-input" placeholder="无人车报警距离" />
          <input v-model="form.aircraftDistance" class="form-input" placeholder="飞机告警距离" />
        </div>
        <div class="form-row">
          <span class="form-label">分离距离调整：</span>
          <input v-model="form.separationDistance" class="form-input" placeholder="请输入..." />
        </div>
      </div>

      <div class="dialog-footer">
        <button class="footer-btn cancel" @click="handleClose">取消</button>
        <button class="footer-btn confirm" @click="handleConfirm">确定</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue'
import closeIcon from '@/assets/images/close_icon.png'

const props = defineProps({
  visible: { type: Boolean, default: false }
})

const emit = defineEmits(['close', 'confirm'])

const form = ref({
  vehicleDistance: '',
  aircraftDistance: '',
  separationDistance: ''
})

function handleClose() {
  emit('close')
}

function handleConfirm() {
  emit('confirm', { ...form.value })
}

watch(
  () => props.visible,
  (v) => {
    if (!v) return
    form.value = { vehicleDistance: '', aircraftDistance: '', separationDistance: '' }
  }
)
</script>

<style scoped>
.dialog-mask {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 4000;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}

.dialog {
  width: 620px;
  max-width: calc(100vw - 40px);
  background-color: #424851;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  color: #ffffff;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid #303850;
}

.dialog-title {
  font-size: 18px;
  font-weight: 600;
}

.dialog-close {
  width: 22px;
  height: 22px;
  cursor: pointer;
}

.dialog-body {
  padding: 18px 22px 8px;
}

.form-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.form-label {
  width: 140px;
  text-align: right;
  font-size: 14px;
  color: #dcdcdc;
  white-space: nowrap;
}

.form-input {
  flex: 1;
  height: 34px;
  border-radius: 4px;
  border: 1px solid rgba(47, 122, 185, 0.9);
  outline: none;
  background: rgba(0, 150, 255, 0.08);
  color: #ffffff;
  padding: 0 12px;
}

.form-input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.dialog-footer {
  padding: 12px 18px 16px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  border-top: 1px solid #303850;
}

.footer-btn {
  width: 88px;
  height: 34px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid rgba(47, 122, 185, 0.8);
  background: rgba(0, 150, 255, 0.08);
  color: #ffffff;
}

.footer-btn.confirm {
  background: #0096ff;
  border-color: #0078cc;
}
</style>
