import { ToastListItem } from '../../toast/toast.types'

export const toastsReducer = (
  state: { list: ToastListItem[] },
  action: { type: 'add' | 'remove'; toast: ToastListItem },
) => {
  switch (action.type) {
    case 'add': {
      return { list: [action.toast, ...state.list] }
    }
    case 'remove': {
      return { list: state.list.filter(t => t.id !== action.toast.id) }
    }
    default: {
      throw new Error(`Unhandled action type: ${action.type}`)
    }
  }
}

export const genericReducer = (state: any, action: any) => (state = action)
