// Initial state
export const initialSidebarState = {
    nodes: [],
    expandedNodes: new Set(),
    pinnedNodePath: [],
    maxDepth: 4,
    searchTerm: "",
    searchResults: [],
    isSearching: false,
    activeSearchIndex: 0,
    activeNodeId: undefined,
    isStatusFilterEnabled: false,
};
// Action types
export var SidebarActionType;
(function (SidebarActionType) {
    SidebarActionType["SET_NODES"] = "SET_NODES";
    SidebarActionType["TOGGLE_NODE"] = "TOGGLE_NODE";
    SidebarActionType["OPEN_NODE"] = "OPEN_NODE";
    SidebarActionType["CLOSE_NODE"] = "CLOSE_NODE";
    SidebarActionType["TOGGLE_PIN"] = "TOGGLE_PIN";
    SidebarActionType["OPEN_LEVEL"] = "OPEN_LEVEL";
    SidebarActionType["CHANGE_SEARCH_TERM"] = "CHANGE_SEARCH_TERM";
    SidebarActionType["SET_SEARCH_RESULTS"] = "SET_SEARCH_RESULTS";
    SidebarActionType["SET_IS_SEARCHING"] = "SET_IS_SEARCHING";
    SidebarActionType["NEXT_SEARCH_RESULT"] = "NEXT_SEARCH_RESULT";
    SidebarActionType["PREVIOUS_SEARCH_RESULT"] = "PREVIOUS_SEARCH_RESULT";
    SidebarActionType["SYNC_ACTIVE_NODE_ID"] = "SYNC_ACTIVE_NODE_ID";
    SidebarActionType["TOGGLE_STATUS_FILTER"] = "TOGGLE_STATUS_FILTER";
    SidebarActionType["SET_FLATTENED_NODES"] = "SET_FLATTENED_NODES";
    SidebarActionType["SET_PINNED_NODE_PATH"] = "SET_PINNED_NODE_PATH";
    SidebarActionType["SET_EXPANDED_NODES"] = "SET_EXPANDED_NODES";
})(SidebarActionType || (SidebarActionType = {}));
// Reducer function
export const sidebarReducer = (state = initialSidebarState, action) => {
    switch (action.type) {
        case SidebarActionType.SET_NODES: {
            return {
                ...state,
                pinnedNodePath: [],
                nodes: action.payload,
            };
        }
        case SidebarActionType.TOGGLE_NODE: {
            const newExpandedNodes = new Set(state.expandedNodes);
            if (newExpandedNodes.has(action.payload)) {
                newExpandedNodes.delete(action.payload);
            }
            else {
                newExpandedNodes.add(action.payload);
            }
            return {
                ...state,
                expandedNodes: newExpandedNodes,
            };
        }
        case SidebarActionType.OPEN_NODE: {
            const newExpandedNodes = new Set(state.expandedNodes);
            newExpandedNodes.add(action.payload);
            return {
                ...state,
                expandedNodes: newExpandedNodes,
            };
        }
        case SidebarActionType.CLOSE_NODE: {
            const newExpandedNodes = new Set(state.expandedNodes);
            newExpandedNodes.delete(action.payload);
            return {
                ...state,
                expandedNodes: newExpandedNodes,
            };
        }
        case SidebarActionType.TOGGLE_PIN:
            // The actual logic for toggling pin will be handled in the provider
            // This is just a placeholder for the action
            return state;
        case SidebarActionType.OPEN_LEVEL:
            // The actual logic for opening levels will be handled in the provider
            // This is just a placeholder for the action
            return state;
        case SidebarActionType.CHANGE_SEARCH_TERM:
            return {
                ...state,
                searchTerm: action.payload,
            };
        case SidebarActionType.SET_SEARCH_RESULTS:
            return {
                ...state,
                searchResults: action.payload,
            };
        case SidebarActionType.SET_IS_SEARCHING:
            return {
                ...state,
                isSearching: action.payload,
            };
        case SidebarActionType.NEXT_SEARCH_RESULT: {
            const nextIndex = Math.min(state.searchResults.length - 1, state.activeSearchIndex + 1);
            return {
                ...state,
                activeSearchIndex: nextIndex,
            };
        }
        case SidebarActionType.PREVIOUS_SEARCH_RESULT: {
            const previousIndex = Math.max(0, state.activeSearchIndex - 1);
            return {
                ...state,
                activeSearchIndex: previousIndex,
            };
        }
        case SidebarActionType.SYNC_ACTIVE_NODE_ID:
            return {
                ...state,
                activeNodeId: action.payload,
            };
        case SidebarActionType.TOGGLE_STATUS_FILTER:
            return {
                ...state,
                isStatusFilterEnabled: !state.isStatusFilterEnabled,
            };
        case SidebarActionType.SET_PINNED_NODE_PATH: {
            return {
                ...state,
                pinnedNodePath: action.payload,
            };
        }
        case SidebarActionType.SET_EXPANDED_NODES:
            return {
                ...state,
                expandedNodes: action.payload,
            };
        default:
            return state;
    }
};
//# sourceMappingURL=sidebar-reducer.js.map