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

// 서브카테고리 조회 IF-LGSP-051
let getSubCategoryKey = null;
export const getSubCategory = (params, key) => (dispatch, getState) => {
  const { lgCatCd, patnrIdList, tabType, pageSize, pageNo, filterType } =
    params;
  const maxResults = CATEGORY_DATA_MAX_RESULTS_LIMIT;

  let currentKey = key;
  const onSuccess = (response) => {
    console.log("getSubCategory onSuccess ", response.data);

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

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

  TAxios(
    dispatch,
    getState,
    "get",
    URLS.GET_SUB_CATEGORY,
    { lgCatCd, patnrIdList, tabType, filterType },
    {},
    onSuccess,
    onFail
  );
};

// TOP20 영상 목록 조회 IF-LGSP-069
export const getTop20Show = () => (dispatch, getState) => {
  const onSuccess = (response) => {
    console.log("getTop20Show onSuccess ", response.data);

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

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

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