import { useState, type ReactNode } from "react";
import { useSightingFeed } from "../../hooks/useSightingFeed";
import { SightingFeedContext } from "../SightingFeedContext";

type SightingFeedProviderProps = {
  url: string;
  children: ReactNode;
  side: string;
};

export const SightingFeedProvider = ({
  children,
  url,
  side,
}: SightingFeedProviderProps) => {
  const {
    sightings,
    selectedRef,
    setSelectedRef,
    // effectiveSelected,
    setSelectedSighting,
    selectedSighting,
    mostRecent,
  } = useSightingFeed(url);
  const [isSightingModalOpen, setSightingModalOpen] = useState(false);

  return (
    <SightingFeedContext.Provider
      value={{
        sightings,
        selectedRef,
        setSelectedRef,
        setSelectedSighting,
        selectedSighting,
        setSightingModalOpen,
        isSightingModalOpen,
        // effectiveSelected,
        mostRecent,
        side,
      }}
    >
      {children}
    </SightingFeedContext.Provider>
  );
};
