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

type Fn = (params?: any) => any

export function usePageSearch(searchCallback?: Fn, resetCallback?: Fn) {
  const pageContentRef = ref<PageContentInstance>(null);

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

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

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

    pageContentRef.value?.getPageData(mergeParams);
  }

  function handleResetClick() {
    pageContentRef.value?.getPageData();
    resetCallback && resetCallback()
  }

  return {
    pageContentRef,
    handleSearchClick,
    handleResetClick
  };
}
