import getPaymentTypes from "@/utils/requests/getPaymentTypes";
import { useQuery } from "@tanstack/react-query";
import { createContext, useContext, useState } from "react";
import type { IauthenticationData } from "./Types";
export interface UserAuthenticationContextProps {
	isAuthenticated: boolean;
	setIsAuthenticated: React.Dispatch<React.SetStateAction<boolean>>;
	setAuthenticationData: React.Dispatch<React.SetStateAction<IauthenticationData>>;
}

export const UserAuthenticationContext = createContext<UserAuthenticationContextProps>({
	isAuthenticated: false,
	setIsAuthenticated: () => {},
	setAuthenticationData: () => {},
});

export const UserAuthenticationContextProvider = ({ children }: { children: React.ReactNode }) => {
	const [isAuthenticated, setIsAuthenticated] = useState(false);
	const [authenticationData, setAuthenticationData] = useState<IauthenticationData>({
		access: "",
		refresh: "",
	});

	const { data, isLoading, error } = useQuery({
		queryKey: ["paymentTypes"],
		queryFn: getPaymentTypes,
		enabled: true,
	});

	console.log("data", data);
	console.log("isLoading", isLoading);
	console.log("error", error);

	return (
		<UserAuthenticationContext.Provider
			value={{ isAuthenticated: isAuthenticated, setIsAuthenticated, setAuthenticationData }}
		>
			{children}
		</UserAuthenticationContext.Provider>
	);
};

export const useUserAuthenticationContext = () => {
	return useContext(UserAuthenticationContext);
};
