<template>
  <div class="app_build_steps">
    <ul class="steps_header">
      <template v-for="(item, index) in steps">
        <li
          class="step_line left"
          :class="{
            active: item.step <= activeStep,
          }"
          v-if="item.step > 0"
          :key="'line_left_' + index"
        ></li>
        <li
          class="step_item"
          :class="{
            active: item.step <= activeStep,
            current: item.step === activeStep,
          }"
          :key="'step_' + index"
        >
          <div class="step_icon_active" v-if="item.step <= activeStep">
            <div class="icon_container">
              <img :src="item.activeIcon" />
            </div>
          </div>
          <div class="step_icon" v-else></div>
          <div class="step_info">
            <p class="step_state">
              <span v-show="item.step > activeStep">
                待进行
              </span>
              <span v-show="item.step === activeStep">
                进行中
              </span>
              <span v-show="item.step < activeStep">
                已完成
              </span>
            </p>
            <p class="step_name" v-text="item.title"></p>
          </div>
        </li>
        <li
          class="step_line right"
          :class="{
            active: item.step <= activeStep,
          }"
          v-if="item.step < steps.length - 1"
          :key="'line_right_' + index"
        ></li>
      </template>
    </ul>

    <div class="steps_container">
      <slot></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: "appBuildSteps",
  props: {
    activeStep: {
      type: Number,
      default: () => "",
    },
  },
  data: () => ({
    steps: [],
  }),
  computed: {},
  methods: {
    getSteps() {
      this.steps = this.$slots.default
        .filter(
          (vnode) =>
            vnode.tag &&
            vnode.componentOptions &&
            vnode.componentOptions.Ctor.options.name === "appBuildStep"
        )
        .map((vnode) => vnode.componentInstance);
    },
  },
  mounted() {
    this.getSteps();
  },
};
</script>

<style scoped>
.steps_header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
}
.steps_header > .step_line {
  flex-grow: 1;
  height: 4px;
  background-color: #e3e5ef;
}
.steps_header > .step_line.right {
  border-bottom-left-radius: 2px;
  border-top-left-radius: 2px;
}
.steps_header > .step_line.active {
  background-color: #515fe7;
}
.steps_header > .step_item {
  display: inline-flex;
  justify-content: flex-start;
  align-items: center;
  color: #bcc1d0;
}
.steps_header > .step_item > .step_icon {
  width: 30px;
  height: 30px;
  background-color: #bcc1d0;
  border: 7px solid #e3e5ef;
  border-radius: 50%;
  box-sizing: border-box;
}
.steps_header > .step_item > .step_icon_active {
  padding: 10px;
  background-color: #515fe7;
  border-radius: 50%;
}
.steps_header > .step_item > .step_icon_active > .icon_container {
  width: 60px;
  height: 60px;
  border: 3px solid #8390ee;
  box-sizing: border-box;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.steps_header > .step_item > .step_info {
  margin: 0 15px;
}
.steps_header > .step_item .step_state {
  font-size: 18px;
  line-height: 34px;
}
.steps_header > .step_item .step_name {
  font-size: 14px;
  line-height: 24px;
}
.steps_header > .step_item.active .step_state {
  color: #242c43;
}
.steps_header > .step_item.active .step_name {
  color: #8890a7;
}

.steps_container {
  border-top: 2px solid #f4f7fc;
  margin-top: 20px;
}
</style>
