const key = require('keymaster');
const actions = require('./actions');

function setupKeys(store) {
    store.subscribe(() => {
        const state = store.getState();

        key.unbind('esc');

        if (state.activeItem) {
            key('esc', () => store.dispatch(actions.setActiveItem(null)));
        }
        if (state.activeSkill) {
            key('esc', () => store.dispatch(actions.setActiveSkill(null)));
        }
        if (state.activeIncoming) {
            key('esc', () => store.dispatch(actions.setActiveIncoming(null)));
        }
    });
}

module.exports = setupKeys;
