import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import { RootState } from '../../app/store'
import { ParticipantsViewType, ViewModel } from './models'

const initialState: ViewModel = {
  participantsView: {
    currentView: ParticipantsViewType.Grid,
  },
}

export const viewSlice = createSlice({
  name: 'view',
  initialState,
  reducers: {
    changeParticipantsView: (state, action: PayloadAction<ParticipantsViewType>) => {
      state.participantsView.currentView = action.payload
    },
  },
})

export const { changeParticipantsView } = viewSlice.actions

export const selectCurrentParticipantsView = (state: RootState) => state.view.participantsView.currentView

export default viewSlice.reducer
