import React from 'react';
import { Alert } from '@mui/material';
import { isFetchBaseQueryError } from '../error';
import type { StatusProps } from '../models';
import type { Data } from '../error';

const Status = ({ error, setOpen, type }: StatusProps) => {
  return isFetchBaseQueryError(error) ? (
    <Alert severity="error" onClose={() => setOpen(false)}>
      {(error.data as Data).message}
    </Alert>
  ) : (
    <Alert severity="error" onClose={() => setOpen(false)}>
      {`${type} login failed`}
    </Alert>
  );
};

export default Status;
