<template>
  <CommonListPage 
    :title="querys.title || undefined"
    :load="loadData"
    :itemType="querys.itemType as any || undefined"
    :detailsPage="querys.detailsPage || undefined"
    :detailsParams="{
      mainBodyColumnId: querys.mainBodyColumnId || undefined,
      modelId: querys.modelId || undefined,
    }"
  />
</template>

<script setup lang="ts">
import { useLoadQuerys, stringDotNumbersToNumbers } from '@/common/composeabe/LoadQuerys';
import CommonListPage from './CommonListPage.vue';
import CommonContent, { GetContentListParams } from '@/api/CommonContent';

const { querys } = useLoadQuerys({
  mainBodyColumnId: '',
  modelId: 0,
  itemType: '',
  detailsPage: '',
  title: '',
  region: '',
});

async function loadData(
  page: number, 
  pageSize: number,
  searchText: string,
  dropDownValues: number[]
) {
  const mainBodyColumnId = stringDotNumbersToNumbers(querys.value.mainBodyColumnId);

  const res = await CommonContent.getContentList(new GetContentListParams().setSelfValues({
    mainBodyColumnId: mainBodyColumnId || undefined,
    modelId: querys.value.modelId || undefined,
    keywords: searchText,
    region: querys.value.region || undefined,
  }), page, pageSize);

  return res.list;
}
</script>