'use client';

import { createContext, useContext } from 'react';

/**
 * True após o `PersistQueryClientProvider` estar activo (pós-hidratação).
 * Evita iniciar fetch de aparência antes da persistência restaurar o cache — o swap de
 * provider abortava o pedido e, em alguns browsers/rede, o login ficava no spinner.
 */
const QueryPersistReadyContext = createContext(false);

export function QueryPersistReadyProvider({
    ready,
    children,
}: {
    ready: boolean;
    children: React.ReactNode;
}) {
    return (
        <QueryPersistReadyContext.Provider value={ready}>{children}</QueryPersistReadyContext.Provider>
    );
}

export function useQueryPersistReady(): boolean {
    return useContext(QueryPersistReadyContext);
}
