"use strict";

import { createSlice } from '@reduxjs/toolkit';
const initialState = {
  messageHeap: []
};

// Reducers extracted as a named const so we can give the slice an
// explicit Slice<State, typeof reducers, Name> type. Without that, tsc's
// declaration emission inlines immer's internal WritableNonArrayDraft
// type and fails with TS4023.
const reducers = {
  addMessageToHeap: (state, action) => {
    state.messageHeap.push(action.payload);
  },
  removeMessageFromHeapById: (state, action) => {
    const index = state.messageHeap.findIndex(m => m.id === action.payload);
    if (index !== -1) {
      state.messageHeap.splice(index, 1);
    }
  },
  clearHeap: state => {
    state.messageHeap = [];
  }
};
export const roomHeapSlice = createSlice({
  name: 'roomHeapStore',
  initialState,
  reducers
});
export const {
  addMessageToHeap,
  clearHeap,
  removeMessageFromHeapById
} = roomHeapSlice.actions;
export default roomHeapSlice.reducer;
//# sourceMappingURL=roomHeapSlice.js.map