import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { useQuery } from '@tanstack/react-query';
import { noop } from '@bigbinary/neeto-cist';
import { useMutationWithInvalidation } from '@bigbinary/neeto-commons-frontend/react-utils';
import axios from 'axios';
import { B as BASE_URL, Q as QUERY_KEYS } from './constants-CXdiW8NZ.js';

var fetch$1 = function fetch() {
  return axios.get("".concat(BASE_URL, "/global_roles"));
};
var globalRolesApi = {
  fetch: fetch$1
};

var fetch = function fetch() {
  return axios.get("".concat(BASE_URL, "/organization_roles"));
};
var create = function create(payload) {
  return axios.post("".concat(BASE_URL, "/organization_roles"), payload);
};
var update = function update(id, payload) {
  return axios.patch("".concat(BASE_URL, "/organization_roles/").concat(id), payload);
};
var destroy = function destroy(id, payload) {
  return axios["delete"]("".concat(BASE_URL, "/organization_roles/").concat(id), {
    data: payload
  });
};
var bulkUpdate = function bulkUpdate(payload) {
  return axios.patch("".concat(BASE_URL, "/organization_roles/bulk_update"), payload);
};
var organizationRolesApi = {
  bulkUpdate: bulkUpdate,
  create: create,
  destroy: destroy,
  fetch: fetch,
  update: update
};

var _excluded = ["onSuccess"],
  _excluded2 = ["onSuccess"],
  _excluded3 = ["onSuccess"],
  _excluded4 = ["onSuccess"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var useFetchRoles = function useFetchRoles() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  return useQuery(_objectSpread({
    queryKey: [QUERY_KEYS.ROLES],
    queryFn: organizationRolesApi.fetch,
    select: function select(response) {
      return response === null || response === void 0 ? void 0 : response.organizationRoles;
    }
  }, options));
};
var useFetchGlobalRoles = function useFetchGlobalRoles() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  return useQuery(_objectSpread({
    queryKey: [QUERY_KEYS.GLOBAL_ROLES],
    queryFn: globalRolesApi.fetch
  }, options));
};
var useCreateRole = function useCreateRole(_ref) {
  var _onSuccess = _ref.onSuccess,
    options = _objectWithoutProperties(_ref, _excluded);
  return useMutationWithInvalidation(organizationRolesApi.create, _objectSpread({
    keysToInvalidate: [[QUERY_KEYS.TEAMS_DEPENDENCIES], [QUERY_KEYS.ROLES]],
    onSuccess: function onSuccess() {
      _onSuccess === null || _onSuccess === void 0 || _onSuccess();
    }
  }, options));
};
var useUpdateRole = function useUpdateRole(_ref2) {
  var _onSuccess2 = _ref2.onSuccess,
    options = _objectWithoutProperties(_ref2, _excluded2);
  return useMutationWithInvalidation(function (_ref3) {
    var id = _ref3.id,
      payload = _ref3.payload;
    return organizationRolesApi.update(id, payload);
  }, _objectSpread({
    keysToInvalidate: [[QUERY_KEYS.TEAMS], [QUERY_KEYS.TEAMS_DEPENDENCIES], [QUERY_KEYS.ROLES]],
    onSuccess: function onSuccess() {
      _onSuccess2 === null || _onSuccess2 === void 0 || _onSuccess2();
    }
  }, options));
};
var useDestroyRole = function useDestroyRole(_ref4) {
  var _ref4$onSuccess = _ref4.onSuccess,
    _onSuccess3 = _ref4$onSuccess === void 0 ? noop : _ref4$onSuccess,
    options = _objectWithoutProperties(_ref4, _excluded3);
  return useMutationWithInvalidation(function (_ref5) {
    var id = _ref5.id,
      payload = _ref5.payload;
    return organizationRolesApi.destroy(id, payload);
  }, _objectSpread({
    keysToInvalidate: [[QUERY_KEYS.TEAMS], [QUERY_KEYS.TEAMS_DEPENDENCIES], [QUERY_KEYS.ROLES]],
    onSuccess: function onSuccess() {
      _onSuccess3 === null || _onSuccess3 === void 0 || _onSuccess3();
    }
  }, options));
};
var useBulkUpdateRoles = function useBulkUpdateRoles(_ref6) {
  var _onSuccess4 = _ref6.onSuccess,
    options = _objectWithoutProperties(_ref6, _excluded4);
  return useMutationWithInvalidation(organizationRolesApi.bulkUpdate, _objectSpread({
    keysToInvalidate: [[QUERY_KEYS.TEAMS], [QUERY_KEYS.TEAMS_DEPENDENCIES], [QUERY_KEYS.ROLES]],
    onSuccess: function onSuccess() {
      _onSuccess4 === null || _onSuccess4 === void 0 || _onSuccess4();
    }
  }, options));
};

export { useFetchGlobalRoles as a, useCreateRole as b, useUpdateRole as c, useDestroyRole as d, useBulkUpdateRoles as e, useFetchRoles as u };
//# sourceMappingURL=useRolesApi-93OoRU1s.js.map
