import { transitions } from "./clark-fsm.js";
export const transitionForEvent = (event, { from } = {}) => {
    let transitions = getAllTransitionsForEvent(event);
    if (from) {
        transitions = transitions.filter((t) => t.from === from);
    }
    if (transitions.length === 0) {
        throw new Error(`No transitions found for event type "${event.type}"`);
    }
    if (transitions.length > 1) {
        throw new Error(`Multiple transitions found for event type "${event.type}"`);
    }
    return transitions[0];
};
const getAllTransitionsForEvent = (event) => {
    const result = [];
    for (const [fromState, stateTransitions] of Object.entries(transitions)) {
        if (event.type in stateTransitions) {
            const toState = stateTransitions[event.type];
            result.push({
                from: fromState,
                to: toState,
                event: event,
            });
        }
    }
    return result;
};
//# sourceMappingURL=test-util.js.map