import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import { RootState } from '../../app/store'
import { VirtualBackgroundModel } from './models'
import { VirtualBackgroundType } from '@zocks-communications/client-sdk-js'

const initialState: VirtualBackgroundModel = {
  currentVirtualBackground: null,
}

export const virtualBackgroundSlice = createSlice({
  name: 'virtualBackground',
  initialState,
  reducers: {
    setCurrentVirtualBackground: (state, action: PayloadAction<VirtualBackgroundType>) => {
      state.currentVirtualBackground = action.payload
    },
    clearCurrentVirtualBackground: (state) => {
      state.currentVirtualBackground = null
    },
  },
})

export const { setCurrentVirtualBackground, clearCurrentVirtualBackground } = virtualBackgroundSlice.actions

export const selectCurrentVirtualBackground = (state: RootState) => state.virtualBackground.currentVirtualBackground

export default virtualBackgroundSlice.reducer
