import { HYDRATE } from 'next-redux-wrapper';

import * as actionTypes from '../constants/actionTypes';
import initialState from "./initialState";

const questionnaireReducer = (state = initialState.questionnaire, action) => 
{
	switch (action.type) 
	{
		/*
		case HYDRATE: 
		{
			return { 
				...state, 
				...action.payload.questionnaire, 
			};
		}
		*/

		case actionTypes.QUESTIONNAIRE_UPDATE: 
		{
			console.log("actionTypes.QUESTIONNAIRE_UPDATE", {
				...state, 
				...action.data.questionnaire, 
			});

			return {
				...state, 
				...action.data.questionnaire, 
			};
		}

		case actionTypes.QUESTIONNAIRE_SET_SIGN: 
		{
			return {
				...state, 
				sign: { ...state.sign, ...action.data.sign, },  
			};
		}

		case actionTypes.QUESTIONNAIRE_RESET: 
		{
			return {
				...state, 
				...action.data.questionnaire, 
			};
		}

		default: {
			return state;
		}
	}
};

export default questionnaireReducer;