<script setup lang="ts">
import { computed } from 'vue';
import { formatNumber } from "@/utils/common";
import { useI18n } from "vue-i18n";

const { t } = useI18n();

interface Props {
  visible: boolean;
  goods: any;
  requiredPoints: number;
  remainingPoints: number;
  expiryDate: string;
}

const props = defineProps<Props>();

const emit = defineEmits<{
  confirm: [];
  cancel: [];
}>();
</script>

<template>
  <Transition name="el2-modal">
    <div v-if="visible" class="el2-modal-wrap" @click="emit('cancel')">
      <div class="el2-modal-box" @click.stop>
        <div class="el2-modal-head">
          <h2 class="el2-modal-title">{{ t("pay_view.confirm_exchange") }}</h2>
        </div>

        <div class="el2-modal-body">
          <!-- 警告信息 -->
          <div class="el2-warn">
            <p class="el2-warn-text">
              <strong>{{ t("pay_view.monthly_limit") }}</strong>
              {{ t("pay_view.monthly_limit_desc", { date: expiryDate }) }}
            </p>
            <p class="el2-warn-text">
              <strong>{{ t("pay_view.final_exchange") }}</strong>
              {{ t("pay_view.final_exchange_desc") }}
            </p>
          </div>

          <!-- 商品信息 -->
          <div class="el2-info">
            <div class="el2-info-row">
              <span class="el2-info-lbl">{{ t("pay_view.selected_prize") }}</span>
              <span class="el2-info-val el2-pname">{{ goods?.title }}</span>
            </div>

            <div class="el2-info-row">
              <span class="el2-info-lbl">{{ t("pay_view.required_points") }}</span>
              <span class="el2-info-val el2-preq">{{ formatNumber(requiredPoints) }}</span>
            </div>

            <div class="el2-info-row">
              <span class="el2-info-lbl">{{ t("pay_view.remaining_points") }}</span>
              <span class="el2-info-val el2-prem">{{ formatNumber(remainingPoints) }}</span>
            </div>
          </div>

          <!-- 确认问题 -->
          <p class="el2-question">{{ t("pay_view.confirm_exchange_question") }}</p>
        </div>

        <div class="el2-modal-foot">
          <button type="button" class="el2-btn-cancel" @click="emit('cancel')">
            {{ t("Cancel") }}
          </button>
          <button type="button" class="el2-btn-ok" @click="emit('confirm')">
            {{ t("pay_view.confirm_btn") }}
          </button>
        </div>
      </div>
    </div>
  </Transition>
</template>

<style scoped>
.el2-modal-wrap {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 20px;
}

.el2-modal-box {
  background: #ffffff;
  border-radius: 16px;
  max-width: 500px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.el2-modal-head {
  background: var(--global-primary-color);
  padding: 20px 20px;
  border-radius: 16px 16px 0 0;
  flex-shrink: 0;
}

.el2-modal-title {
  font-size: 20px;
  font-weight: 700;
  color: #ffffff;
  margin: 0;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.el2-modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.el2-warn {
  background: #FFF9E6;
  border: 2px solid #FFB800;
  border-left: 5px solid #FFB800;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 20px;
}

.el2-warn-text {
  font-size: 13px;
  color: #6B4E00;
  line-height: 1.5;
  margin: 0 0 10px 0;
}

.el2-warn-text:last-child {
  margin-bottom: 0;
}

.el2-warn-text strong {
  font-weight: 700;
  color: #4A3500;
}

.el2-info {
  background: #F8F9FA;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
}

.el2-info-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid #E0E0E0;
}

.el2-info-row:last-child {
  border-bottom: none;
}

.el2-info-lbl {
  font-size: 14px;
  color: #666666;
  font-weight: 500;
}

.el2-info-val {
  font-size: 14px;
  color: #333333;
  font-weight: 600;
  text-align: right;
  max-width: 60%;
}

.el2-info-val.el2-pname {
  color: #000000;
}

.el2-info-val.el2-preq {
  font-size: 17px;
  color: var(--global-primary-color);
  font-weight: 700;
}

.el2-info-val.el2-prem {
  font-size: 17px;
  color: var(--global-primary-color);
  font-weight: 700;
}

.el2-question {
  font-size: 15px;
  font-weight: 600;
  color: #333333;
  text-align: center;
  margin: 16px 0 0 0;
}

.el2-modal-foot {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid #E0E0E0;
  flex-shrink: 0;
  background: #ffffff;
}

.el2-btn-cancel,
.el2-btn-ok {
  width: 100%;
  padding: 14px 24px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.el2-btn-cancel {
  background: #F5F5F5;
  color: #666666;
}

.el2-btn-cancel:hover {
  background: #E0E0E0;
}

.el2-btn-ok {
  background: var(--global-primary-color);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(218, 41, 28, 0.3);
}

.el2-btn-ok:hover {
  background: var(--global-primary-color);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(218, 41, 28, 0.4);
}

.el2-btn-ok:active {
  transform: translateY(0);
}

/* Modal 动画 */
.el2-modal-enter-active,
.el2-modal-leave-active {
  transition: opacity 0.3s ease;
}

.el2-modal-enter-active .el2-modal-box,
.el2-modal-leave-active .el2-modal-box {
  transition: transform 0.3s ease;
}

.el2-modal-enter-from,
.el2-modal-leave-to {
  opacity: 0;
}

.el2-modal-enter-from .el2-modal-box,
.el2-modal-leave-to .el2-modal-box {
  transform: scale(0.9) translateY(20px);
}

/* 响应式 */
@media (max-width: 480px) {
  .el2-modal-box {
    max-width: 95%;
    max-height: 90vh;
  }

  .el2-modal-head {
    padding: 16px;
  }

  .el2-modal-title {
    font-size: 17px;
  }

  .el2-modal-body {
    padding: 16px;
  }

  .el2-warn-text {
    font-size: 12px;
  }

  .el2-info-lbl,
  .el2-info-val {
    font-size: 13px;
  }

  .el2-info-val.el2-preq,
  .el2-info-val.el2-prem {
    font-size: 16px;
  }

  .el2-question {
    font-size: 14px;
  }

  .el2-modal-foot {
    padding: 14px 16px;
  }

  .el2-btn-cancel,
  .el2-btn-ok {
    padding: 12px 20px;
    font-size: 14px;
  }
}
</style>
