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

// Define the shape of the mouse position state
interface MousePositionState {
  x: number;
  y: number;
}

// Initial state center point
const initialState: MousePositionState = {
  x: window.innerWidth / 2,
  y: window.innerHeight / 2,
};

// Create a slice for mouse position
const mousePositionSlice = createSlice({
  name: 'mousePosition',
  initialState,
  reducers: {
    setMousePosition: (state, action: PayloadAction<MousePositionState>) => {
      state.x = action.payload.x;
      state.y = action.payload.y;
    },
  },
});

// Export actions
export const { setMousePosition } = mousePositionSlice.actions;

// Export reducer
export default mousePositionSlice.reducer;
