'use client';

import { createContext, useContext, ReactNode } from 'react';
import { useWikiMap } from '@/hooks/useWikiMap';

interface WikiMapContextValue {
    wikiMap: Map<string, string>;
    isLoading: boolean;
    refresh: () => void;
}

const WikiMapContext = createContext<WikiMapContextValue | undefined>(undefined);

export function WikiMapProvider({ children }: { children: ReactNode }) {
    const wikiMapData = useWikiMap();
    return (
        <WikiMapContext.Provider value={wikiMapData}>
            {children}
        </WikiMapContext.Provider>
    );
}

export function useWikiMapContext(): WikiMapContextValue {
    const ctx = useContext(WikiMapContext);
    if (!ctx) throw new Error('useWikiMapContext must be used within WikiMapProvider');
    return ctx;
}
