import { containerConnect } from 'Framework/ComponentContainer';
import { setStockInformationOption } from 'App/Reducers/Configurator/Actions';
import { setVisible } from 'App/Reducers/UI/Actions';
import OptionsList from '../../Components/OptionsList';
import { getConf } from '../../../../configuration';
import { Services } from 'App/ServiceLocator';

const mapStateToProps = ({ ui, configurator, api }) => {
    const showDialog = !!ui.visibilityMap.incompatibility || !!ui.visibilityMap.optionDetails;

    return {
        Component: OptionsList,
        isLoading: api.isFetching && !showDialog,
        optionclassification: ui.visibilityMap.optionlist ? configurator.selectedoptionclassification : {},
        options: configurator.options,
        show: !!ui.visibilityMap.optionlist,
        isAdminMode: !!getConf('adminMode'),
    };
};

const mapDispatchToProps = dispatch => ({
    viewStockInformation: option => {
        dispatch(setStockInformationOption(option));
        dispatch(setVisible('stockInformation', true));
    },
    onClose: () => dispatch(setVisible('optionlist', false)),
    setOptionInputText: (identifier, value) => Services.configurator.setOptionInputText(identifier, value),
});

export default containerConnect(mapStateToProps, mapDispatchToProps);
