import React, { createContext, ReactNode, useContext, useState } from "react";

interface MainContextType {
	searchValue?: string;
	setSearchValue?: React.Dispatch<React.SetStateAction<string>>;
}

const MainContext = createContext<MainContextType | null>(null);
interface MainProviderProps {
	children: ReactNode;
}

export function MainProvider({ children }: MainProviderProps) {
	const [searchValue, setSearchValue] = useState("");
	return (
		<MainContext.Provider
			value={{
				searchValue,
				setSearchValue,
			}}>
			{children}
		</MainContext.Provider>
	);
}
export const useMainContext = () => {
	const context = useContext(MainContext);
	if (!context) {
		throw new Error("useMainContext must be used within MainProvider");
	}
	return context;
};
