export const actionIsOpen = (value) => ({type: 'OPEN', value});

export const actionModalContent = (value) => ({type: 'CONTENT', value});

export const actionModalDraft = (value, draftName) => ({type: 'MODALDRAFT', value, draftName});



export const actionOpenModal = (content) => 
    dispatch => {
        dispatch(actionModalContent(content));
        dispatch(actionIsOpen(true));
    }

export function modalReducer(state = {}, {type, value, draftName}){
    if(type === 'OPEN'){
        return {
            ...state, isOpen: value
        }
    }
    if(type === 'CONTENT'){
        return {
            ...state, content: value
        }
    }
    if(type === 'MODALDRAFT'){
        return{
            ...state, draft : {...state?.draft, [draftName]: value}
        }
    }
    return state
}