'use client';
import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useContext, useState, useCallback } from 'react';
const PlaygroundNavigationContext = /*#__PURE__*/ createContext(undefined);
export function PlaygroundNavigationProvider({ children }) {
    const [state, setState] = useState({
        activeTab: null,
        highlightField: null,
        showError: false
    });
    const navigateToTab = useCallback((tab)=>{
        setState((prev)=>({
                ...prev,
                activeTab: tab,
                highlightField: null,
                showError: false
            }));
    }, []);
    const navigateAndHighlight = useCallback((tab, field, showError = true)=>{
        setState({
            activeTab: tab,
            highlightField: field || null,
            showError
        });
        // Auto-clear highlight after a delay
        if (field) {
            setTimeout(()=>{
                setState((prev)=>({
                        ...prev,
                        highlightField: null,
                        showError: false
                    }));
            }, 3000);
        }
    }, []);
    const clearHighlight = useCallback(()=>{
        setState((prev)=>({
                ...prev,
                highlightField: null,
                showError: false
            }));
    }, []);
    const setActiveTab = useCallback((tab)=>{
        setState((prev)=>({
                ...prev,
                activeTab: tab
            }));
    }, []);
    const resetNavigation = useCallback(()=>{
        setState({
            activeTab: null,
            highlightField: null,
            showError: false
        });
    }, []);
    return /*#__PURE__*/ _jsx(PlaygroundNavigationContext.Provider, {
        value: {
            state,
            navigateToTab,
            navigateAndHighlight,
            clearHighlight,
            setActiveTab,
            resetNavigation
        },
        children: children
    });
}
export function usePlaygroundNavigation() {
    const context = useContext(PlaygroundNavigationContext);
    if (context === undefined) {
        throw new Error('usePlaygroundNavigation must be used within a PlaygroundNavigationProvider');
    }
    return context;
}
