"use strict";
const api = require("./api-BygscvSz.js");
const common = require("./common-B47boGYI.js");
const toolkit = require("@reduxjs/toolkit");
const _ = require("lodash");
const createParties = toolkit.createAsyncThunk(
  "parties/create",
  async (payload) => {
    const response = await api.postV1Parties({
      ...payload,
      ...common.getToken()
    });
    return response;
  }
);
const getOptions = async (apiFunc, filters, dataKey, labelKey, valueKey) => {
  var _a, _b;
  const response = await apiFunc({
    ...filters,
    ...common.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 = toolkit.createAsyncThunk(
  "location/fetch",
  async (filter) => {
    const locationFilter = {
      ...filter
    };
    const response = await getOptions(
      api.getV1WarehouseLocation,
      locationFilter,
      "warehouseLocationList",
      "name"
    );
    return response;
  }
);
const getItems = toolkit.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(
    api.getV1InventoryItems,
    itemFilter,
    "inventoryItemsList",
    "name"
  );
  return response;
});
const getCurrency = toolkit.createAsyncThunk(
  "currency/fetch",
  async (filter) => {
    const currencyFiter = {
      ...filter
    };
    const response = await getOptions(
      api.getV1Currency,
      currencyFiter,
      "currencies",
      "currency_name"
    );
    return response;
  }
);
exports.createParties = createParties;
exports.getCurrency = getCurrency;
exports.getItems = getItems;
exports.getLocation = getLocation;
exports.getOptions = getOptions;
//# sourceMappingURL=actionCreator-Dyrn7xiX.js.map
