import { fromJS } from "immutable";
import {
  ZALO_TEMPLATE_INFO_ERROR,
  ZALO_TEMPLATE_INFO_SUCCESS,
  ZALO_TEMPLATE_INFO_REQUEST,
  ZALO_TEMPLATE_PREVIEW_RESET,
  ZALO_TEMPLATE_PREVIEW_INFO,
  ZALO_TEMPLATE_INFO_RESET,
  SUCCESS,
  REQUEST,
  ERROR,
} from "./constants";

const initialState = fromJS({
  zaloTemplateInfoStatus: "",
  zaloTemplateInfoValue: "",
  zaloTemplateInfoError: "",
  zaloTemplatePreviewData: "",
});

const zaloReducer = (state = initialState, action) => {
  switch (action.type) {
    case ZALO_TEMPLATE_INFO_REQUEST:
      return state
        .set("zaloTemplateInfoStatus", REQUEST)
        .set("zaloTemplateInfoValue", "")
        .set("zaloTemplateInfoError", null);

    case ZALO_TEMPLATE_INFO_SUCCESS:
      return state
        .set("zaloTemplateInfoStatus", SUCCESS)
        .set("zaloTemplateInfoValue", action.result)
        .set("zaloTemplateInfoError", null);

    case ZALO_TEMPLATE_INFO_ERROR:
      return state
        .set("zaloTemplateInfoStatus", ERROR)
        .set("zaloTemplateInfoValue", "")
        .set("zaloTemplateInfoError", action.error);

    case ZALO_TEMPLATE_PREVIEW_INFO:
      return state
        .set("zaloTemplateInfoStatus", SUCCESS)
        .set("zaloTemplatePreviewData", action.result)
        .set("zaloTemplateInfoError", null);

    case ZALO_TEMPLATE_PREVIEW_RESET:
      return state
        .set("zaloTemplateInfoStatus", REQUEST)
        .set("zaloTemplatePreviewData", "")
        .set("zaloTemplateInfoError", null);
    case ZALO_TEMPLATE_INFO_RESET:
      return state
        .set("zaloTemplateInfoStatus", REQUEST)
        .set("zaloTemplateInfoValue", "")
        .set("zaloTemplateInfoError", null);

    default:
      return state;
  }
};

export default zaloReducer;
