<template>
  <div class="elem-explain">
    <div v-if="data.showTitle" ref="ElemTitle" class="elem-title">
      {{ data.parent.topicName }}
    </div>
    <div ref="ElemBody" class="elem-body">
      <div v-if="data.serialNumber && !data.isExtend" class="elem-explain-no">
        {{ 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: "ElemExplain",
  components: { ElemExplainElement },
  props: {
    data: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    return {};
  },
  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>
