<template>
  <!-- 使用规则弹窗 -->
  <BasicModal type="bottom" v-model:open="getOpen" :is-mack="true">
    <view class="rules-modal">
      <!-- 标题栏 -->
      <view class="rules-modal__header">
        <text class="header-title">使用规则</text>
        <view class="close-btn" @click="handleClose">
          <view class="close-icon"></view>
        </view>
      </view>

      <!-- 优惠券卡片 - 与列表页样式一致 -->
      <view class="coupon-card-wrapper">
        <view class="coupon-card">
          <image :src="getFileUrl('img/personal/coupon.png')" mode="widthFix" class="coupon-card-bg"></image>
          <image :src="getFileUrl('img/personal/couponLeft.png')" mode="heightFix" class="coupon-card-bgLeft"></image>
          <view class="coupon-card-content">
            <!-- 左侧金额区域 -->
            <view class="coupon-card__left">
              <view class="amount-wrapper">
                <text class="amount-number">{{ couponData?.amount || 0 }}</text>
                <text class="amount-unit">元</text>
              </view>
              <text class="condition-text">满{{ couponData?.minAmount || 0 }}可用</text>
            </view>

            <!-- 右侧信息区域 -->
            <view class="coupon-card__right">
              <view class="coupon-info">
                <text class="coupon-name">{{ couponData?.name || '6元通用优惠券' }}</text>
                <text class="coupon-expire">{{ couponData?.expireDate || '' }}到期</text>
              </view>
            </view>
          </view>
        </view>
      </view>

      <!-- 规则详情 -->
      <view class="rules-content">
        <view class="rules-item">
          <text class="rules-label">有效期</text>
          <text class="rules-value">{{ couponData?.validDays || 90 }}天</text>
        </view>
        
        <view class="rules-item">
          <text class="rules-label">补充说明</text>
          <text class="rules-value">{{ couponData?.description || '周一、周五不可用' }}</text>
        </view>
      </view>

      <!-- 底部按钮 -->
      <view class="rules-modal__footer">
        <view class="use-btn" hover-class="hover-active" @click="handleUse">
          去使用
        </view>
      </view>
    </view>
  </BasicModal>
</template>

<script setup>
import { computed } from 'vue';
import BasicModal from '@/components/Modal/BasicModal.vue';
import { getFileUrl } from '@/utils/file.js';

const props = defineProps({
  open: {
    type: Boolean,
    default: false
  },
  couponData: {
    type: Object,
    default: () => ({
      amount: 6,
      minAmount: 66,
      name: '6元通用优惠券',
      expireDate: '2025/07/12',
      validDays: 90,
      description: '周一、周五不可用'
    })
  }
});

const emit = defineEmits(['update:open', 'use']);

const getOpen = computed({
  get: () => props.open,
  set: (val) => emit('update:open', val)
});

// 关闭弹窗
const handleClose = () => {
  getOpen.value = false;
};

// 使用优惠券
const handleUse = () => {
  emit('use', props.couponData);
  getOpen.value = false;
};
</script>

<style lang="scss" scoped>
.rules-modal {
  width: 100%;
  background: #FFFFFF;
  border-radius: 24rpx 24rpx 0 0;
  padding: 32rpx 30rpx;
  padding-bottom: calc(32rpx + env(safe-area-inset-bottom));
  box-sizing: border-box;

  // 标题栏
  &__header {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 32rpx;
    position: relative;

    .header-title {
      font-size: 36rpx;
      font-weight: bold;
      color: #151515;
    }

    .close-btn {
      position: absolute;
      right: 0;
      top: 50%;
      transform: translateY(-50%);
      width: 48rpx;
      height: 48rpx;
      display: flex;
      align-items: center;
      justify-content: center;

      .close-icon {
        width: 28rpx;
        height: 28rpx;
        position: relative;

        &::before,
        &::after {
          content: '';
          position: absolute;
          width: 28rpx;
          height: 2rpx;
          background: #999999;
          top: 50%;
          left: 50%;
          transform-origin: center;
        }

        &::before {
          transform: translate(-50%, -50%) rotate(45deg);
        }

        &::after {
          transform: translate(-50%, -50%) rotate(-45deg);
        }
      }
    }
  }

  // 优惠券卡片容器
  .coupon-card-wrapper {
    margin-bottom: 32rpx;
  }

  // 优惠券卡片样式 - 与列表页完全一致
  .coupon-card {
    display: flex;
    align-items: center;
    overflow: hidden;
    position: relative;
    box-sizing: border-box;

    .coupon-card-bg {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      z-index: 1;
    }

    .coupon-card-bgLeft {
      position: absolute;
      top: 0;
      left: 0;
      width: auto;
      height: 190rpx;
      z-index: 1;
    }

    .coupon-card-content {
      position: relative;
      z-index: 3;
      display: flex;
      align-items: center;
      width: 100%;
      height: 200rpx;
    }

    &__left {
      width: 200rpx;
      padding: 32rpx 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;

      .amount-wrapper {
        display: flex;
        align-items: baseline;
        margin-bottom: 8rpx;

        .amount-number {
          font-size: 64rpx;
          font-weight: bold;
          color: #F47D1F;
          line-height: 1;
        }

        .amount-unit {
          font-size: 28rpx;
          color: #F47D1F;
          margin-left: 4rpx;
        }
      }

      .condition-text {
        font-size: 22rpx;
        color: #F47D1F;
      }
    }

    &__right {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 32rpx 24rpx;

      .coupon-info {
        flex: 1;
        display: flex;
        flex-direction: column;

        .coupon-name {
          font-size: 28rpx;
          font-weight: bold;
          color: #151515;
          margin-bottom: 12rpx;
        }

        .coupon-expire {
          font-size: 22rpx;
          color: #999999;
        }
      }
    }
  }

  // 规则详情
  .rules-content {
    margin-bottom: 40rpx;
    padding: 0 8rpx;

    .rules-item {
      display: flex;
      align-items: flex-start;
      margin-bottom: 20rpx;
      font-size: 26rpx;
      line-height: 40rpx;

      &:last-child {
        margin-bottom: 0;
      }

      .rules-label {
        color: #666666;
        flex-shrink: 0;
      }

      .rules-value {
        color: #151515;
        margin-left: 16rpx;
        flex: 1;
      }
    }
  }

  // 底部按钮
  &__footer {
    .use-btn {
      width: 100%;
      height: 88rpx;
      background: linear-gradient(135deg, #FF8A57 0%, #F47D1F 100%);
      border-radius: 44rpx;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 32rpx;
      font-weight: bold;
      color: #FFFFFF;
      letter-spacing: 2rpx;
    }
  }
}

.hover-active {
  opacity: 0.8;
  transform: scale(0.98);
  transition: all 0.2s;
}
</style>

