<template>
  <CommonListPage 
    title="非遗传承人"
    itemType="article-character"
    detailsPage="/pages/inhert/inheritor/details"
    :dropdownNames="dropdownNames"
    :load="loadData" 
  />
</template>

<script setup lang="ts">
import CommonContent, { GetContentListParams } from '@/api/CommonContent';
import InheritorContent from '@/api/inheritor/InheritorContent';
import CommonListPage, { 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[]
) {
  return (await InheritorContent.getContentList(new GetContentListParams().setSelfValues({
    ichType: dropDownValues[0] == 0 ? undefined: dropDownValues[0],
    level: dropDownValues[1] == 0 ? undefined: dropDownValues[1],
    region: dropDownValues[2] == 0 ? undefined: dropDownValues[2],
  }), page, pageSize)).list;
}

onMounted(async () => {
  dropdownNames.value.push({ 
    options: [{
      id: 0, 
      name: '全部'
    }].concat((await CommonContent.getCategoryList(4)).map((item) => ({
      id: item.id,
      name: item.title,
    }))),
    defaultSelectedValue: 0,
  });
  dropdownNames.value.push({ 
    options: [{
      id: 0, 
      name: '全部'
    }].concat((await CommonContent.getCategoryList(2)).map((item) => ({
      id: item.id,
      name: item.title,
    }))),
    defaultSelectedValue: 0,
  });
  dropdownNames.value.push({ 
    options: [{
      id: 0, 
      name: '全部'
    }].concat((await CommonContent.getCategoryList(1)).map((item) => ({
      id: item.id,
      name: item.title,
    }))),
    defaultSelectedValue: 0,
  });
})
</script>
