import { UseSelectGetItemPropsOptions } from "downshift";
import { Context, createContext, MutableRefObject } from "react";
import { SingleSelectedOption } from "../shared/types";

type SingleSelectContextType = {
  getItemProps: (options: UseSelectGetItemPropsOptions<any>) => any;
  selectedItem: SingleSelectedOption;
  highlightedIndex: number;
  optionIndexRef: MutableRefObject<number>;
  setOptionIndex: (newIndex: number) => void;
};

const defaultContext: SingleSelectContextType = {
  getItemProps: () => {},
  selectedItem: null,
  highlightedIndex: 0,
  optionIndexRef: { current: 0 },
  setOptionIndex: () => {},
};

export const SingleSelectContext: Context<SingleSelectContextType> = createContext<SingleSelectContextType>(
  defaultContext,
);
