<template>
  <div class="grade-step">
    <table class="table">
      <tr>
        <td
          v-if="showAnalysis"
          :class="[
            'step-analysis',
            { 'step-act': curStep.name === 'analysis' }
          ]"
          @click="selectAnalysis"
        >
          <p><Icon type="md-stats" /></p>
        </td>
        <td
          v-for="(step, sindex) in steps"
          :key="sindex"
          :class="['step-item', { 'step-act': curStep.name === step.name }]"
          @click="selectStep(step)"
        >
          <div v-if="step.type === 'done'">
            <p>
              <span>{{ step.gcount }}/</span><span>{{ step.gpercent }}%</span
              ><span>({{ step.pt }}%)</span>
            </p>
            <p class="step-name">{{ step.name }}</p>
            <p>
              <span>{{ step.count }}/</span><span>{{ step.percent }}%</span
              ><span>({{ step.kdpt }}%)</span>
            </p>
          </div>
          <div v-else>
            <p>{{ step.count }}</p>
            <p class="step-name">{{ step.name }}</p>
            <p>{{ step.count }}</p>
          </div>
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  name: "grade-step",
  props: {
    showAnalysis: {
      type: Boolean,
      default: true
    },
    steps: {
      type: Array,
      default() {
        return [];
      }
    },
    initStep: {
      type: Object,
      default() {
        return { type: "analysis", name: "analysis" };
      }
    }
  },
  data() {
    return {
      curStep: {}
    };
  },
  mounted() {
    this.selectStep(this.initStep);
  },
  methods: {
    selectStep(step) {
      this.curStep = { ...step };
      this.$emit("on-change", this.curStep);
    },
    selectAnalysis() {
      this.selectStep({ type: "analysis", name: "analysis" });
    }
  }
};
</script>
