"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _react = require("react");
var _linkClientExtension = require("@atlaskit/link-client-extension");
var _linkProvider = require("@atlaskit/link-provider");
var useInvoke = function useInvoke() {
  var _useSmartLinkContext = (0, _linkProvider.useSmartLinkContext)(),
    connections = _useSmartLinkContext.connections;
  var clientExt = (0, _linkClientExtension.useSmartLinkClientExtension)(connections.client);
  return (0, _react.useCallback)( /*#__PURE__*/function () {
    var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(req, cb) {
      var response;
      return _regenerator.default.wrap(function (_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            _context.next = 1;
            return clientExt.invoke(req);
          case 1:
            response = _context.sent;
            return _context.abrupt("return", cb ? cb(response) : response);
          case 2:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return function (_x, _x2) {
      return _ref.apply(this, arguments);
    };
  }(), [clientExt]);
};
var _default = exports.default = useInvoke;