"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.roomHeapSlice = exports.removeMessageFromHeapById = exports.default = exports.clearHeap = exports.addMessageToHeap = void 0;
var _toolkit = require("@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 = [];
  }
};
const roomHeapSlice = exports.roomHeapSlice = (0, _toolkit.createSlice)({
  name: 'roomHeapStore',
  initialState,
  reducers
});
const {
  addMessageToHeap,
  clearHeap,
  removeMessageFromHeapById
} = roomHeapSlice.actions;
exports.removeMessageFromHeapById = removeMessageFromHeapById;
exports.clearHeap = clearHeap;
exports.addMessageToHeap = addMessageToHeap;
var _default = exports.default = roomHeapSlice.reducer;
//# sourceMappingURL=roomHeapSlice.js.map