import type { Reducer } from 'react';
import type { AuthAction, AuthState } from './types';

export const authReducer: Reducer<AuthState, AuthAction> = (state, action) => {
  switch (action.type) {
    case 'LOG_IN':
      return { isAuthenticated: true, currentUser: action.user ?? state.currentUser };
    case 'LOG_OUT':
      return { isAuthenticated: false };
    default:
      return state;
  }
};
