import { produce } from "immer";
import { LinkerActions } from "../actions/linkerActions";
// The linker state before we initialize the linker. The initialize linker function will
// make calls to the LinkerClient and
// fill in the state with the relevant linker information.
export const initialState = {
    channels: {},
    isAccessibleLinker: true,
};
// The linker's reducer
export const linkerReducer = produce((state, action) => {
    LinkerActions.match(action, {
        UPDATE_CHANNEL_STATUS: ({ channelId, active }) => {
            const targetChannel = state.channels[channelId];
            if (targetChannel)
                targetChannel.active = active;
        },
        SET_CHANNELS: ({ channels }) => {
            state.channels = channels.map((channel, index) => {
                return {
                    id: index,
                    name: channel.name,
                    color: channel.color,
                    border: channel.border,
                    active: false,
                };
            });
        },
        UPDATE_ACTIVE_CHANNELS: ({ channelNames, windowIdentifier }) => {
            const channelNameArray = Object.values(channelNames).map((obj) => obj.name);
            state.windowIdentifier = windowIdentifier;
            for (const channel of Object.values(state.channels)) {
                if (channel) {
                    channel.active = channelNameArray.includes(channel.name);
                }
            }
        },
        SET_ACCESSIBILITY: ({ isAccessibleLinker }) => {
            state.isAccessibleLinker = isAccessibleLinker;
        },
        default: () => state,
    });
}, initialState);
//# sourceMappingURL=linkerReducer.js.map