<template>
  <div class="elem-composition">
    <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-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 {};
  },
  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>
