import { p as postV1Parties, n as getV1WarehouseLocation, o as getV1Currency, q as getV1InventoryItems } from "./api-BQ_tS-9F.esm.js";
import { at as getToken } from "./common-B0qL-cCR.esm.js";
import { createAsyncThunk } from "@reduxjs/toolkit";
import _ from "lodash";
const createParties = createAsyncThunk(
  "parties/create",
  async (payload) => {
    const response = await postV1Parties({
      ...payload,
      ...getToken()
    });
    return response;
  }
);
const getOptions = async (apiFunc, filters, dataKey, labelKey, valueKey) => {
  var _a, _b;
  const response = await apiFunc({
    ...filters,
    ...getToken()
  });
  const options = ((_b = (_a = response == null ? void 0 : response.data) == null ? void 0 : _a[dataKey]) == null ? void 0 : _b.map((d) => ({
    ...d,
    label: labelKey instanceof Function ? labelKey(d) : _.get(d, labelKey),
    value: valueKey ? _.get(d, valueKey, d.id) : d.id
  }))) || [];
  return options;
};
const getLocation = createAsyncThunk(
  "location/fetch",
  async (filter) => {
    const locationFilter = {
      ...filter
    };
    const response = await getOptions(
      getV1WarehouseLocation,
      locationFilter,
      "warehouseLocationList",
      "name"
    );
    return response;
  }
);
const getItems = createAsyncThunk("item/fetch", async (filter) => {
  const itemFilter = {
    ...filter,
    order: "name:1"
    // select:"[id,name,type,unit_of_measurement,default_tax_id,vendor_informatio]"
  };
  const response = await getOptions(
    getV1InventoryItems,
    itemFilter,
    "inventoryItemsList",
    "name"
  );
  return response;
});
const getCurrency = createAsyncThunk(
  "currency/fetch",
  async (filter) => {
    const currencyFiter = {
      ...filter
    };
    const response = await getOptions(
      getV1Currency,
      currencyFiter,
      "currencies",
      "currency_name"
    );
    return response;
  }
);
export {
  getItems as a,
  getLocation as b,
  createParties as c,
  getOptions as d,
  getCurrency as g
};
//# sourceMappingURL=actionCreator-CVpuMig1.esm.js.map
