<template>
  <CommonListPage 
    title="我的收藏"
    showTotal
    :dropDownNames="dropdownNames"
    detailsPage="custom"
    :load="loadData" 
    @goCustomDetails="goCustomDetails"
  />
</template>

<script setup lang="ts">
import { GetContentListParams } from '@/api/CommonContent';
import InheritorContent from '@/api/inheritor/InheritorContent';
import ProductsContent from '@/api/inheritor/ProductsContent';
import ProjectsContent from '@/api/inheritor/ProjectsContent';
import UnmoveableContent from '@/api/inheritor/UnmoveableContent';
import UserApi from '@/api/user/UserApi';
import { navTo } from '@/components/utils/PageAction';
import CommonListPage, { type CommonListItem, type DropDownNames } from '@/pages/article/common/CommonListPage.vue';
import { onMounted, ref } from 'vue';

const dropdownNames = ref<DropDownNames[]>([]);

async function loadData(
  page: number, 
  pageSize: number,
  searchText: string,
  dropDownValues: number[]
) {
  
  const res = await UserApi.getUserCollect(page, pageSize);
  if (searchText)
    res.list = res.list.filter((p) => (p.title as string).includes(searchText));
  res.list.forEach((p) => {
    switch(p.modelId) {
      default:
        p.itemType = p.type === GetContentListParams.TYPE_VIDEO ? 'video' : 'article';
        break;
      case UnmoveableContent.modelId:
        p.itemType = 'artifact';
        break;
      case ProductsContent.modelId:
      case ProjectsContent.modelId:
        p.itemType = 'intangible';
        break;
      case InheritorContent.modelId:
        p.itemType = 'inheritor';
        break;
    }
    p.bottomTags = [
      p.levelText, 
      p.batchText,
      p.ichTypeText,
    ];
  })
  return {
    list: res.list as unknown as CommonListItem[],
    total: res.total,
  };
}

function goCustomDetails(item: any) {
  const params = {
    id: item.id,
    modelId: item.modelId,
    mainBodyColumnId: item.mainBodyColumnId,
  }
  switch (item.itemType) {
    default:
    case 'article':
      navTo('/pages/article/details', params)
      break;
    case 'video':
      navTo('/pages/video/details', params)
      break;
    case 'artifact':
      navTo('/pages/article/data/details?pageConfigName=artifact-details', params)
      break;
    case 'intangible':
      navTo('/pages/article/data/details?pageConfigName=intangible-details', params)
      break;
    case 'inheritor':
      navTo('/pages/article/data/details?pageConfigName=inheritor-details', params)
      break;

  }

}

onMounted(async () => {
  
})
</script>
