<template>
  <div class="forget-container">
    <!-- 导航栏 -->
    <div class="nav-bar">
      <div class="back-btn" @click="$router.back()">
        <i class="arrow-left"></i>
      </div>
      <div class="title">忘记密码</div>
    </div>

    <!-- 页面内容 -->
    <div class="content">
      <!-- 顶部说明 -->
      <div class="header-section">
        <div class="logo-container">
          <img src="@/assets/logo.png" alt="红旗" class="logo-img">
        </div>
        <div class="header-text">
          <div class="main-title">找回密码</div>
          <div class="sub-title">请按照步骤重置您的登录密码</div>
        </div>
      </div>

      <!-- 重置表单 -->
      <div class="form-section">
        <div class="form-card">
          <div class="step-indicator">
            <div class="step-item" :class="{ active: currentStep >= 1, completed: currentStep > 1 }">
              <div class="step-number">1</div>
              <div class="step-text">验证身份</div>
            </div>
            <div class="step-line" :class="{ active: currentStep > 1 }"></div>
            <div class="step-item" :class="{ active: currentStep >= 2, completed: currentStep > 2 }">
              <div class="step-number">2</div>
              <div class="step-text">重置密码</div>
            </div>
            <div class="step-line" :class="{ active: currentStep > 2 }"></div>
            <div class="step-item" :class="{ active: currentStep >= 3 }">
              <div class="step-number">3</div>
              <div class="step-text">完成</div>
            </div>
          </div>

          <!-- 步骤1：验证身份 -->
          <div class="step-content" v-if="currentStep === 1">
            <div class="step-title">验证您的身份</div>
            <div class="step-desc">请输入您的手机号码以接收验证码</div>
            
            <div class="form-group">
              <label class="form-label">手机号码</label>
              <div class="input-wrapper">
                <i class="input-icon phone-icon"></i>
                <input
                  type="tel"
                  v-model="phone"
                  placeholder="请输入手机号码"
                  class="form-input"
                  maxlength="11"
                >
              </div>
            </div>

            <div class="form-group">
              <label class="form-label">验证码</label>
              <div class="input-wrapper">
                <i class="input-icon code-icon"></i>
                <input
          type="text"
                  v-model="verifyCode"
                  placeholder="请输入验证码"
                  class="form-input code-input"
                  maxlength="6"
                >
                <button 
                  class="send-code-btn" 
                  @click="sendVerifyCode"
                  :disabled="!canSendCode || countdown > 0"
                >
                  {{ countdown > 0 ? `${countdown}s` : '发送验证码' }}
                </button>
              </div>
            </div>

            <button 
              class="next-btn" 
              @click="verifyIdentity"
              :disabled="!phone || !verifyCode"
            >
              下一步
            </button>
          </div>

          <!-- 步骤2：重置密码 -->
          <div class="step-content" v-if="currentStep === 2">
            <div class="step-title">设置新密码</div>
            <div class="step-desc">请设置您的新登录密码</div>
            
            <div class="form-group">
              <label class="form-label">新密码</label>
              <div class="input-wrapper">
                <i class="input-icon password-icon"></i>
                <input
                  :type="showPassword ? 'text' : 'password'"
                  v-model="newPassword"
                  placeholder="请输入新密码"
                  class="form-input"
                  maxlength="20"
                >
                <button class="toggle-password" @click="showPassword = !showPassword">
                  <i :class="showPassword ? 'eye-open' : 'eye-close'"></i>
                </button>
              </div>
              <div class="password-strength">
                <div class="strength-text">密码强度：</div>
                <div class="strength-meter">
                  <div class="strength-bar" :class="passwordStrength"></div>
                </div>
                <div class="strength-label" :class="passwordStrength">{{ getStrengthText() }}</div>
              </div>
            </div>

            <div class="form-group">
              <label class="form-label">确认密码</label>
              <div class="input-wrapper">
                <i class="input-icon password-icon"></i>
                <input
                  :type="showConfirmPassword ? 'text' : 'password'"
                  v-model="confirmPassword"
                  placeholder="请再次输入新密码"
                  class="form-input"
                  maxlength="20"
                >
                <button class="toggle-password" @click="showConfirmPassword = !showConfirmPassword">
                  <i :class="showConfirmPassword ? 'eye-open' : 'eye-close'"></i>
                </button>
              </div>
              <div class="validation-msg" v-if="confirmPassword && !passwordsMatch">
                密码不一致，请重新输入
              </div>
            </div>

            <div class="password-tips">
              <div class="tips-title">密码要求：</div>
              <div class="tips-list">
                <div class="tip-item" :class="{ valid: hasMinLength }">
                  <i class="tip-icon"></i>
                  <span>至少8个字符</span>
                </div>
                <div class="tip-item" :class="{ valid: hasUpperCase }">
                  <i class="tip-icon"></i>
                  <span>包含大写字母</span>
                </div>
                <div class="tip-item" :class="{ valid: hasLowerCase }">
                  <i class="tip-icon"></i>
                  <span>包含小写字母</span>
                </div>
                <div class="tip-item" :class="{ valid: hasNumber }">
                  <i class="tip-icon"></i>
                  <span>包含数字</span>
                </div>
              </div>
            </div>

            <button 
              class="next-btn" 
              @click="resetPassword"
              :disabled="!canResetPassword"
            >
              重置密码
            </button>
          </div>

          <!-- 步骤3：完成 -->
          <div class="step-content success-content" v-if="currentStep === 3">
            <div class="success-icon">
              <i class="check-icon"></i>
            </div>
            <div class="success-title">密码重置成功！</div>
            <div class="success-desc">您的密码已成功重置，请使用新密码登录</div>
            
            <button class="complete-btn" @click="goToLogin">
              前往登录
            </button>
          </div>
        </div>
      </div>

      <!-- 帮助信息 -->
      <div class="help-section">
        <div class="help-card">
          <div class="help-title">需要帮助？</div>
          <div class="help-content">
            <div class="help-item">
              <i class="help-icon"></i>
              <span>如果您无法接收验证码，请检查手机号是否正确</span>
            </div>
            <div class="help-item">
              <i class="help-icon"></i>
              <span>遇到其他问题，请联系客服：400-888-8888</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Forget',
  data() {
    return {
      currentStep: 1,
      phone: '',
      verifyCode: '',
      newPassword: '',
      confirmPassword: '',
      showPassword: false,
      showConfirmPassword: false,
      countdown: 0,
      timer: null
    }
  },
  computed: {
    canSendCode() {
      return /^1[3-9]\d{9}$/.test(this.phone)
    },
    passwordsMatch() {
      return this.newPassword === this.confirmPassword
    },
    hasMinLength() {
      return this.newPassword.length >= 8
    },
    hasUpperCase() {
      return /[A-Z]/.test(this.newPassword)
    },
    hasLowerCase() {
      return /[a-z]/.test(this.newPassword)
    },
    hasNumber() {
      return /\d/.test(this.newPassword)
    },
    passwordStrength() {
      const checks = [this.hasMinLength, this.hasUpperCase, this.hasLowerCase, this.hasNumber]
      const score = checks.filter(Boolean).length
      
      if (score < 2) return 'weak'
      if (score < 3) return 'medium'
      if (score < 4) return 'strong'
      return 'very-strong'
    },
    canResetPassword() {
      return this.newPassword && 
             this.confirmPassword && 
             this.passwordsMatch && 
             this.hasMinLength
    }
  },
  methods: {
    sendVerifyCode() {
      if (!this.canSendCode || this.countdown > 0) return
      
      // 模拟发送验证码
      this.countdown = 60
      this.timer = setInterval(() => {
        this.countdown--
        if (this.countdown <= 0) {
          clearInterval(this.timer)
        }
      }, 1000)
      
      this.$toast('验证码已发送')
    },
    verifyIdentity() {
      if (!this.phone || !this.verifyCode) return
      
      // 模拟验证身份
      if (this.verifyCode === '123456') {
        this.currentStep = 2
        this.$toast('身份验证成功')
      } else {
        this.$toast('验证码错误，请重新输入')
      }
    },
    resetPassword() {
      if (!this.canResetPassword) return
      
      // 模拟重置密码
      setTimeout(() => {
        this.currentStep = 3
      }, 1000)
    },
    goToLogin() {
      this.$router.replace('/login')
    },
    getStrengthText() {
      const texts = {
        weak: '弱',
        medium: '中',
        strong: '强',
        'very-strong': '很强'
      }
      return texts[this.passwordStrength] || ''
    }
  },
  beforeDestroy() {
    if (this.timer) {
      clearInterval(this.timer)
    }
  }
}
</script>

