<template>
  <!-- 首页：流程概览 -->
  <div v-if="currentStep === 0" class="home-entry">
    <h3 class="title"><el-image :src="homeIcon" class="homeIcon" />免费入驻店铺</h3>
    <div class="steps-container">
      <el-steps align-center :active="stepActive" :finish-status="stepFinishStatus">
        <el-step v-for="(item, index) in entryList" :key="index">
          <template #title>
            <div class="step-title-wrapper">
              <span class="step-title">{{ item.title }}</span>
              <span class="step-time">{{ item.time }}</span>
            </div>
          </template>
          <template #description>
            <div class="step-desc">
              {{ item.desc }}
            </div>
          </template>
        </el-step>
      </el-steps>
    </div>
    <div class="button-container">
      <el-button type="danger" size="large" class="register-btn-red" @click="handleRegister" v-if="storeApplicationStatus == 2">
        审核拒绝，重新入驻
      </el-button>
      <el-button type="primary" size="large" class="register-btn" v-else-if="storeApplicationStatus == 0"> 等待审核 </el-button>
      <el-button type="primary" size="large" class="register-btn" @click="handleGoEnter" v-else> 去入驻 </el-button>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref, defineProps, defineEmits, computed } from "vue";
import { localGet } from "@/utils/index";
import homeIcon from "../../../assets/images/home-icon.png";

const entryList = ref([
  {
    title: "个人实名",
    time: "约3分钟",
    desc: "填写店铺经营者姓名、身份证号等"
  },
  {
    title: "填写信息",
    time: "约30分钟",
    desc: "上传营业执照及填写店铺信息等"
  },
  {
    title: "等待审核",
    time: "约1-3个工作日",
    desc: "平台进行资质审核"
  },
  {
    title: "入驻成功",
    desc: "入驻成功后即可管理您的店铺"
  }
]);

const props = defineProps({
  currentStep: {
    type: Number,
    default: 0
  },
  storeApplicationStatus: {
    type: Number,
    default: undefined
  }
});

const emit = defineEmits(["update:currentStep"]);

// 检查用户是否已完成个人实名认证
const hasCompletedRealName = computed(() => {
  const geekerUser = localGet("geeker-user");
  return geekerUser?.userInfo?.idCard ? true : false;
});

// 计算步骤的 active 值
const stepActive = computed(() => {
  // 如果审核状态为等待审核(0)或审核拒绝(2)，显示第三步
  if (props.storeApplicationStatus == 0 || props.storeApplicationStatus == 2) {
    return 2;
  }
  // 如果已完成个人实名认证，显示第二步
  if (hasCompletedRealName.value) {
    return 1;
  }
  // 否则显示第一步
  return 0;
});

// 计算 finish-status
const stepFinishStatus = computed(() => {
  // 如果审核状态为等待审核(0)或审核拒绝(2)，或者已完成个人实名认证，显示成功状态
  if (props.storeApplicationStatus == 0 || props.storeApplicationStatus == 2 || hasCompletedRealName.value) {
    return "success";
  }
  return undefined;
});

// 处理入驻按钮
// 点击后跳转到 go-flow 组件（步骤1：填写信息）
const handleRegister = () => {
  emit("update:currentStep", 2);
};
const handleGoEnter = () => {
  emit("update:currentStep", 1);
};
</script>

<style scoped lang="scss">
// 首页样式
.home-entry {
  box-sizing: border-box;
  width: 100%;
  height: calc(100vh - 105px);
  overflow: hidden;
  background: url("../../../assets/images/home-bg.png") center center no-repeat;
  background-size: cover;
  .title {
    display: flex;
    align-items: center;
    height: 105px;
    font-size: 20px;
    font-weight: 600;
    color: #ffffff;
    background: linear-gradient(90deg, #6c8ff8 0%, rgb(255 255 255 / 0%) 100%);
    border-radius: 10px;
    .homeIcon {
      width: 76px;
      height: 76px;
      margin-right: 8px;
      margin-left: 25px;
    }
  }
  .steps-container {
    margin-top: 120px;
    margin-bottom: 60px;
    :deep(.el-steps) {
      // 所有连接线保持蓝色
      .el-step__line {
        border-color: #6c8ff8 !important;
        .el-step__line-inner {
          background-color: #6c8ff8 !important;
          border-color: #6c8ff8 !important;
        }
      }
      .el-step__head {
        .el-step__icon {
          width: 30px;
          height: 30px;
          font-size: 16px;
          font-weight: 600;
          color: #ffffff;
          background: #6c8ff8;
          border: 0;
        }

        // 已完成步骤的样式（显示对勾）
        &.is-finish {
          .el-step__icon {
            color: #ffffff;
            background-color: #6c8ff8 !important;
            border-color: #6c8ff8 !important;
          }
        }
      }
      .el-step__title {
        .step-title-wrapper {
          display: flex;
          flex-direction: column;
          gap: 8px;
          align-items: center;
          .step-title {
            padding-top: 15px;
            font-size: 16px;
            font-weight: 600;
            line-height: 1.5;
            color: #6c8ff8;
          }
          .step-time {
            display: inline-block;
            padding: 4px 12px;
            font-size: 12px;
            color: #909399;
            white-space: nowrap;
            background: #f5f7fa;
            border-radius: 12px;
          }
        }
      }
      .el-step__description {
        .step-desc {
          margin-top: 8px;
          font-size: 14px;
          line-height: 1.5;
          color: #606266;
        }
      }
    }
  }
  .button-container {
    display: flex;
    align-items: center;
    justify-content: center;
    .register-btn {
      width: 200px;
      height: 44px;
      font-size: 16px;
      font-weight: 500;
      background: #6c8ff8;
      border: 0;
      border-radius: 4px;
      outline: none;
    }
    .register-btn-red {
      width: 200px;
      height: 44px;
      font-size: 16px;
      font-weight: 500;
      border: 0;
      border-radius: 4px;
      outline: none;
    }
  }
}
</style>
