import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _regeneratorRuntime from '@babel/runtime/regenerator';
import { useState, useCallback, useEffect } from 'react';
import getSuiteHeaderData, { calcRoutes, calcSurveyStatus, calcI18N, defaultFetchApi } from '../util/suiteHeaderData.js';

/**
 * @deprecated use useUiResources instead
 */
var useSuiteHeaderData = function useSuiteHeaderData(_ref) {
  var baseApiUrl = _ref.baseApiUrl,
    domain = _ref.domain,
    _ref$lang = _ref.lang,
    lang = _ref$lang === void 0 ? 'en' : _ref$lang,
    _ref$calculateRoutes = _ref.calculateRoutes,
    calculateRoutes = _ref$calculateRoutes === void 0 ? calcRoutes : _ref$calculateRoutes,
    _ref$calculateSurveyS = _ref.calculateSurveyStatus,
    calculateSurveyStatus = _ref$calculateSurveyS === void 0 ? calcSurveyStatus : _ref$calculateSurveyS,
    _ref$calculateI18N = _ref.calculateI18N,
    calculateI18N = _ref$calculateI18N === void 0 ? calcI18N : _ref$calculateI18N,
    _ref$fetchApi = _ref.fetchApi,
    fetchApi = _ref$fetchApi === void 0 ? defaultFetchApi : _ref$fetchApi,
    _ref$surveyConfig = _ref.surveyConfig,
    surveyConfig = _ref$surveyConfig === void 0 ? null : _ref$surveyConfig,
    _ref$isTest = _ref.isTest,
    isTest = _ref$isTest === void 0 ? false : _ref$isTest;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    isLoading = _useState2[0],
    setIsLoading = _useState2[1];
  var _useState3 = useState(),
    _useState4 = _slicedToArray(_useState3, 2),
    error = _useState4[0],
    setError = _useState4[1];
  var _useState5 = useState({
      username: null,
      userDisplayName: null,
      email: null,
      routes: {
        profile: null,
        navigator: null,
        admin: null,
        logout: null,
        about: null,
        documentation: null,
        whatsNew: null,
        requestEnhancement: null,
        support: null,
        gettingStarted: null,
        workspaceId: null,
        domain: null
      },
      applications: [],
      showSurvey: false
    }),
    _useState6 = _slicedToArray(_useState5, 2),
    data = _useState6[0],
    setData = _useState6[1];
  var refreshData = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var suiteHeaderData;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          _context.prev = 0;
          setIsLoading(true);
          _context.next = 4;
          return getSuiteHeaderData({
            baseApiUrl: baseApiUrl,
            domain: domain,
            lang: lang,
            calculateRoutes: calculateRoutes,
            calculateSurveyStatus: calculateSurveyStatus,
            calculateI18N: calculateI18N,
            fetchApi: fetchApi,
            surveyConfig: surveyConfig,
            isTest: isTest
          });
        case 4:
          suiteHeaderData = _context.sent;
          setData(suiteHeaderData);
          _context.next = 12;
          break;
        case 8:
          _context.prev = 8;
          _context.t0 = _context["catch"](0);
          setError(_context.t0);
          setIsLoading(false);
        case 12:
        case "end":
          return _context.stop();
      }
    }, _callee, null, [[0, 8]]);
  })), [baseApiUrl, domain, lang, isTest, setIsLoading]); // eslint-disable-line react-hooks/exhaustive-deps

  useEffect(function () {
    // load actual data
    refreshData();
  }, [refreshData]);
  return [data, isLoading, error, refreshData];
};
var useSuiteHeaderData$1 = useSuiteHeaderData;

export { useSuiteHeaderData$1 as default };
