import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { useCallback } from 'react';
import { useSmartLinkClientExtension } from '@atlaskit/link-client-extension';
import { useSmartLinkContext } from '@atlaskit/link-provider';
var useInvoke = function useInvoke() {
  var _useSmartLinkContext = useSmartLinkContext(),
    connections = _useSmartLinkContext.connections;
  var clientExt = useSmartLinkClientExtension(connections.client);
  return useCallback( /*#__PURE__*/function () {
    var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(req, cb) {
      var response;
      return _regeneratorRuntime.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]);
};
export default useInvoke;