import request from '@/utils/request';
import type { HomeRecommendResponse } from './types/response';
import { ref } from 'vue';
import type { AxiosResponse } from 'axios';

type RecommendParams = {
  page: string;
  per_page: string;
  sort: string;
};
/**
 * 首页推荐内容
 * @param params 可选参数
 * @returns  推荐结果
 */
export function recommend(params: Partial<RecommendParams>) {
  const code = ref();
  const message = ref();
  const data = ref<HomeRecommendResponse['data']>();

  request<HomeRecommendResponse>({
    url: `/console/survey/trend/list`,
    params
  }).then((res) => {
    code.value = res.data.code;
    message.value = res.data.message;
    data.value = res.data.data;
  });

  return {
    code,
    message,
    data
  };
}
