import { containerConnect } from 'Framework/ComponentContainer';
import AlertDialog from '../Components/AlertDialog';
import { Services } from 'App/ServiceLocator';
import { t } from 'Framework/i18n';

const mapStateToProps = ({ ui: { error } }) => ({
    Component: AlertDialog,
    message:
        error && (error.message || (error.type && t(`errorTypes.${error.type}`)) || t('errorTypes.unknown')),
    title: t('errorDialogTitle'),
});

const mapDispatchToProps = () => ({
    dismissMessage: () => Services.ui.dismissError(),
});

export default containerConnect(mapStateToProps, mapDispatchToProps);
