import { STATUS, Records, QueryFeedback, getFeedbackList } from '@/api/feedback/feedback';
import { onMounted, ref } from 'vue';

export function useFeedbackList() {
  const feedbackList = ref<Records[]>([]);
  const pageNumber = ref<number>(1);
  const pageSize = ref<number>(10);
  const problemStatus = ref<STATUS>(STATUS.unhandled);
  const queryDescription = ref<string>('');
  const totalPage = ref<number>();
  const totalRow = ref<number>();

  const getList = () => {
    const params: QueryFeedback = {
      pageNumber: pageNumber.value,
      pageSize: pageSize.value,
      //problemDescription: queryDescription.value
      problemStatus: problemStatus.value,
    };
    if (queryDescription.value) {
      params.problemDescription = queryDescription.value;
    }
    getFeedbackList(params).then((res) => {
      feedbackList.value = res.records;
      totalPage.value = res.totalPage;
      totalRow.value = res.totalRow;
    });
  };

  onMounted(() => {
    getList();
  });

  return {
    feedbackList,
    pageNumber,
    pageSize,
    problemStatus,
    queryDescription,
    totalPage,
    totalRow,
    getList,
  };
}

export default useFeedbackList;
