<template>
  <view v-show="visible" class="modal-overlay" :class="{ 'modal-visible': visible }" @tap="handleCancel">
    <view class="modal-box" @tap.stop>
      <!-- 标题 -->
      <view v-if="title" class="modal-title">
        <text>{{ title }}</text>
      </view>

      <!-- 内容 -->
      <view class="modal-body">
        <text class="modal-content">{{ content }}</text>
      </view>

      <!-- 按钮区 -->
      <view class="modal-actions">
        <view v-if="showCancel" class="btn btn-cancel" @tap="handleCancel">
          <text>{{ cancelText }}</text>
        </view>
        <view class="btn btn-confirm" @tap="handleConfirm">
          <text>{{ confirmText }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  inheritAttrs: false,
};
</script>

<script setup>
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  title: {
    type: String,
    default: ''
  },
  content: {
    type: String,
    default: ''
  },
  confirmText: {
    type: String,
    default: '确认'
  },
  cancelText: {
    type: String,
    default: '取消'
  },
  showCancel: {
    type: Boolean,
    default: true
  }
})

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

function handleConfirm() {
  emit('confirm', { confirm: true })
}

function handleCancel() {
  emit('cancel', { confirm: false })
}
</script>

<style scoped>
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.modal-overlay.modal-visible {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  width: 560rpx;
  background: #fff;
  border-radius: 24rpx;
  overflow: hidden;
  padding: 48rpx 40rpx 32rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.modal-title {
  font-size: 34rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 32rpx;
}

.modal-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12rpx;
  margin-bottom: 40rpx;
}

.modal-content {
  font-size: 28rpx;
  color: #555;
  text-align: center;
  white-space: pre-line;
}

.modal-actions {
  width: 100%;
  display: flex;
  gap: 24rpx;
}

.btn {
  flex: 1;
  height: 80rpx;
  border-radius: 40rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30rpx;
}

.btn-cancel {
  background: #f0f0f0;
  color: #666;
}

.btn-confirm {
  background: linear-gradient(to right, #F08399, #B94E73);
  color: #fff;
}
</style>
