<template>
  <div class="select-region-page">
    <div class="page-header">
      <h1 class="title">订单详情</h1>
    </div>
    
    <!-- 订单详情表格 -->
    <div class="order-details">
      <div class="detail-row">
        <div class="detail-label">代练大区</div>
        <div class="detail-label">状态</div>
        <div class="detail-label">打手信息</div>
        <div class="detail-label">目标点数</div>
      </div>
      <div class="detail-row detail-values">
        <div class="detail-value region-value">{{ selectedRegion || '未选择' }}</div>
        <div class="detail-value">待选区</div>
        <div class="detail-value">{{ mecmachineId || '待分配' }}</div>
        <div class="detail-value points-value">{{ displayTotalPoints }}</div>
      </div>
    </div>

    <!-- 选择大区输入框 -->
    <div class="region-selector">
      <input 
        type="text" 
        v-model="regionInput" 
        placeholder="请选择大区"
        readonly
        class="region-input"
      />
      <button 
        @click="confirmSelection" 
        class="confirm-btn"
        :disabled="!selectedRegion || submitting"
      >
        确认选择
      </button>
    </div>

    <!-- 选择区域按钮 -->
    <div class="region-options">
      <button 
        @click="selectRegionOption('Q')" 
        class="option-btn qq-option"
        :class="{ 'selected': selectedRegion === 'QQ区' }"
      >
        <div class="option-icon qq-icon">
          <svg viewBox="0 0 24 24" width="32" height="32" fill="currentColor">
            <circle cx="12" cy="12" r="10" />
          </svg>
        </div>
        <span>QQ区</span>
      </button>
      
      <button 
        @click="selectRegionOption('V')" 
        class="option-btn wx-option"
        :class="{ 'selected': selectedRegion === '微信区' }"
      >
        <div class="option-icon wx-icon">
          <svg viewBox="0 0 24 24" width="32" height="32" fill="currentColor">
            <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z"/>
            <path d="M12 6c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6z"/>
          </svg>
        </div>
        <span>微信区</span>
      </button>
    </div>

    <div class="notice-text">
      <p>代理技术代练平台操作中</p>
      <p>绝对安全保障！请耐心等待</p>
      <p>温馨提示: 请选择正确区域</p>
      <p v-if="mecmachineId" class="machine-id-info">ID: {{ mecmachineId }}</p>
      <p>桂ICP备2025067557号-2</p>
    </div>
  </div>
</template>

<script>
export default {
  name: 'SelectRegion',
  props: {
    submitting: {
      type: Boolean,
      default: false
    },
    mecmachineId: {
      type: String,
      default: null
    },
    totalPoints: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      selectedRegion: '',
      regionInput: '',
      regionCode: ''
    }
  },
  emits: ['selectRegion'],
  computed: {
    displayTotalPoints() {
      // 如果 totalPoints 为 null 或 undefined，显示"待分配"
      // 注意：0 是有效值，应该显示
      if (this.totalPoints === null || this.totalPoints === undefined) {
        return '待分配'
      }
      return this.totalPoints
    }
  },
  methods: {
    selectRegionOption(code) {
      this.regionCode = code
      if (code === 'Q') {
        this.selectedRegion = 'QQ区'
        this.regionInput = 'QQ区'
      } else if (code === 'V') {
        this.selectedRegion = '微信区'
        this.regionInput = '微信区'
      }
    },
    confirmSelection() {
      if (this.regionCode && !this.submitting) {
        this.$emit('selectRegion', this.regionCode)
      }
    }
  }
}
</script>

<style scoped>
.select-region-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
  min-height: 100vh;
}

.page-header {
  text-align: center;
  padding: 20px;
  background: white;
  border-bottom: 3px solid #4776e6;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.title {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  color: #333;
  background: linear-gradient(135deg, #4776e6 0%, #8e54e9 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* 订单详情表格 */
.order-details {
  background: white;
  margin: 16px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.detail-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.detail-label {
  padding: 12px 8px;
  text-align: center;
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  font-size: 14px;
  font-weight: 500;
  color: #333;
}

.detail-values {
  background: white;
}

.detail-value {
  padding: 12px 8px;
  text-align: center;
  border: 1px solid #e9ecef;
  border-top: none;
  font-size: 14px;
  color: #666;
}

.region-value {
  color: #4CAF50;
  font-weight: 600;
}

.points-value {
  color: #f44336;
  font-weight: 600;
}

/* 选择大区区域 */
.region-selector {
  margin: 16px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.region-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  background: white;
  color: #333;
}

.region-input::placeholder {
  color: #999;
}

.confirm-btn {
  padding: 12px 24px;
  background: linear-gradient(135deg, #4776e6 0%, #8e54e9 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.confirm-btn:hover:not(:disabled) {
  opacity: 0.9;
  transform: translateY(-1px);
}

.confirm-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 选择区域按钮 */
.region-options {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 40px;
  padding: 20px;
}

.option-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
  background: white;
  border: 3px solid transparent;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 120px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.option-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.option-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
  transition: all 0.3s ease;
}

.qq-icon {
  background: #12B7F5;
}

.wx-icon {
  background: #07C160;
}

.option-btn span {
  font-size: 16px;
  font-weight: 500;
  color: #333;
}

.option-btn.selected {
  border-color: #4776e6;
  background: #f3f4ff;
}

.qq-option.selected {
  border-color: #12B7F5;
  background: #e3f2fd;
}

.qq-option.selected span {
  color: #12B7F5;
  font-weight: 600;
}

.wx-option.selected {
  border-color: #07C160;
  background: #e8f5e9;
}

.wx-option.selected span {
  color: #07C160;
  font-weight: 600;
}

.notice-text {
  text-align: center;
  padding: 20px;
  background: #f8f9fa;
  border-top: 2px solid #e9ecef;
  margin-top: auto;
}

.notice-text p {
  margin: 4px 0;
  font-size: 12px;
  color: #666;
}

.machine-id-info {
  color: #4CAF50 !important;
  font-weight: 600 !important;
  opacity: 1 !important;
}

@media (max-width: 768px) {
  .detail-label,
  .detail-value {
    padding: 10px 6px;
    font-size: 12px;
  }
  
  .region-selector {
    flex-direction: column;
  }
  
  .region-input,
  .confirm-btn {
    width: 100%;
  }

  .region-options {
    gap: 20px;
    padding: 16px;
  }

  .option-btn {
    min-width: 100px;
    padding: 16px;
  }

  .option-icon {
    width: 50px;
    height: 50px;
  }

  .option-btn span {
    font-size: 14px;
  }
}
</style>