<script setup lang="ts">
import type {CmsArticle} from "~/api/cms/cmsArticle/model";
import {findTags, listCmsArticle, pageCmsArticle} from "~/api/cms/cmsArticle";
const props = withDefaults(
    defineProps<{
      data?: CmsArticle;
      model?: string;
    }>(),
    {}
);
const i18n = useI18n();
const list = ref<CmsArticle[]>([])
const tags = props.data?.tags ? JSON.parse(props.data?.tags)[0] : '';
const reload = () => {
  if(props.data?.tags){
    const tags = JSON.parse(props.data?.tags);
    findTags({
      tags: tags.join(',')
    }).then(data => {
      if(data){
        list.value = data.filter(d => d.model == 'article');
      }
    })
  }
}

watch(
    () => props.data?.articleId,
    () => {
      reload();
    },
    {immediate: true}
);
</script>

<template>
  <div class="relatenew relate"><h4>{{ $t('articleRelated')}}：</h4>
    <div class="p-1">
      <ul id="relate_n" class="news_list clearfix">
        <li v-for="(item,index) in list" :key="index"><a :href="detail(item)" :title="item.title">{{ item.title }}</a></li>
      </ul>
    </div>
  </div>
</template>

<style scoped lang="scss">

</style>
