<template>
  <div class="kole-steps" :class="direction">
    <div
      v-for="(s, i) in steps" :key="i"
      class="kole-step"
      :class="'is-' + statusOf(i)"
    >
      <div class="kole-step-icon">{{ statusOf(i) === 'finish' ? '✓' : (statusOf(i) === 'error' ? '!' : (i + 1)) }}</div>
      <div class="kole-step-body">
        <div class="kole-step-title">{{ s.title }}</div>
        <div v-if="s.desc" class="kole-step-desc">{{ s.desc }}</div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue';

const props = defineProps({
  steps: { type: Array, required: true },                 // [{ title, desc? }]
  current: { type: Number, default: 0 },                  // 当前步骤索引
  errorAt: { type: Number, default: -1 },                 // 异常步骤索引
  direction: { type: String, default: 'horizontal' }      // horizontal | vertical
});

function statusOf(i) {
  if (i === props.errorAt) return 'error';
  if (i < props.current) return 'finish';
  if (i === props.current) return 'process';
  return 'wait';
}
</script>

<!-- 样式对齐 组件2/7 StepList 规范 -->
<style scoped>
.kole-steps { font-family: var(--font-family, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif); color: #262626; }
.kole-steps.horizontal { display: flex; }
.kole-steps.vertical { display: inline-flex; flex-direction: column; }
.kole-step { position: relative; display: flex; gap: 12px; flex: 1; }
.kole-steps.vertical .kole-step { flex-direction: column; }
.kole-step-icon { position: relative; width: 32px; height: 32px; border-radius: 50%; border: 2px solid #E8ECF1; display: flex; align-items: center; justify-content: center; font-size: 14px; background: #fff; color: #6E6E6E; flex-shrink: 0; z-index: 1; }
.kole-step.is-finish .kole-step-icon { border-color: #2F54EB; color: #2F54EB; background: #F0F5FF; }
.kole-step.is-process .kole-step-icon { border-color: #2F54EB; color: #fff; background: #2F54EB; }
.kole-step.is-error .kole-step-icon { border-color: #CF1322; color: #CF1322; background: #FFF1F0; }
.kole-step-title { font-size: 14px; font-weight: 500; line-height: 32px; }
.kole-step.is-wait .kole-step-title { color: #6E6E6E; }
.kole-step-desc { font-size: 12px; color: #6E6E6E; margin-top: 2px; }
.kole-steps.horizontal .kole-step:not(:last-child) .kole-step-icon::after { content: ''; position: absolute; top: 15px; left: 38px; right: -12px; height: 2px; background: #E8ECF1; }
.kole-steps.horizontal .kole-step.is-finish:not(:last-child) .kole-step-icon::after { background: #2F54EB; }
.kole-steps.vertical .kole-step-body { padding-bottom: 24px; }
.kole-steps.vertical .kole-step:not(:last-child) .kole-step-icon::after { content: ''; position: absolute; top: 40px; left: 15px; bottom: -12px; width: 2px; background: #E8ECF1; }
.kole-steps.vertical .kole-step.is-finish:not(:last-child) .kole-step-icon::after { background: #2F54EB; }
</style>
