import {connect} from 'react-redux';
import {add_dialog_msg, get_select_list, clear_select_list, get_schedule_list, add_schedule, del_schedule, edit_schedule, sw_schedule, clear_schedule} from '../../actions';
import SchedulePage from '../../components/AdminPage/Schedule';

const mapStateToProps = (state) => ({
	i18n: state.i18n,
	devs: state.lists.selectdev,
	list: state.lists.schedule.list,
	dos: state.lists.schedule.do,
	les: state.lists.schedule.leone,
	ios: state.lists.schedule.iogroup,
	permissions: (function() {
        let p = sessionStorage.getItem('permissions');
        if (!p) return {};
        let json = {};
        try {
            json = JSON.parse(p);
        } catch (e) {
            return {};
        }
        return json
    }())
});

const mapDispatchToProps = (dispatch, ownProps) => ({
	showDialog: (msg) => {
		dispatch(add_dialog_msg(msg));
	},
	clearList: () => {
		dispatch(clear_schedule());
	},
	getSelectList: (data) => {
		dispatch(get_select_list(data));
	},
	clearSelectList: () => {
		dispatch(clear_select_list());
	},
	getScheduleList: () => {
		dispatch(get_schedule_list());
	},
	addSchedule: (data) => {
		dispatch(add_schedule(data));
	},
	editSchedule: (data) => {
		dispatch(edit_schedule(data));
	},
	delSchedule: (data) => {
		dispatch(del_schedule(data));
	},
	swSchedule: (data) => {
		dispatch(sw_schedule(data));
	}
});

export default connect(mapStateToProps, mapDispatchToProps)(SchedulePage);