import { createAsyncThunk } from "@reduxjs/toolkit";
import axios from "axios";
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
import { getRoleFromUrl } from "../../../utils/getRoleFromUrl";

export const slaughterEnterLoadInformationGetDashboard = createAsyncThunk(
  "PROVINCE_GET_LOAD_INFO_DASHBOARD",
  async (d, { dispatch }) => {
    try {
      dispatch(LOADING_START());
      const { data, status } = await axios.get(
        "dashboard_enter_load_information",
        {
          params: {
            date1: d.selectedDate1,
            date2: d.selectedDate2,
            role: getRoleFromUrl(),
            filter: "search",
            value: d.text ? d.text : "",
            role_key: d.role_key || "",
          },
        }
      );
      dispatch(LOADING_END());
      return { data, status };
    } catch (e) {
      dispatch(LOADING_END());
      return { error: e.response.data };
    }
  }
);
