<template>
  <ul class="card-wrap">
    <li v-for="(item, idx) in list" :key="idx" class="mb-30" @click="fnMoveTo(item)">
      <div class="result-box">
        <div class="main-img">
          <img v-if="item.hasOwnProperty('files') && item.files.length > 0" :src="item.files[0].filePath" :alt="item.sj + ' 첫 번째 이미지'">
          <img v-else src="client/resources/images/img6.png" alt="Not found image">
        </div>
        <div class="text-box">
          <router-link :to="{ path: '/PicHistoryDetail.page' }">
            <h5>{{ item.sj }}</h5>
          </router-link>
          <p v-if="item.hasOwnProperty('adres')" class="address">{{ item.adres }}</p>
          <p class="text">{{ $stripHtml(item.cn) }}</p>
          <div class="mb-20">
            <ul class="category">
              <li v-for="(ctgry, ctgryIdx) of item.ctgrys" :key="ctgryIdx" class="category1">{{ ctgry.ctgryNm }}</li>
            </ul>
          </div>
          <div class="date">
            <ul>
              <li>생산연도 <b>{{ item.prdctnYear ? item.prdctnYear : '-' }}</b></li>
              <li>|</li>
              <li>등록 <b>{{ $dotFormatDate(item.rgsde) }}</b></li>
            </ul>
          </div>
        </div>
      </div>
    </li>
  </ul>
</template>
<script>
export default {
  name: "CardStyleComponent",

  props: {
    name: {
      type: String,
      default: 'P',
    },
    list: {
      type: Array,
      default: () => [],
    },
  },

  computed: {
    page() {
      switch (this.name) {
        case 'P':
          return 'PicHistoryDetail';
        case 'V':
          return 'VideoHistoryDetail';
        case 'M':
          return 'MediaVideoDetail';
        case 'N':
          return 'NewsReleaseDetail';
      }
    },
  },

  methods: {
    // 페이지 이동
    fnMoveTo(item) {
      let key = null;
      switch (this.name) {
        case 'P':
        case 'V':
          key = 'dcryId';
          break;
        case 'M':
          key = 'mediaVidoId';
          break;
        case 'N':
          key = 'nesDtaId';
          break;
      }
      this.$router.push({ name: this.page, query: { id: item[key] } });
    }
  },
};
</script>