<template>
  <div class="elem-explain">
    <div
      v-if="data.showTitle"
      ref="ElemTitle"
      class="elem-title"
      :style="nameStyles"
    >
      {{ data.parent.topicName }}
    </div>
    <div class="elem-body" ref="ElemBody">
      <div
        class="elem-explain-no"
        v-if="data.parent.questionsCount > 1 && !data.isExtend"
      >
        {{ data.serialNumber }}、
      </div>
      <!-- 解答题子元件区域 -->
      <div class="elem-explain-elements">
        <elem-explain-element
          v-for="element in data.elements"
          :key="element.id"
          :data="element"
        ></elem-explain-element>
      </div>
    </div>
  </div>
</template>

<script>
import ElemExplainElement from "./ElemExplainElement";

export default {
  name: "elem-explain",
  components: { ElemExplainElement },
  props: {
    data: {
      type: Object,
    },
  },
  data() {
    return {};
  },
  computed: {
    nameStyles() {
      return {
        fontWeight: this.data.parent.nameFontWeight,
        fontSize: this.data.parent.nameFontSize,
      };
    },
  },
  mounted() {
    this.modifyBodyStyle();
  },
  methods: {
    modifyBodyStyle() {
      let height = this.data.h;
      if (this.data.showTitle) {
        height = this.data.h - this.$refs.ElemTitle.clientHeight;
      }
      this.$refs.ElemBody.style.height = height + "px";
    },
  },
};
</script>
