import produce from 'immer';
import reducerRegistry from '~/Utils/reducerRegistry';

export const initialState = {
    select: {
      show: false,
      items: [],
      selectedItem: null,
      itemRender: null,
      onChange: (item) => {},
      onCancel: () => {},
      setSelectedItem: () => {},
    },
};

export default function reducer(state = initialState, action = {}) {
    return produce(state, draft => {
        switch (action.type) {
            case SELECT_SHOW:
                draft.select = action.payload;
                break;
            case CHANGE_SELECTED_ITEM:
                draft.select.selectedItem = action.payload;
                break;
        }
    });
}

export const SELECT_SHOW = 'GLOBAL_SELECT_BOX/SELECT_OPEN';
export const CHANGE_SELECTED_ITEM = 'GLOBAL_SELECT_BOX/CHANGE_SELECTED_ITEM';
export const selectOpenAction = payload => ({ type: SELECT_SHOW, payload });
export const changeSelectedItemAction = payload => ({ type: CHANGE_SELECTED_ITEM, payload });
