import { createSlice, PayloadAction } from '@reduxjs/toolkit';

/**
 * Main slice - UI state that doesn't belong to other slices
 *
 * Note: User data is stored in authSlice.currentUser.
 * This slice previously had duplicate user fields that were never populated.
 */

interface MainState {
  /** Field focus with ctrl+k (to register only once) */
  isFieldFocusRegistered: boolean;
}

const initialState: MainState = {
  isFieldFocusRegistered: false,
};

export const mainSlice = createSlice({
  name: 'main',
  initialState,
  reducers: {
    setFieldFocusRegistered: (state, action: PayloadAction<boolean>) => {
      state.isFieldFocusRegistered = action.payload;
    },
  },
});

// Action creators are generated for each case reducer function
export const { setFieldFocusRegistered } = mainSlice.actions;

export default mainSlice.reducer;
