import React from "react";
import { Vault } from "@hyperion-framework/vault";
const defaultState = {
    expanded: false,
    sequences: [],
    vault: new Vault(),
};
const YithStateContext = React.createContext(defaultState);
const YithDispatchContext = React.createContext(defaultState);
function yithReducer(state, action) {
    switch (action.type) {
        case "updateModal": {
            return Object.assign(Object.assign({}, state), { expanded: action.expanded });
        }
        case "updateSequences": {
            return Object.assign(Object.assign({}, state), { sequences: action.sequences });
        }
        default: {
            throw new Error(`Unhandled action type: ${action.type}`);
        }
    }
}
const YithProvider = ({ sequence, initialState = defaultState, children, }) => {
    const [state, dispatch] = React.useReducer(yithReducer, initialState);
    if (state.sequences.filter(function (e) {
        return e.id === sequence.id;
    }).length === 0) {
        state.sequences.push(sequence);
    }
    return (React.createElement(YithStateContext.Provider, { value: state },
        React.createElement(YithDispatchContext.Provider, { value: dispatch }, children)));
};
function useYithState() {
    const context = React.useContext(YithStateContext);
    if (context === undefined) {
        throw new Error("useYithState must be used within a YithProvider");
    }
    return context;
}
function useYithDispatch() {
    const context = React.useContext(YithDispatchContext);
    if (context === undefined) {
        throw new Error("useYithDispatch must be used within a YithProvider");
    }
    return context;
}
export { YithProvider, useYithState, useYithDispatch };
//# sourceMappingURL=yith-context.js.map