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

<script>
import PreviewText from "../../card/elements/text/ElemText";
import PreviewFieldText from "../elements/field-text/ElemFieldText";
import PreviewImage from "../../card/elements/image/ElemImage";
import PreviewLine from "../../card/elements/line/ElemLine";
import PreviewLines from "../../card/elements/lines/ElemLines";
import PreviewGrids from "../../card/elements/grids/ElemGrids";
import PreviewPane from "../../card/elements/pane/ElemPane";
import PreviewGutter from "../../card/elements/gutter/ElemGutter";
import PreviewFillField from "../elements/fill-field/ElemFillField";
import PreviewFillTable from "../../card/elements/fill-table/ElemFillTable";
import PreviewFillPane from "../../card/elements/fill-pane/ElemFillPane";

export default {
  name: "BoxElementPreview",
  components: {
    PreviewText,
    PreviewFieldText,
    PreviewImage,
    PreviewLine,
    PreviewLines,
    PreviewGrids,
    PreviewPane,
    PreviewGutter,
    PreviewFillField,
    PreviewFillTable,
    PreviewFillPane,
  },
  props: {
    data: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  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>
