<template>
  <CommonListPage 
    :title="querys.title || undefined"
    :load="loadData"
    :itemType="querys.itemType as any || undefined"
    :detailsPage="querys.detailsPage || 'byContent'"
    :detailsPageByContentCallback="resolveCommonContentGetPageDetailUrlAuto"
    :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';
import { resolveCommonContentGetPageDetailUrlAuto, resolveCommonContentSolveProps } from './CommonContent';
import type { IHomeCommonCategoryListTabListDataSolve } from '../data/CommonCategoryDefine';

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

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);

  if (querys.value.dataSolve) {
    res.list = resolveCommonContentSolveProps(
      res.list, 
      querys.value.dataSolve.split(',') as IHomeCommonCategoryListTabListDataSolve[]);
  }

  return res;
}
</script>