import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import { useQuery } from '@tanstack/react-query';
import { useMutationWithInvalidation } from '@bigbinary/neeto-commons-frontend/react-utils';
import { prop } from 'ramda';
import axios from 'axios';
import { B as BASE_URL, Q as QUERY_KEYS } from './constants-CXdiW8NZ.js';

var list$1 = function list(params) {
  return axios.get("".concat(BASE_URL, "/api/v1/groups"), {
    params: params
  });
};
var show = function show(id) {
  return axios.get("".concat(BASE_URL, "/api/v1/groups/").concat(id));
};
var create = function create(payload) {
  return axios.post("".concat(BASE_URL, "/api/v1/groups"), payload);
};
var update = function update(id, payload) {
  return axios.patch("".concat(BASE_URL, "/api/v1/groups/").concat(id), payload);
};
var destroy = function destroy(id) {
  return axios["delete"]("".concat(BASE_URL, "/api/v1/groups/").concat(id));
};
var groupsApi = {
  create: create,
  list: list$1,
  update: update,
  show: show,
  destroy: destroy
};

var useFetchGroups = function useFetchGroups(_ref) {
  var page = _ref.page,
    pageSize = _ref.pageSize,
    _ref$searchTerm = _ref.searchTerm,
    searchTerm = _ref$searchTerm === void 0 ? "" : _ref$searchTerm;
  return useQuery({
    queryKey: [QUERY_KEYS.GROUPS, searchTerm, page, pageSize],
    queryFn: function queryFn() {
      return groupsApi.list({
        searchTerm: searchTerm,
        page: page,
        pageSize: pageSize,
        loadDetails: true
      });
    }
  });
};
var useCreateGroup = function useCreateGroup() {
  var _config$form$otherKey, _config$form;
  var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  return useMutationWithInvalidation(function (payload) {
    return groupsApi.create(payload);
  }, {
    keysToInvalidate: [[QUERY_KEYS.GROUPS]].concat(_toConsumableArray((_config$form$otherKey = config === null || config === void 0 || (_config$form = config.form) === null || _config$form === void 0 ? void 0 : _config$form.otherKeysToInvalidate) !== null && _config$form$otherKey !== void 0 ? _config$form$otherKey : []))
  });
};
var useDeleteGroup = function useDeleteGroup() {
  var _config$form$otherKey2, _config$form2;
  var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  return useMutationWithInvalidation(function (id) {
    return groupsApi.destroy(id);
  }, {
    keysToInvalidate: [[QUERY_KEYS.GROUPS]].concat(_toConsumableArray((_config$form$otherKey2 = config === null || config === void 0 || (_config$form2 = config.form) === null || _config$form2 === void 0 ? void 0 : _config$form2.otherKeysToInvalidate) !== null && _config$form$otherKey2 !== void 0 ? _config$form$otherKey2 : []))
  });
};
var useFetchGroup = function useFetchGroup(id) {
  return useQuery({
    queryKey: [QUERY_KEYS.GROUPS, id],
    queryFn: function queryFn() {
      return groupsApi.show(id);
    },
    select: prop("group"),
    enabled: !!id
  });
};
var useUpdateGroup = function useUpdateGroup() {
  var _config$form$otherKey3, _config$form3;
  var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  return useMutationWithInvalidation(function (_ref2) {
    var id = _ref2.id,
      payload = _ref2.payload;
    return groupsApi.update(id, payload);
  }, {
    keysToInvalidate: [[QUERY_KEYS.GROUPS]].concat(_toConsumableArray((_config$form$otherKey3 = config === null || config === void 0 || (_config$form3 = config.form) === null || _config$form3 === void 0 ? void 0 : _config$form3.otherKeysToInvalidate) !== null && _config$form$otherKey3 !== void 0 ? _config$form$otherKey3 : []))
  });
};

var list = function list() {
  return axios.get("".concat(BASE_URL, "/api/v1/users"));
};
var usersApi = {
  list: list
};

var useFetchUsers = function useFetchUsers() {
  return useQuery({
    queryKey: [QUERY_KEYS.USERS],
    queryFn: usersApi.list
  });
};

export { useCreateGroup as a, useUpdateGroup as b, useFetchGroup as c, useDeleteGroup as d, useFetchGroups as e, useFetchUsers as u };
//# sourceMappingURL=useUsersApi-BRPy1kqa.js.map
