<template>
  <div class="self-step">
    <div
      :class="{
        'step-item': true,
        'step-item-start': item.key === stepData[0].key,
        'step-item-end': item.key === stepData[ (stepData?.length??1) - 1].key,
        'step-item-active': item.key === activeStep,
        'step-item-success': successList.includes(item.key),
      }"
      v-for="item in stepData"
      :key="item.title"
      @click="$emit('check', item)"
    >
      <span class="step-title">
        <i :class="`${item.icon} step-title-icon`"></i>
        {{ item.title }}
      </span>
      <span class="step-count">
        <slot name="xxx" :item="item"></slot>
      </span>
    </div>
    <div class="step-line">
      <div
        class="step-line-item"
        v-for="item in (stepData?.length? stepData?.length-1 : 1) "
        :key="item"
      ></div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    stepData: {
      type: Array,
      default: () => []
    },
    successList: {
      type: Array,
      default: () => []
    },
    activeStep: {
      type: [Number, String],
      default: 1
    }
  }
}
</script>

<style lang="scss" scoped>
.self-step {
  width: 100%;
  display: flex;
  justify-content: space-between;
  position: relative;
  margin-bottom: 50px;
  .step-item {
    // flex: 1;
    background-color: white;
    position: relative;
    z-index: 1;
    user-select: none;
  }
  .step-item-start {
  }
  .step-title {
    font-size: 18px;
    font-weight: bold;
    padding: 0 20px;
    line-height: 30px;
    display: flex;
    align-items: center;
    cursor: pointer;
    .step-title-icon {
      font-size: 30px;
      margin-right: 5px;
    }
  }
  .step-item-success {
    color: $--color-success;
  }
  .step-count {
    // margin-top: 10px;
    position: absolute;
    top: calc(100% + 5px);
    width: 100%;
    white-space: nowrap;
    left: 0;
    text-align: center;
  }
  .step-line {
    height: 100%;
    width: 100%;
    position: absolute;
    left: 0;
    display: flex;
    transform: translateY(50%);
  }
  .step-line-item {
    flex: 1;
    height: 2px;
    background-color: #ccc;
  }
  .step-item-active {
    color: $--color-primary;
  }
}
</style>
