import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Alert, Snackbar } from '@mui/material';
import { close, selectSnackbarState } from '../slices/snackbarSlice';

const Status = () => {
  const dispatch = useDispatch();
  const snackbarState = useSelector(selectSnackbarState);

  const closeSnackbar = () => {
    dispatch(close());
  };

  return (
    <Snackbar
      open={snackbarState.open}
      onClose={closeSnackbar}
      autoHideDuration={5000}
    >
      <div>
        <Alert severity={snackbarState.severity} onClose={closeSnackbar}>
          {snackbarState.message}
        </Alert>
      </div>
    </Snackbar>
  );
};

export default Status;
