import { useEffect, useState } from "react";
import { ActivityRouteEntity } from "../../activity/domain/entities/activity_info_entity";
import { useDataContext } from "../../common/contexts/data_context";
import { useGet } from "../../common/hooks/useGet";
import { RouteEntity } from "../domain/entities/route";

export const useGetRouteActivities = (routeId: number) => {
  const { routeRepository } = useDataContext();
  const callback = async () => {
    return await routeRepository!.getRoute(routeId);
  };
  const {
    data: routeActivities,
    requestStatus,
    refresh,
  } = useGet<RouteEntity>(callback);
  const [activities, setActivities] = useState<ActivityRouteEntity[]>([]);
  useEffect(() => {
    if (routeActivities) {
      setActivities([...routeActivities.travelPlaces]);
    }
  }, [routeActivities]);
  return { activities, requestStatus, refresh };
};
