import DangerMessage from "@/components/message/DangerMessage";
import { useGetGameCalendar, useGetRaidGroupCalendar, useGetRaidInstanceCalendarEvents } from "@/hooks/CalendarHooks";
import CalendarDisplay from "./CalendarDisplay";


export default function RaidGroupCalendarLoader({
	gameId,
	raidGroupId
}:{
	gameId: string;
	raidGroupId: string;
}){
	const gameCalendarQuery = useGetGameCalendar(gameId);
	const raidGroupCalendarQuery = useGetRaidGroupCalendar(raidGroupId);
	const raidInstanceCalendarQuery = useGetRaidInstanceCalendarEvents(raidGroupId);


	if(raidGroupCalendarQuery.status === "error"){
		return (<DangerMessage>Error {raidGroupCalendarQuery.error.message}</DangerMessage>);
	}
	else if(gameCalendarQuery.status === "error"){
		return (<DangerMessage>Error {gameCalendarQuery.error.message}</DangerMessage>);
	}
	else if(raidInstanceCalendarQuery.status === "error"){
		return (<DangerMessage>Error {raidInstanceCalendarQuery.error.message}</DangerMessage>);
	}
	else if((raidGroupCalendarQuery.status === "pending") || (gameCalendarQuery.status === "pending") || (raidInstanceCalendarQuery.status === "pending")){
		return (
			<div>
				Loading...
			</div>
		);
	}
	else{
		return (
			<CalendarDisplay
				raidGroupId={raidGroupId}
				calendarEvents={[...raidGroupCalendarQuery.data, ...gameCalendarQuery.data, ...raidInstanceCalendarQuery.data]}
			/>
		);
	}
}
