import DangerMessage from "@/components/message/DangerMessage";
import { useGetPersonCharactersByPersonIdSearch } from "@/hooks/PersonCharacterHooks";
import { Person } from "@/interface/Person";
import { RaidGroup } from "@/interface/RaidGroup";
import PersonCharacterList from "./PersonCharacterList";
import PersonCharacterListSkeleton from "./PersonCharacterListSkeleton";


export default function PersonCharacterLoader({
	raidGroup,
	person,
	page,
	pageSize,
	searchTerm
}:{
	raidGroup: RaidGroup;
	person: Person;
	page: number;
	pageSize: number;
	searchTerm?: string;
}){
	const personCharactersQuery = useGetPersonCharactersByPersonIdSearch(person.personId ?? "", raidGroup.raidGroupId ?? "", page - 1, pageSize, searchTerm);


	if(personCharactersQuery.status === "pending"){
		<PersonCharacterListSkeleton/>
	}
	else if(personCharactersQuery.status === "error"){
		return <DangerMessage>Error: {personCharactersQuery.error.message}</DangerMessage>
	}
	else{
		return (
			<PersonCharacterList
				personCharacters={personCharactersQuery.data ?? []}
				raidGroup={raidGroup}
				person={person}
			/>
		);
	}
}
