import { URLS } from "../api/apiConfig";
import { TAxios } from "../api/TAxios";
import { types } from "./actionTypes";

// 약관 정보 조회 IF-LGSP-005
export const getHomeTerms = (props) => (dispatch, getState) => {
  const { trmsTpCdList, mbrNo } = props;

  const onSuccess = (response) => {
    console.log("getHomeTerms onSuccess ", response.data);

    dispatch({
      type: types.GET_HOME_TERMS,
      payload: response.data,
    });
  };

  const onFail = (error) => {
    console.error("getHomeTerms onFail ", error);
  };

  TAxios(
    dispatch,
    getState,
    "get",
    URLS.GET_HOME_TERMS,
    { trmsTpCdList, mbrNo },
    {},
    onSuccess,
    onFail
  );
};

// 메뉴 목록 조회 IF-LGSP-044
export const getHomeMenu = () => (dispatch, getState) => {
  const onSuccess = (response) => {
    console.log("getHomeMenu onSuccess ", response.data);

    dispatch({
      type: types.GET_HOME_MENU,
      payload: response.data,
    });
  };

  const onFail = (error) => {
    console.error("getHomeMenu onFail ", error);
  };

  TAxios(
    dispatch,
    getState,
    "get",
    URLS.GET_HOME_MENU,
    {},
    {},
    onSuccess,
    onFail
  );
};

// HOME LAYOUT 정보 조회 IF-LGSP-300
export const getHomeLayout = () => (dispatch, getState) => {
  const onSuccess = (response) => {
    console.log("getHomeLayout onSuccess", response.data);

    dispatch({
      type: types.GET_HOME_LAYOUT,
      payload: response.data.data,
    });
  };

  const onFail = (error) => {
    console.error("getHomeLayout onFail", error);
  };

  TAxios(
    dispatch,
    getState,
    "get",
    URLS.GET_HOME_LAYOUT,
    {},
    {},
    onSuccess,
    onFail
  );
};

// HOME Main Contents Banner 정보 조회 IF-LGSP-301
export const getHomeMainContents = () => (dispatch, getState) => {
  const onSuccess = (response) => {
    console.log("getHomeMainContents onSuccess", response.data);

    dispatch({
      type: types.GET_HOME_MAIN_CONTENTS,
      payload: response.data.data,
    });
  };

  const onFail = (error) => {
    console.error("getHomeMainContents onFail", error);
  };

  TAxios(
    dispatch,
    getState,
    "get",
    URLS.GET_HOME_MAIN_CONTENTS,
    {},
    {},
    onSuccess,
    onFail
  );
};

// Theme 전시 정보 조회 : IF-LGSP-045
export const getThemeCurationInfo = () => (dispatch, getState) => {
  const onSuccess = (response) => {
    console.log("getThemeCurationInfo onSuccess", response.data);

    dispatch({
      type: types.GET_THEME_CURATION_INFO,
      payload: response.data.data,
    });
  };

  const onFail = (error) => {
    console.error("getThemeCurationInfo onFail", error);
  };

  TAxios(
    dispatch,
    getState,
    "get",
    URLS.GET_THEME_CURATION_INFO,
    {},
    {},
    onSuccess,
    onFail
  );
};
