'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var reactQuery = require('@tanstack/react-query');
var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
var axios = require('axios');
var constants = require('./constants-D_H6M1Pm.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var axios__default = /*#__PURE__*/_interopDefault(axios);

var fetch = function fetch() {
  return axios__default.default.get("".concat(constants.BASE_URL, "/api/v1/invite_links"));
};
var create = function create(payload) {
  return axios__default.default.post("".concat(constants.BASE_URL, "/api/v1/invite_links"), {
    inviteLink: payload
  });
};
var regenerate = function regenerate(inviteLinkId, payload) {
  return axios__default.default.put("".concat(constants.BASE_URL, "/api/v1/invite_links/").concat(inviteLinkId), {
    inviteLink: payload
  });
};
var inviteLinksApi = {
  fetch: fetch,
  create: create,
  regenerate: regenerate
};

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__default.default(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 useFetchInviteLinks = function useFetchInviteLinks() {
  return reactQuery.useQuery({
    queryKey: [constants.QUERY_KEYS.INVITATION_LINK],
    queryFn: function queryFn() {
      return inviteLinksApi.fetch();
    }
  });
};
var useCreateInviteLinks = function useCreateInviteLinks() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  return reactUtils.useMutationWithInvalidation(function (payload) {
    return inviteLinksApi.create(payload);
  }, _objectSpread({
    keysToInvalidate: [[constants.QUERY_KEYS.INVITATION_LINK]]
  }, options));
};
var useRegenerateInviteLink = function useRegenerateInviteLink() {
  return reactUtils.useMutationWithInvalidation(function (_ref) {
    var inviteLinkId = _ref.inviteLinkId,
      payload = _ref.payload;
    return inviteLinksApi.regenerate(inviteLinkId, payload);
  }, {
    keysToInvalidate: [[constants.QUERY_KEYS.INVITATION_LINK]]
  });
};

exports.useCreateInviteLinks = useCreateInviteLinks;
exports.useFetchInviteLinks = useFetchInviteLinks;
exports.useRegenerateInviteLink = useRegenerateInviteLink;
//# sourceMappingURL=useInviteLinksApi-COVfmZiQ.js.map
