<template>
  <div class="elem-composition-element">
    <div :id="data.id" :class="classes" :style="styles">
      <component :is="compName" :data="data"></component>
    </div>
  </div>
</template>

<script>
import ElemText from "../text/ElemText";
import ElemImage from "../image/ElemImage";
import ElemLine from "../line/ElemLine";
import ElemLines from "../lines/ElemLines";
import ElemGrids from "../grids/ElemGrids";

export default {
  name: "ElemCompositionElement",
  components: {
    ElemText,
    ElemImage,
    ElemLine,
    ElemLines,
    ElemGrids,
  },
  props: {
    data: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    return {};
  },
  computed: {
    compName() {
      if (this.data.type.includes("LINE_")) return "elem-line";
      return `elem-${this.data.type.toLowerCase()}`;
    },
    elementName() {
      return this.data.type.toLowerCase().replace("_", "-");
    },
    classes() {
      return [
        "composition-element-body",
        `composition-element-${this.elementName}`,
      ];
    },
    styles() {
      return {
        left: this.data.x + "px",
        top: this.data.y + "px",
        width: this.data.w + "px",
        height: this.data.h + "px",
      };
    },
  },
};
</script>
