/* eslint-disable prettier/prettier */
import { ref } from "vue";
import { PageContentInstance } from "/@/components/PageContent";

export function usePageSearch(callback?: (params: any) => any) {
  const pageContentRef = ref<PageContentInstance>(null);

  function handleSearchClick(params: any) {
    const { result, deleteProps } = callback ? callback(params) : { result: {}, deleteProps: [] }

    const mergeParams = {
      ...params,
      ...result
    };

    deleteProps.forEach(key => delete mergeParams[key])

    pageContentRef.value.getPageData(mergeParams);
  }

  function handleResetClick() {
    pageContentRef.value.getPageData();
  }

  return {
    pageContentRef,
    handleSearchClick,
    handleResetClick
  };
}
