import { useEducationListSearch, useLogos } from './useEducation';

export const useSearchEducation = (
  token: string,
  educationType: string,
  isFuture: string,
  year: string,
  relationType: string,
) => {
  const {
    data: educationList,
    refetch: refetchList,
    isFetching: isEducationListLoading,
  } = useEducationListSearch(token, educationType, isFuture, year, relationType);

  const logos = useLogos(token, educationList || []);

  const list = educationList?.map(item => {
    const logo = logos.map(item => item.data).find(logoItem => logoItem?.id === item.logoId);
    return {
      ...item,
      logo: logo?.documentContent || '',
    };
  });

  const isLoading = isEducationListLoading;

  return { list, refetchList, isLoading };
};
