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

export const provinceDispenserWithInGetDashboard = createAsyncThunk(
  "PROVINCE_DISPENSER_SALE_WITHIN_DASHBOARD",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get(
      `in-province-allocation-dashboard/?type=KillHouse`,
      {
        params: {
          date1: d.selectedDate1,
          date2: d.selectedDate2,
          role: getRoleFromUrl(),
          kill_house_key: d.kill_house_key || "all",
          trash: d.trash,
          return_trash: d.return_trash,
        },
      }
    );
    dispatch(LOADING_END());
    return { data, status };
  }
);
