import EmailActionTypes from "./email.types";

const INITIAL_STATE = {
  emailConfig: {
    messageOptions: {
      from: { name: "ShopName", address: "noreply@bodyshop.app" },
      to: null,
      replyTo: null,
    },
    template: { name: null, variables: {} },
  },

  visible: false,
  error: null,
};

const emailReducer = (state = INITIAL_STATE, action) => {
  switch (action.type) {
    case EmailActionTypes.TOGGLE_EMAIL_OVERLAY_VISIBLE:
      return {
        ...state,
        visible: !state.visible,
      };
    case EmailActionTypes.SET_EMAIL_OPTIONS:
      return {
        ...state,
        emailConfig: { ...action.payload },
        visible: true,
      };
    default:
      return state;
  }
};

export default emailReducer;
