<template>
  <div class="card-view">
    <template v-for="(page, pageNo) in pages">
      <div
        :id="`preview-page-box-${pageNo}`"
        :class="[
          'page-box',
          `page-box-${cardConfig.pageSize}`,
          `page-box-${pageNo % 2}`,
          { 'page-box-less': pages.length <= 2 },
        ]"
        :key="pageNo"
      >
        <div v-if="!(pageNo % 2)" class="package-number">${packageCodeDom}</div>
        <!-- locator -->
        <div class="page-locator page-locator-top">
          <div
            v-for="elem in page.locators.top"
            :key="elem.id"
            :id="elem.id"
            class="page-locator-item"
          ></div>
        </div>
        <div class="page-locator page-locator-bottom">
          <div
            v-for="elem in page.locators.bottom"
            :key="elem.id"
            :id="elem.id"
            class="page-locator-item"
          ></div>
        </div>
        <!-- inner edit area -->
        <div class="page-main-inner">
          <div
            :class="['page-main', `page-main-${page.columns.length}`]"
            :style="{ margin: `0 -${page.columnGap / 2}px` }"
          >
            <div
              class="page-column"
              v-for="(column, columnNo) in page.columns"
              :key="columnNo"
              :style="{ padding: `0 ${page.columnGap / 2}px` }"
            >
              <div
                class="page-column-main"
                :id="[`column-${pageNo}-${columnNo}`]"
              >
                <div class="page-column-body" v-if="column.elements.length">
                  <topic-element-preview
                    class="page-column-element"
                    v-for="element in column.elements"
                    :key="element.id"
                    :data="element"
                  ></topic-element-preview>
                </div>
                <div class="page-column-body" v-else>
                  <div
                    class="page-column-forbid-area"
                    v-if="cardConfig.showForbidArea"
                  >
                    <p>该区域严禁作答</p>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- outer edit area -->
        <div class="page-main-outer">
          <page-number
            type="rect"
            :total="pages.length"
            :current="pageNo + 1"
          ></page-number>
          <page-number
            type="text"
            :total="pages.length"
            :current="pageNo + 1"
          ></page-number>
          <elem-undertaking
            v-if="cardConfig.undertakingEnable && pageNo === pages.length - 1"
            :content="cardConfig.undertakingBody"
            :page-size="cardConfig.pageSize"
          ></elem-undertaking>
          <course-barcode
            v-if="pageNo % 2 === 0"
            :data="cardConfig"
          ></course-barcode>
        </div>
      </div>
    </template>
  </div>
</template>

<script>
import TopicElementPreview from "./TopicElementPreview";
import ElemUndertaking from "../elements/undertaking/ElemUndertaking.vue";
import CourseBarcode from "./CourseBarcode.vue";
import PageNumber from "./PageNumber";
import previewTemp from "../previewTemp";
import exchangeMixins from "../mixins/exchange";

export default {
  name: "card-view",
  components: {
    TopicElementPreview,
    PageNumber,
    ElemUndertaking,
    CourseBarcode,
  },
  mixins: [exchangeMixins],
  props: {
    pages: {
      type: Array,
      default() {
        return [];
      },
    },
    cardConfig: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  methods: {
    getPreviewTemp(htmlContent) {
      return previewTemp(htmlContent);
    },
  },
};
</script>
