<template>
  <div class="topic-element-preview">
    <div
      :class="classes"
      :id="`preview-${data.id}`"
      :data-type="data.type"
      :style="styles"
    >
      <component :is="compName" :data="data" preview></component>
    </div>
  </div>
</template>

<script>
import PreviewFillQuestion from "../elements/fill-question/ElemFillQuestion";
import PreviewFillLine from "../elements/fill-line/ElemFillLine";
import PreviewText from "../../../elements/text/ElemText";
import PreviewImage from "../../../elements/image/ElemImage";
import PreviewLine from "../../../elements/line/ElemLine";
import PreviewLines from "../../../elements/lines/ElemLines";
import PreviewGrids from "../../../elements/grids/ElemGrids";
import PreviewPane from "../../../elements/pane/ElemPane";
import PreviewBarcode from "../../../elements/barcode/ElemBarcode";
import PreviewFillNumber from "../../../elements/fill-number/ElemFillNumber";
import PreviewFillField from "../../../elements/fill-field/ElemFillField";
import PreviewFillTable from "../../../elements/fill-table/ElemFillTable";
import PreviewFillPane from "../../../elements/fill-pane/ElemFillPane";

export default {
  name: "topic-element-preview",
  components: {
    PreviewFillQuestion,
    PreviewFillLine,
    PreviewFillNumber,
    PreviewFillField,
    PreviewFillTable,
    PreviewFillPane,
    PreviewText,
    PreviewImage,
    PreviewLine,
    PreviewLines,
    PreviewGrids,
    PreviewPane,
    PreviewBarcode,
  },
  props: {
    data: {
      type: Object,
    },
  },
  data() {
    return {};
  },
  computed: {
    elementName() {
      const name = this.data.type.toLowerCase().replace("_", "-");
      return name.includes("line-") ? "line" : name;
    },
    compName() {
      return `preview-${this.elementName}`;
    },
    classes() {
      return [
        "topic-preview",
        "element-item",
        `element-item-${this.elementName}`,
      ];
    },
    styles() {
      return {
        left: this.data.x + "px",
        top: this.data.y + "px",
        width: this.data.w + "px",
        height: this.data.h + "px",
        zIndex: this.data.zindex,
      };
    },
  },
  methods: {},
};
</script>
