import { createContext, useContext } from "react";
import type { SightingType } from "../types/types";

type SightingFeedContextType = {
  sightings: (SightingType | null | undefined)[];
  selectedRef: number | null;
  setSelectedRef: (ref: number | null) => void;
  // effectiveSelected: SightingType | null;
  mostRecent: SightingType | null;
  side: string | undefined;
  selectedSighting: SightingType | null;
  setSelectedSighting: (sighting: SightingType | SightingType | null) => void;
  setSightingModalOpen: (isSightingModalOpen: boolean) => void;
  isSightingModalOpen: boolean;
  isError: boolean;
  isLoading: boolean;
  data: SightingType | undefined;
  sessionStarted: boolean;
};

export const SightingFeedContext = createContext<
  SightingFeedContextType | undefined
>(undefined);

export const useSightingFeedContext = () => {
  const ctx = useContext(SightingFeedContext);
  if (!ctx)
    throw new Error(
      "useSightingFeedContext must be used within SightingFeedProvider"
    );
  return ctx;
};
