<template>
  <el-card class="step-card">
    <template #header>
      <div class="card-header">
        <div class="header-icon">
          <el-icon class="text-green-600">
            <ShieldCheckIcon />
          </el-icon>
        </div>
        <div class="header-content">
          <h2 class="header-title">企业认证</h2>
          <p class="header-subtitle">请完成企业认证流程</p>
        </div>
      </div>
    </template>

    <div class="verify-content">
      <!-- 企业认证iframe -->
      <div class="esign-iframe-section">
        <div class="iframe-container">
          <iframe
            :src="authUrl"
            frameborder="0"
            class="esign-iframe"
            title="企业认证"
            @load="handleIframeLoad"
          ></iframe>
          <div v-if="iframeLoading" class="iframe-loading">
            <div class="loading-spinner"></div>
            <p>正在加载企业认证页面...</p>
          </div>
        </div>
      </div>
    </div>
  </el-card>
</template>

<script setup>
import {
  CheckIcon,
  ShieldCheckIcon
} from '@heroicons/vue/24/outline'
import { ElMessage } from 'element-plus'

const props = defineProps({
  enterpriseData: {
    type: Object,
    required: true
  },
  authUrl: {
    type: String,
    default: ''
  }
})

const emit = defineEmits(['submit'])

// 企业认证状态
const esignCompleted = ref(false)
const iframeLoading = ref(true)

// 企业认证完成回调
const handleEsignComplete = async () => {
  try {
    esignCompleted.value = true
    ElMessage.success('企业认证完成')
    emit('submit')
  } catch (error) {
    console.error('企业认证失败:', error)
    ElMessage.error('企业认证失败，请重试')
  }
}

// 刷新iframe
const refreshIframe = () => {
  const iframe = document.querySelector('.esign-iframe')
  if (iframe) {
    iframe.src = iframe.src // 刷新iframe
  }
}

// iframe加载完成回调
const handleIframeLoad = () => {
  iframeLoading.value = false
}
</script>

<style scoped>
.step-card {
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
  border: none;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* 卡片头部 */
.card-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
}

.header-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.header-content {
  flex: 1;
}

.header-title {
  font-size: 24px;
  font-weight: 700;
  color: #1e293b;
  margin: 0 0 4px 0;
}

.header-subtitle {
  font-size: 14px;
  color: #64748b;
  margin: 0;
  font-weight: 500;
}

/* 认证内容 */
.verify-content {
  max-width: 100%;
  margin: 0 auto;
  padding: 20px 0;
}

/* 企业认证iframe */
.esign-iframe-section {
  padding: 20px;
}

.iframe-container {
  position: relative;
  width: 100%;
  height: 600px; /* 调整iframe高度 */
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  background: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.esign-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.iframe-loading {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  border-radius: 12px;
  z-index: 10;
}

.iframe-loading .loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e2e8f0;
  border-top: 4px solid #3b82f6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.iframe-loading p {
  font-size: 16px;
  color: #64748b;
  font-weight: 500;
}

.iframe-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 24px;
}

.esign-complete-btn {
  min-width: 180px;
  border-radius: 12px;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border: none;
  font-weight: 500;
  transition: all 0.3s ease;
}

.esign-complete-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.esign-complete-btn:disabled {
  background: #e2e8f0;
  color: #64748b;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.refresh-btn {
  min-width: 120px;
  border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  border: none;
  font-weight: 500;
  transition: all 0.3s ease;
}

.refresh-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* 动画 */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .verify-content {
    max-width: 100%;
    padding: 10px 0;
  }

  .esign-iframe-section {
    padding: 15px;
  }

  .iframe-container {
    height: 400px; /* 移动端调整iframe高度 */
  }

  .iframe-actions {
    flex-direction: column;
    gap: 12px;
  }

  .esign-complete-btn,
  .refresh-btn {
    min-width: 100%;
  }

  .card-header {
    flex-direction: column;
    text-align: center;
    gap: 12px;
  }

  .header-icon {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  .header-title {
    font-size: 20px;
  }
}

/* 大屏幕优化 */
@media (min-width: 1200px) {
  .iframe-container {
    height: 700px; /* 大屏幕增加iframe高度 */
  }
}
</style>
