<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 v-if="item.stepTitle != ''" class="step_state">
              <span>
                {{ item.stepTitle }}
              </span>
            </p>
            <p v-else class="step_state">
              <span v-if="item.step < activeStep || done">
                已完成
              </span>
              <span v-else-if="item.step > activeStep">
                待进行
              </span>
              <span v-else-if="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 steps_done" v-if="done && showDone">
      <div class="steps_done_info">
        <div class="left_container">
          <img
            :src="require('../../assets/imgs/steps_done.png')"
            width="100%"
          />
        </div>
        <div class="right_container">
          <p v-if="doneTitle" v-text="doneTitle"></p>
          <p v-if="doneSubTitle" v-text="doneSubTitle"></p>
        </div>
      </div>
      <div class="done_action apaas_button">
        <slot name="action"></slot>
      </div>
    </div>
    <div class="steps_container" v-else>
      <slot></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: "appBuildSteps",
  props: {
    activeStep: {
      type: Number,
      default: () => "",
    },
    done: {
      type: Boolean,
      default: () => false,
    },
    showDone: {
      type: Boolean,
      default: () => false,
    },
    doneTitle: {
      type: String,
      default: () => "操作成功",
    },
    doneSubTitle: {
      type: String,
      default: () => "",
    },
  },
  data: () => ({
    steps: [],
  }),
  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>
.app_build_steps {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
}
.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;
  flex-grow: 1;
}
.steps_done {
  position: relative;
  min-height: 400px;
}
.steps_done_info {
  position: absolute;
  top: calc(50% - 40px);
  left: 50%;
  transform: translate(-50%, -50%);
}
.steps_done_info > * {
  display: inline-block;
  vertical-align: middle;
}
.steps_done_info > .left_container {
  width: 70px;
  font-size: 0;
  margin-right: 10px;
}
.steps_done_info > .right_container > p:nth-child(1) {
  font-size: 18px;
  font-weight: 700;
  line-height: 24px;
  color: #242c43;
}
.steps_done_info > .right_container > p:nth-child(2) {
  font-size: 14px;
  line-height: 20px;
  color: #8890a7;
  margin-top: 5px;
}
.done_action {
  position: absolute;
  right: 0;
  bottom: 0;
}
</style>
