<template>
  <div class="elem-composition">
    <div class="elem-title" v-if="data.showTitle" ref="ElemTitle">
      {{ data.parent.topicName }}
    </div>
    <div class="elem-body" ref="ElemBody">
      <div class="elem-composition-elements">
        <elem-composition-element
          v-for="element in data.elements"
          :key="element.id"
          :data="element"
        ></elem-composition-element>
      </div>
    </div>
  </div>
</template>

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

export default {
  name: "elem-composition",
  components: { ElemCompositionElement },
  props: {
    data: {
      type: Object,
    },
  },
  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>