<style scoped>
.forget-container {
  min-height: 100vh;
  background: linear-gradient(to bottom, #dc2626 0%, #b91c1c 100%);
}

.nav-bar {
  height: 56px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  color: #fff;
  display: flex;
  align-items: center;
  position: relative;
  padding: 0 15px;
}

.back-btn {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.arrow-left {
  width: 12px;
  height: 12px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(45deg);
}

.title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 18px;
  font-weight: 600;
}

.content {
  padding: 20px;
  min-height: calc(100vh - 56px);
}

.header-section {
  text-align: center;
  margin-bottom: 32px;
}

.logo-container {
  width: 80px;
  height: 80px;
  background: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.logo-img {
  width: 50px;
  height: 50px;
  object-fit: contain;
}

.header-text {
  color: #fff;
}

.main-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.sub-title {
  font-size: 14px;
  opacity: 0.9;
}

.form-section {
  margin-bottom: 24px;
}

.form-card {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  padding: 24px;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.step-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 32px;
}

.step-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.step-number {
  width: 32px;
  height: 32px;
  background: #e5e7eb;
  color: #9ca3af;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  transition: all 0.3s ease;
}

.step-item.active .step-number {
  background: #dc2626;
  color: #fff;
}

.step-item.completed .step-number {
  background: #10b981;
  color: #fff;
}

.step-text {
  font-size: 12px;
  color: #6b7280;
  font-weight: 500;
}

.step-item.active .step-text {
  color: #dc2626;
  font-weight: 600;
}

.step-line {
  width: 60px;
  height: 2px;
  background: #e5e7eb;
  margin: 0 8px;
  margin-bottom: 24px;
  transition: all 0.3s ease;
}

.step-line.active {
  background: #10b981;
}

.step-content {
  
}

.step-title {
  font-size: 20px;
  font-weight: 700;
  color: #374151;
  text-align: center;
  margin-bottom: 8px;
}

.step-desc {
  font-size: 14px;
  color: #6b7280;
  text-align: center;
  margin-bottom: 24px;
}

.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 8px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 12px;
  font-size: 16px;
  color: #9ca3af;
  z-index: 1;
}

.form-input {
  width: 100%;
  height: 48px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 0 48px 0 44px;
  font-size: 16px;
  color: #374151;
  outline: none;
  transition: all 0.3s ease;
}

.form-input:focus {
  border-color: #dc2626;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.form-input::placeholder {
  color: #9ca3af;
}

.code-input {
  padding-right: 120px;
}

.send-code-btn {
  position: absolute;
  right: 8px;
  background: #dc2626;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.send-code-btn:hover:not(:disabled) {
  background: #b91c1c;
}

.send-code-btn:disabled {
  background: #d1d5db;
  cursor: not-allowed;
}

.toggle-password {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  padding: 4px;
  transition: color 0.3s ease;
}

.toggle-password:hover {
  color: #6b7280;
}

.password-strength {
  display: flex;
  align-items: center;
  margin-top: 8px;
  gap: 8px;
}

.strength-text {
  font-size: 12px;
  color: #6b7280;
}

.strength-meter {
  flex: 1;
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  overflow: hidden;
}

.strength-bar {
  height: 100%;
  width: 0;
  border-radius: 2px;
  transition: all 0.3s ease;
}

.strength-bar.weak {
  width: 25%;
  background: #ef4444;
}

.strength-bar.medium {
  width: 50%;
  background: #f59e0b;
}

.strength-bar.strong {
  width: 75%;
  background: #3b82f6;
}

.strength-bar.very-strong {
  width: 100%;
  background: #10b981;
}

.strength-label {
  font-size: 12px;
  font-weight: 500;
}

.strength-label.weak {
  color: #ef4444;
}

.strength-label.medium {
  color: #f59e0b;
}

.strength-label.strong {
  color: #3b82f6;
}

.strength-label.very-strong {
  color: #10b981;
}

.validation-msg {
  font-size: 12px;
  color: #ef4444;
  margin-top: 8px;
}

.password-tips {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 20px;
}

.tips-title {
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 12px;
}

.tips-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tip-item {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: #6b7280;
}

.tip-item.valid {
  color: #10b981;
}

.tip-icon {
  width: 4px;
  height: 4px;
  background: #d1d5db;
  border-radius: 50%;
  margin-right: 8px;
}

.tip-item.valid .tip-icon {
  background: #10b981;
}

.next-btn,
.complete-btn {
  width: 100%;
  height: 48px;
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.next-btn:hover:not(:disabled),
.complete-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

.next-btn:disabled {
  background: #d1d5db;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.success-content {
  text-align: center;
  padding: 20px 0;
}

.success-icon {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}

.check-icon {
  font-size: 32px;
  color: #fff;
}

.check-icon::before {
  content: '✓';
}

.success-title {
  font-size: 22px;
  font-weight: 700;
  color: #374151;
  margin-bottom: 8px;
}

.success-desc {
  font-size: 14px;
  color: #6b7280;
  margin-bottom: 32px;
}

.help-section {
  
}

.help-card {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  padding: 16px;
  backdrop-filter: blur(10px);
}

.help-title {
  font-size: 14px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 12px;
}

.help-content {
  
}

.help-item {
  display: flex;
  align-items: flex-start;
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 8px;
}

.help-item:last-child {
  margin-bottom: 0;
}

.help-icon {
  width: 4px;
  height: 4px;
  background: #9ca3af;
  border-radius: 50%;
  margin: 6px 8px 0 0;
  flex-shrink: 0;
}

/* Icon styles */
.phone-icon::before { content: '📱'; }
.code-icon::before { content: '🔒'; }
.password-icon::before { content: '🔑'; }
.eye-open::before { content: '👁'; }
.eye-close::before { content: '🙈'; }

/* 移动端适配 */
@media (max-width: 768px) {
  .nav-bar {
    height: 50px;
    padding: 0 12px;
  }
  
  .back-btn {
    width: 36px;
    height: 36px;
  }
  
  .title {
    font-size: 16px;
  }
  
  .content {
    padding: 16px;
  }
  
  .header-section {
    margin-bottom: 24px;
  }
  
  .logo-container {
    width: 60px;
    height: 60px;
    margin-bottom: 16px;
  }
  
  .logo-img {
    width: 36px;
    height: 36px;
  }
  
  .main-title {
    font-size: 20px;
    margin-bottom: 6px;
  }
  
  .sub-title {
    font-size: 13px;
  }
  
  .form-section {
    margin-bottom: 20px;
  }
  
  .form-card {
    padding: 20px 16px;
  }
  
  .step-indicator {
    margin-bottom: 24px;
  }
  
  .step-number {
    width: 28px;
    height: 28px;
    font-size: 12px;
    margin-bottom: 6px;
  }
  
  .step-text {
    font-size: 11px;
  }
  
  .step-line {
    width: 40px;
    margin: 0 4px;
    margin-bottom: 20px;
  }
  
  .step-title {
    font-size: 18px;
    margin-bottom: 6px;
  }
  
  .step-desc {
    font-size: 13px;
    margin-bottom: 20px;
  }
  
  .form-group {
    margin-bottom: 16px;
  }
  
  .form-label {
    font-size: 13px;
    margin-bottom: 6px;
  }
  
  .form-input {
    height: 44px;
    padding: 0 44px 0 40px;
    font-size: 15px;
  }
  
  .input-icon {
    left: 10px;
    font-size: 14px;
  }
  
  .code-input {
    padding-right: 110px;
  }
  
  .send-code-btn {
    right: 6px;
    padding: 6px 12px;
    font-size: 11px;
  }
  
  .toggle-password {
    right: 10px;
  }
  
  .password-strength {
    margin-top: 6px;
    gap: 6px;
  }
  
  .strength-text {
    font-size: 11px;
  }
  
  .strength-label {
    font-size: 11px;
  }
  
  .validation-msg {
    font-size: 11px;
    margin-top: 6px;
  }
  
  .password-tips {
    padding: 12px;
    margin-bottom: 16px;
  }
  
  .tips-title {
    font-size: 12px;
    margin-bottom: 10px;
  }
  
  .tips-list {
    gap: 6px;
  }
  
  .tip-item {
    font-size: 11px;
  }
  
  .tip-icon {
    margin-right: 6px;
  }
  
  .next-btn,
  .complete-btn {
    height: 44px;
    font-size: 15px;
  }
  
  .success-content {
    padding: 16px 0;
  }
  
  .success-icon {
    width: 60px;
    height: 60px;
    margin-bottom: 16px;
  }
  
  .check-icon {
    font-size: 24px;
  }
  
  .success-title {
    font-size: 18px;
    margin-bottom: 6px;
  }
  
  .success-desc {
    font-size: 13px;
    margin-bottom: 24px;
  }
  
  .help-card {
    padding: 12px;
  }
  
  .help-title {
    font-size: 13px;
    margin-bottom: 10px;
  }
  
  .help-item {
    font-size: 12px;
    margin-bottom: 6px;
  }
  
  .help-icon {
    margin: 5px 6px 0 0;
  }
}
</style>
