<template>
  <div class="step-bar">
    <div
      v-for="(step, index) in steps"
      :key="index"
      class="step-item"
      :class="getStepClass(index)"
    >
      <div class="step-circle" @click="onStepClick(index)">
        <span v-if="getStatus(index) === 'finish'" class="step-check">✓</span>
        <span v-else>{{ index + 1 }}</span>
      </div>
      <div class="step-label">{{ step }}</div>
      <div v-if="index < steps.length - 1" class="step-line" :class="{'step-line-done': getStatus(index) === 'finish'}"></div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'StepBar',
  props: {
    current: {
      type: Number,
      default: 1
    },
    steps: {
      type: Array,
      default: () => ['基本信息', '添加企微', '车辆信息', '驾驶员信息']
    }
  },
  methods: {
    getStatus(index) {
      const stepNum = index + 1;
      if (stepNum < this.current) return 'finish';
      if (stepNum === this.current) return 'process';
      return 'wait';
    },
    getStepClass(index) {
      return `step-${this.getStatus(index)}`;
    },
    onStepClick(index) {
      const stepNum = index + 1;
      if (this.getStatus(index) === 'finish') {
        this.$emit('step-click', stepNum);
      }
    }
  }
}
</script>

<style scoped lang="scss">
.step-bar {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 14px 10px 10px;
  background: #fff;
  position: relative;
}

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

.step-circle {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: bold;
  z-index: 1;
  position: relative;
}

.step-finish .step-circle {
  background: #0E76F4;
  color: #fff;
  cursor: pointer;
}

.step-process .step-circle {
  background: #0E76F4;
  color: #fff;
  box-shadow: 0 0 0 3px rgba(14, 118, 244, 0.2);
}

.step-wait .step-circle {
  background: #e0e0e0;
  color: #999;
}

.step-label {
  font-size: 11px;
  margin-top: 5px;
  text-align: center;
  white-space: nowrap;
}

.step-finish .step-label {
  color: #0E76F4;
}

.step-process .step-label {
  color: #0E76F4;
  font-weight: bold;
}

.step-wait .step-label {
  color: #999;
}

.step-line {
  position: absolute;
  top: 13px;
  left: calc(50% + 13px);
  right: calc(-50% + 13px);
  height: 2px;
  background: #e0e0e0;
}

.step-line-done {
  background: #0E76F4;
}

.step-check {
  font-size: 14px;
}
</style>
