import axios from "axios";
import { dispatch } from "../store/index";
import { filterProductsSuccess, hasError } from "store/reducers/product";

export function filterProducts(filter) {
  console.log("filter", filter);

  return async () => {
    try {
      // const response = await axios.post("/api/products/filter",
      const response = await axios.post(
        "https://mock-data-api-nextjs.vercel.app/api/products/filter",
        { filter }
      );
      dispatch(filterProductsSuccess(response.data));
    } catch (error) {
      dispatch(hasError(error));
    }
  };
}
