import CircularProgress from '@material-ui/core/CircularProgress';
import containerConnect from 'Framework/ComponentContainer';
import { Services } from 'App/ServiceLocator';
import SaveConfiguration from '../Components/SaveConfiguration';
import { getShareUrl } from '../../Reducers/Configurator/Selectors';

const mapStateToProps = ({ ui, configurator }) => ({
    Component: SaveConfiguration,
    ProgressComponent: CircularProgress,
    show: !!ui.visibilityMap.saveConfiguration,
    workInProgress: !!ui.backgroundWorkMap.saveConfiguration,
    errorMessage: ui.error && ui.error.message,
    code: configurator.configuration.code || '',
    savedconfiguration: configurator.configuration,
    loadLoginInfoInProgress: !!ui.backgroundWorkMap.loadLoginInfo,
    shareUrl: getShareUrl(configurator),
});

const mapDispatchToProps = () => ({
    onClose: () => Services.ui.hide('saveConfiguration'),
    onOkClick: () => Services.ui.hide('saveConfiguration'),
});

export default containerConnect(mapStateToProps, mapDispatchToProps);
