<template>
  <view class="popup-mask" v-if="visible" @click="handleCancel">
    <view class="popup-content" @click.stop>
      <text class="popup-title">{{ t('redeem.title') }}</text>
      <view class="popup-body" v-if="coupon">
        <text class="coupon-name">{{ coupon.name }}</text>
        <text class="points-needed">{{ t('redeem.pointsNeeded', { points: coupon.requiredPoints }) }}</text>
      </view>
      <view class="popup-actions">
        <view class="btn cancel-btn" @click="handleCancel">
          <text class="btn-text cancel-text">{{ t('common.cancel') }}</text>
        </view>
        <view class="btn confirm-btn" @click="handleConfirm">
          <text class="btn-text confirm-text">{{ t('redeem.confirmBtn') }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { useI18n } from 'vue-i18n'

const { t } = useI18n()

defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  coupon: {
    type: Object,
    default: null
  }
})

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

function handleConfirm() {
  emit('confirm')
}

function handleCancel() {
  emit('cancel')
}
</script>

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

.popup-content {
  width: 600rpx;
  background-color: #ffffff;
  border-radius: 24rpx;
  padding: 40rpx;
}

.popup-title {
  font-size: 34rpx;
  font-weight: 600;
  color: #333;
  text-align: center;
  display: block;
  margin-bottom: 30rpx;
}

.popup-body {
  text-align: center;
  margin-bottom: 40rpx;
}

.coupon-name {
  font-size: 30rpx;
  color: #333;
  display: block;
  margin-bottom: 16rpx;
}

.points-needed {
  font-size: 28rpx;
  color: #ff6600;
  display: block;
}

.popup-actions {
  display: flex;
  gap: 20rpx;
}

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

.cancel-btn {
  background-color: #f5f5f5;
}

.confirm-btn {
  background-color: #007aff;
}

.btn-text {
  font-size: 28rpx;
}

.cancel-text {
  color: #666;
}

.confirm-text {
  color: #ffffff;
}
</style>
