import React, { createContext, useState, useContext, useRef } from 'react'; import { useErrorStore } from 'src/stores/errorStore'; const ErrorContext = createContext<{ error: string | null; showError: (message: string, loginNeeded: boolean) => void; hideError: () => void; resetErrorState: () => void; navigateToLogin: boolean; navigateToAuth: boolean; premiumError: boolean; }>({ error: null, showError: (message: string, loginNeeded: boolean) => {}, hideError: () => {}, resetErrorState: () => {}, navigateToLogin: false, navigateToAuth: false, premiumError: false }); export const ErrorProvider = ({ children }: { children: React.ReactNode }) => { const { isErrorShown, setErrorShown } = useErrorStore.getState(); const [error, setError] = useState(null); const [navigateToLogin, setNavigateToLogin] = useState(false); const [navigateToAuth, setNavigateToAuth] = useState(false); const [premiumError, setPremiumError] = useState(false); const showError = ( message: string, loginNeeded: boolean, authNeeded: boolean = false, premiumNeeded: boolean = false ) => { if (!isErrorShown) { setErrorShown(true); setError(message); setNavigateToLogin(loginNeeded); setNavigateToAuth(authNeeded); setPremiumError(premiumNeeded); } }; const hideError = () => { setError(null); }; const resetErrorState = () => { setTimeout(() => { setErrorShown(false); }, 10000); }; return ( {children} ); }; export const useError = () => useContext(ErrorContext);