function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

import React, { useEffect, useState } from 'react';
import { initRunItSdk, RunItProvider } from '@looker/run-it';
import { OAuthScene } from '@looker/extension-utils';
import { Provider } from 'react-redux';
import { useLocation } from 'react-router';
import { ApiExplorer } from './ApiExplorer';
import { store } from './state';
import { oAuthPath, ApixAdaptor } from './utils';
import { Loader } from './components';
export var StandaloneApiExplorer = _ref => {
  var {
    headless = false
  } = _ref;
  var [browserAdaptor] = useState(new ApixAdaptor(initRunItSdk(), window.origin));
  var location = useLocation();
  var oauthReturn = location.pathname === "/".concat(oAuthPath);
  var sdk = browserAdaptor.sdk;
  var canLogin = sdk.authSession.settings.authIsConfigured() && !sdk.authSession.isAuthenticated() && !oauthReturn;
  useEffect(() => {
    var login = function () {
      var _ref2 = _asyncToGenerator(function* () {
        return yield browserAdaptor.login();
      });

      return function login() {
        return _ref2.apply(this, arguments);
      };
    }();

    if (canLogin) {
      login();
    }
  }, []);
  var {
    looker_url
  } = sdk.authSession.settings.getStoredConfig();
  return React.createElement(Provider, {
    store: store
  }, React.createElement(RunItProvider, {
    basePath: "/api/4.0"
  }, canLogin ? React.createElement(Loader, {
    themeOverrides: browserAdaptor.themeOverrides(),
    message: "Configuration found. Logging into ".concat(looker_url)
  }) : React.createElement(React.Fragment, null, oauthReturn ? React.createElement(OAuthScene, {
    adaptor: browserAdaptor
  }) : React.createElement(ApiExplorer, {
    adaptor: browserAdaptor,
    headless: headless
  }))));
};
//# sourceMappingURL=StandaloneApiExplorer.js.map