<template>
  <div v-if="modelValue" class="modal-mask" @click.self="onClose">
    <div class="modal-wrapper">
      <div class="modal-container">
        <div class="modal-header">
          <h4>{{ title }}</h4>
          <button class="modal-close" @click="onClose">×</button>
        </div>
        <div class="modal-body">
          <slot />
        </div>
        <div class="modal-footer">
          <slot name="footer">
            <button class="btn btn-primary" @click="onClose">确定</button>
          </slot>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue';
const props = defineProps({
  modelValue: Boolean,
  title: {
    type: String,
    default: ''
  }
});
const emit = defineEmits(['update:modelValue']);
function onClose() {
  emit('update:modelValue', false);
}
</script>

<style scoped>
.modal-mask {
  position: fixed;
  z-index: 9999;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-wrapper {
  width: 400px;
  max-width: 98vw;
  max-height: 90vh;
  background: white;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
}
.modal-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 12px 24px;
  border-bottom: 1px solid #e5e7eb;
}
.modal-header h4 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.modal-close {
  background: none;
  border: none;
  font-size: 28px;
  color: #888;
  cursor: pointer;
}
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  max-height: 60vh;
  min-height: 80px;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid #e5e7eb;
}
.btn {
  padding: 6px 18px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
}
.btn-primary {
  background: #222;
  color: #fff;
}
</style> 