import _extends from '@babel/runtime/helpers/extends';
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
import cloneDeep from '../../node_modules/lodash-es/cloneDeep.js';
import set from '../../node_modules/lodash-es/set.js';
import get from '../../node_modules/lodash-es/get.js';
import _regeneratorRuntime from '@babel/runtime/regenerator';
import 'core-js/modules/es.symbol.js';
import 'core-js/modules/es.array.concat.js';
import 'core-js/modules/es.array.filter.js';
import 'core-js/modules/es.array.find.js';
import 'core-js/modules/es.array.iterator.js';
import 'core-js/modules/es.array.join.js';
import 'core-js/modules/es.array.map.js';
import 'core-js/modules/es.function.name.js';
import 'core-js/modules/es.object.entries.js';
import 'core-js/modules/es.object.get-own-property-descriptor.js';
import 'core-js/modules/es.object.get-own-property-descriptors.js';
import 'core-js/modules/es.object.keys.js';
import 'core-js/modules/es.object.to-string.js';
import 'core-js/modules/es.promise.js';
import 'core-js/modules/es.regexp.exec.js';
import 'core-js/modules/es.string.iterator.js';
import 'core-js/modules/es.string.replace.js';
import 'core-js/modules/web.dom-collections.for-each.js';
import 'core-js/modules/web.dom-collections.iterator.js';
import 'core-js/modules/web.url.js';
import 'core-js/modules/web.url.to-json.js';
import 'core-js/modules/web.url-search-params.js';
import React__default, { useState, useCallback, useRef, useEffect } from 'react';
import PropTypes from 'prop-types';
import { ActionableNotification, Link, HeaderContainer, SkeletonText, ButtonSkeleton } from '@carbon/react';
import classnames from 'classnames';
import SideNav, { SideNavPropTypes } from '../SideNav/SideNav.js';
import Header from '../Header/Header.js';
import { HeaderActionItemPropTypes, ChildContentPropTypes } from '../Header/HeaderPropTypes.js';
import { settings } from '../../constants/Settings.js';
import Walkme from '../Walkme/Walkme.js';
import SuiteHeaderProfile from './SuiteHeaderProfile/SuiteHeaderProfile.js';
import SuiteHeaderAppSwitcher from './SuiteHeaderAppSwitcher/SuiteHeaderAppSwitcher.js';
import SuiteHeaderAppSwitcherLoading from './SuiteHeaderAppSwitcher/SuiteHeaderAppSwitcherLoading.js';
import MultiWorkspaceSuiteHeaderAppSwitcher from './SuiteHeaderAppSwitcher/MultiWorkspaceSuiteHeaderAppSwitcher.js';
import SuiteHeaderLogoutModal from './SuiteHeaderLogoutModal/SuiteHeaderLogoutModal.js';
import IdleLogoutConfirmationModal, { IdleLogoutConfirmationModalIdleTimeoutPropTypes } from './IdleLogoutConfirmationModal/IdleLogoutConfirmationModal.js';
import SuiteHeaderI18N from './i18n/index.js';
import { shouldOpenInNewWindow } from './suiteHeaderUtils.js';
import { SuiteHeaderRoutePropTypes, SuiteHeaderApplicationPropTypes, SuiteHeaderWorkspacePropTypes, SuiteHeaderSurveyDataPropTypes, SuiteHeaderI18NPropTypes } from './SuiteHeaderPropTypes.js';
import { SUITE_HEADER_ROUTE_TYPES } from './suiteHeaderConstants.js';
import { Settings, Help, UserAvatar } from '@carbon/icons-react';

var _excluded = ["className", "suiteName", "appName", "extraContent", "userDisplayName", "username", "hasSideNav", "isAdminView", "routes", "applications", "workspaces", "globalApplications", "sideNavProps", "surveyData", "idleTimeoutData", "onStayLoggedIn", "onSideNavToggled", "onRouteChange", "i18n", "customActionItems", "customHelpLinks", "customProfileLinks", "customApplications", "walkmePath", "walkmeLang", "testId", "handleHeaderNameClick", "hideMenuButton", "closeSideNavOnNavigation"];
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), !0).forEach(function (r) { _defineProperty(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 defaultProps = {
  className: null,
  appName: null,
  extraContent: null,
  userDisplayName: null,
  username: null,
  isAdminView: false,
  hasSideNav: false,
  routes: null,
  applications: null,
  workspaces: null,
  globalApplications: [],
  sideNavProps: null,
  surveyData: null,
  idleTimeoutData: null,
  onStayLoggedIn: function onStayLoggedIn() {},
  onSideNavToggled: function () {
    var _onSideNavToggled = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
      return _regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", Promise.resolve(true));
          case 1:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    function onSideNavToggled() {
      return _onSideNavToggled.apply(this, arguments);
    }
    return onSideNavToggled;
  }(),
  onRouteChange: function () {
    var _onRouteChange = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
      return _regeneratorRuntime.wrap(function _callee2$(_context2) {
        while (1) switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", Promise.resolve(true));
          case 1:
          case "end":
            return _context2.stop();
        }
      }, _callee2);
    }));
    function onRouteChange() {
      return _onRouteChange.apply(this, arguments);
    }
    return onRouteChange;
  }(),
  i18n: SuiteHeaderI18N.en,
  customActionItems: [],
  customHelpLinks: [],
  customProfileLinks: [],
  customApplications: [],
  walkmePath: null,
  walkmeLang: 'en',
  testId: 'suite-header',
  isActionItemVisible: function isActionItemVisible() {
    return true;
  },
  handleHeaderNameClick: null,
  hideMenuButton: false,
  closeSideNavOnNavigation: false
};
var propTypes = {
  /** Add class name to the rendered Header component */
  className: PropTypes.string,
  /** Name of suite (maps to appName in Header) */
  suiteName: PropTypes.string.isRequired,
  /** Application name in suite (maps to subtitle in Header) */
  appName: PropTypes.string,
  /** Extra content (a Tag, for example) */
  extraContent: PropTypes.element,
  /** Display name of current user */
  userDisplayName: PropTypes.string,
  /** Username of current user */
  username: PropTypes.string,
  /** If true, renders the admin button in Header as selected */
  isAdminView: PropTypes.bool,
  /** If true, will render the hamburger icon even if no sideNavProps are provided */
  hasSideNav: PropTypes.bool,
  /** URLs for various routes on Header buttons and submenus */
  routes: PropTypes.shape(SuiteHeaderRoutePropTypes),
  /** Applications to render in AppSwitcher (not used anymore, only kept here for backwards compatibility) */
  applications: PropTypes.arrayOf(PropTypes.shape(SuiteHeaderApplicationPropTypes)),
  /** Workspaces and applications to render in AppSwitcher */
  workspaces: PropTypes.arrayOf(PropTypes.shape(SuiteHeaderWorkspacePropTypes)),
  /** Applications that are not tied to workspaces */
  globalApplications: PropTypes.arrayOf(PropTypes.shape(SuiteHeaderApplicationPropTypes)),
  /** side navigation component */
  sideNavProps: PropTypes.shape(SideNavPropTypes),
  /** If surveyData is present, show an ActionableNotification */
  surveyData: PropTypes.shape(SuiteHeaderSurveyDataPropTypes),
  /** If idleTimeoutData is present, instantiate IdleLogoutConfirmationModal */
  idleTimeoutData: PropTypes.shape(IdleLogoutConfirmationModalIdleTimeoutPropTypes),
  /** Function called when idle timer is restarted */
  onStayLoggedIn: PropTypes.func,
  /** Function called when side nav button is toggled */
  onSideNavToggled: PropTypes.func,
  /** Function called before any route change. Returns a Promise<Boolean>. False means the redirect will not happen. This function should never throw an error. */
  onRouteChange: PropTypes.func,
  /** I18N strings */
  i18n: PropTypes.shape(SuiteHeaderI18NPropTypes),
  /** Array of custom header action items */
  customActionItems: PropTypes.arrayOf(PropTypes.shape(HeaderActionItemPropTypes)),
  /** Array of custom help menu links */
  customHelpLinks: PropTypes.arrayOf(PropTypes.shape(ChildContentPropTypes)),
  /** Array of custom profile menu links */
  customProfileLinks: PropTypes.arrayOf(PropTypes.shape(ChildContentPropTypes)),
  /** Array of custom applications */
  customApplications: PropTypes.arrayOf(PropTypes.shape(SuiteHeaderApplicationPropTypes)),
  /** Path to Walkme entry point */
  walkmePath: PropTypes.string,
  /** Walkme language code */
  walkmeLang: PropTypes.string,
  testId: PropTypes.string,
  /** Optional callback when user clicks on header name */
  handleHeaderNameClick: PropTypes.oneOfType([PropTypes.func, PropTypes.any]),
  /** a function that will be passed the actionItem object and returns a boolean to determine if that item should be shown */
  // eslint-disable-next-line react/forbid-foreign-prop-types
  isActionItemVisible: Header.propTypes.isActionItemVisible,
  /** Force menu button to hide regardless of side nav props */
  hideMenuButton: PropTypes.bool,
  /** Force side nav to close upon item click */
  closeSideNavOnNavigation: PropTypes.bool
};
var SuiteHeader = function SuiteHeader(_ref) {
  var _currentWorkspace$app, _currentWorkspace$app2, _applications$find;
  var className = _ref.className,
    suiteName = _ref.suiteName,
    appName = _ref.appName,
    extraContent = _ref.extraContent,
    userDisplayName = _ref.userDisplayName,
    username = _ref.username,
    hasSideNav = _ref.hasSideNav,
    isAdminView = _ref.isAdminView,
    routes = _ref.routes,
    applications = _ref.applications,
    workspaces = _ref.workspaces,
    globalApplications = _ref.globalApplications,
    sideNavProps = _ref.sideNavProps,
    surveyData = _ref.surveyData,
    idleTimeoutData = _ref.idleTimeoutData,
    onStayLoggedIn = _ref.onStayLoggedIn,
    onSideNavToggled = _ref.onSideNavToggled,
    onRouteChange = _ref.onRouteChange,
    i18n = _ref.i18n,
    customActionItems = _ref.customActionItems,
    customHelpLinks = _ref.customHelpLinks,
    customProfileLinks = _ref.customProfileLinks,
    customApplications = _ref.customApplications,
    walkmePath = _ref.walkmePath,
    walkmeLang = _ref.walkmeLang,
    testId = _ref.testId,
    handleHeaderNameClickProps = _ref.handleHeaderNameClick,
    hideMenuButton = _ref.hideMenuButton,
    closeSideNavOnNavigation = _ref.closeSideNavOnNavigation,
    otherHeaderProps = _objectWithoutProperties(_ref, _excluded);
  var mergedI18N = _objectSpread(_objectSpread({}, defaultProps.i18n), i18n);
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    showLogoutModal = _useState2[0],
    setShowLogoutModal = _useState2[1];
  var _useState3 = useState(surveyData !== null && surveyData !== undefined),
    _useState4 = _slicedToArray(_useState3, 2),
    showToast = _useState4[0],
    setShowToast = _useState4[1];
  var translate = useCallback(function (string, substitutions) {
    return substitutions.reduce(function (acc, _ref2) {
      var _ref3 = _slicedToArray(_ref2, 2),
        key = _ref3[0],
        val = _ref3[1];
      return acc.replace(key, val);
    }, string);
  }, []);
  var sideNavExpandedRef = useRef();
  // Make sure that the survey toast notification is displayed if surveyData is passed in future rerenders
  // not only at mount time
  useEffect(function () {
    if (surveyData !== null && surveyData !== undefined) {
      setShowToast(true);
    }
  }, [surveyData]);

  // Function to include close side nav functionality to items when they are clicked
  var setOnClickDecorators = useCallback(function (sNavProps, onClickSideNavExpand) {
    var clickableItems = [];
    var recursivelyGetClickableItems = function recursivelyGetClickableItems(propValue, parentProp) {
      var _propValue$childConte;
      if (!parentProp) {
        // Get links and recentLinks
        Object.entries(propValue).forEach(function (_ref4) {
          var _ref5 = _slicedToArray(_ref4, 2),
            k = _ref5[0],
            v = _ref5[1];
          if (k === 'links' || k === 'recentLinks') {
            recursivelyGetClickableItems(v, k);
          }
        });
      } else if (Array.isArray(propValue)) {
        // If the propValue is an array, check its items
        propValue.forEach(function (i, idx) {
          return recursivelyGetClickableItems(i, "".concat(parentProp, "[").concat(idx, "]"));
        });
      } else if (((_propValue$childConte = propValue === null || propValue === void 0 ? void 0 : propValue.childContent) !== null && _propValue$childConte !== void 0 ? _propValue$childConte : []).length > 0) {
        // If the propValue contains childContent, check each one of them
        recursivelyGetClickableItems(propValue.childContent, "".concat(parentProp, ".childContent"));
      } else if (propValue !== null && propValue !== void 0 && propValue.metaData) {
        // If propValue doesn't contain children and it has metaData, add it to the clickableItems array
        clickableItems.push("".concat(parentProp, ".metaData"));
      }
    };
    recursivelyGetClickableItems(sNavProps);

    // Clone side nav props object
    var cloned = cloneDeep(sNavProps);
    clickableItems.forEach(function (i) {
      var item = get(cloned, i);
      // Change onClick function to add onClickSideNavExpand call
      set(cloned, i, _objectSpread(_objectSpread({}, item), {}, {
        onClick: function onClick() {
          if (item.onClick) {
            item.onClick.apply(item, arguments);
          }
          if (sideNavExpandedRef.current) {
            // Only allow toggling off the side nav expanded state
            onClickSideNavExpand.apply(void 0, arguments);
          }
        }
      }));
    });
    return cloned;
  }, []);
  var isMultiWorkspace = (workspaces === null || workspaces === void 0 ? void 0 : workspaces.length) > 0;
  var currentWorkspace = workspaces === null || workspaces === void 0 ? void 0 : workspaces.find(function (wo) {
    return wo.isCurrent;
  });
  var appId = (_currentWorkspace$app = currentWorkspace === null || currentWorkspace === void 0 || (_currentWorkspace$app2 = currentWorkspace.applications) === null || _currentWorkspace$app2 === void 0 || (_currentWorkspace$app2 = _currentWorkspace$app2.find(function (a) {
    return a.isCurrent;
  })) === null || _currentWorkspace$app2 === void 0 ? void 0 : _currentWorkspace$app2.id) !== null && _currentWorkspace$app !== void 0 ? _currentWorkspace$app : applications === null || applications === void 0 || (_applications$find = applications.find(function (a) {
    return a.isCurrent;
  })) === null || _applications$find === void 0 ? void 0 : _applications$find.id;
  // Include the current workspace label only if we are not in an admin page and multi workspace is supported and more than one workspace is available
  var currentWorkspaceComponent = !isAdminView && isMultiWorkspace && (workspaces === null || workspaces === void 0 ? void 0 : workspaces.length) > 1 && currentWorkspace ? /*#__PURE__*/React__default.createElement("span", {
    "data-testid": "".concat(testId, "--current-workspace")
  }, currentWorkspace.name) : null;
  var appNameComponent = appName ? /*#__PURE__*/React__default.createElement("span", {
    "data-testid": "".concat(testId, "--appName"),
    className: classnames(_defineProperty({}, "".concat(settings.iotPrefix, "--suite-header-subtitle-appname"), !!currentWorkspaceComponent))
  }, appName) : null;
  var extraContentComponent = extraContent ? /*#__PURE__*/React__default.createElement("span", {
    className: "".concat(settings.iotPrefix, "--suite-header-subtitle")
  }, extraContent) : null;
  var navigatorRoute = (currentWorkspace === null || currentWorkspace === void 0 ? void 0 : currentWorkspace.href) || (routes === null || routes === void 0 ? void 0 : routes.navigator) || 'javascript:void(0)';
  var adminRoute = (routes === null || routes === void 0 ? void 0 : routes.admin) || 'javascript:void(0)';
  // Append originHref query parameter (and, optionally, originIsAdmin, originWorkspaceId and originAppId) to the logout route
  var logoutRoute = routes === null || routes === void 0 ? void 0 : routes.logout;
  try {
    var url = new URL(routes.logout);
    if (window.location.href) {
      url.searchParams.append('originHref', [window.location.protocol, '//', window.location.host, window.location.pathname].join(''));
    }
    if (appId) {
      url.searchParams.append('originAppId', appId);
    }
    if (currentWorkspace !== null && currentWorkspace !== void 0 && currentWorkspace.id) {
      url.searchParams.append('originWorkspaceId', currentWorkspace.id);
    }
    if (isAdminView) {
      url.searchParams.append('originIsAdmin', isAdminView);
    }
    logoutRoute = url.href;
  } catch (e) {
    logoutRoute = routes === null || routes === void 0 ? void 0 : routes.logout;
  }

  // If there are custom help links, include an extra child content entry for the separator
  var mergedCustomHelpLinks = customHelpLinks.length > 0 ? [].concat(_toConsumableArray(customHelpLinks), [{
    metaData: {
      className: "".concat(settings.iotPrefix, "--suite-header-help--separator"),
      element: 'div'
    },
    content: ''
  }]) : [];
  var handleOnClick = function handleOnClick(routeType, href, isExternal) {
    return /*#__PURE__*/function () {
      var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(e) {
        var newWindow, result;
        return _regeneratorRuntime.wrap(function _callee3$(_context3) {
          while (1) switch (_context3.prev = _context3.next) {
            case 0:
              e.preventDefault();
              newWindow = isExternal ? true : shouldOpenInNewWindow(e);
              _context3.next = 4;
              return onRouteChange(routeType, href);
            case 4:
              result = _context3.sent;
              if (result) {
                if (newWindow) {
                  window.open(href, '_blank', 'noopener noreferrer');
                } else {
                  window.location.href = href;
                }
              }
            case 6:
            case "end":
              return _context3.stop();
          }
        }, _callee3);
      }));
      return function (_x) {
        return _ref6.apply(this, arguments);
      };
    }();
  };
  var handleHeaderNameClick = useCallback(function (evt) {
    if (handleHeaderNameClickProps) {
      handleHeaderNameClickProps(evt, navigatorRoute);
    }
  }, [handleHeaderNameClickProps, navigatorRoute]);
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, walkmePath ? /*#__PURE__*/React__default.createElement(Walkme, {
    path: walkmePath,
    lang: walkmeLang
  }) : null, showToast && surveyData ? /*#__PURE__*/React__default.createElement(ActionableNotification, {
    "data-testid": "".concat(testId, "-notification"),
    className: "".concat(settings.iotPrefix, "--suite-header-survey-toast"),
    kind: "info",
    title: typeof mergedI18N.surveyTitle === 'function' ? mergedI18N.surveyTitle(appName || suiteName) : translate(mergedI18N.surveyTitle, [['{solutionName}', appName || suiteName]]),
    lowContrast: true,
    caption: "",
    onCloseButtonClick: function onCloseButtonClick() {
      return setShowToast(false);
    }
  }, /*#__PURE__*/React__default.createElement(Link, {
    href: surveyData.surveyLink,
    rel: "noopener noreferrer",
    onClick: handleOnClick(SUITE_HEADER_ROUTE_TYPES.SURVEY, surveyData.surveyLink, true)
  }, mergedI18N.surveyText), /*#__PURE__*/React__default.createElement("div", {
    className: "".concat(settings.iotPrefix, "--suite-header-survey-policy-link")
  }, /*#__PURE__*/React__default.createElement(Link, {
    href: surveyData.privacyLink,
    rel: "noopener noreferrer",
    onClick: handleOnClick(SUITE_HEADER_ROUTE_TYPES.SURVEY, surveyData.privacyLink, true)
  }, mergedI18N.surveyPrivacyPolicy))) : null, idleTimeoutData && (routes === null || routes === void 0 ? void 0 : routes.domain) !== null && (routes === null || routes === void 0 ? void 0 : routes.domain) !== undefined ? /*#__PURE__*/React__default.createElement(IdleLogoutConfirmationModal, {
    isAdminView: isAdminView,
    appId: appId,
    workspaceId: currentWorkspace === null || currentWorkspace === void 0 ? void 0 : currentWorkspace.id,
    idleTimeoutData: idleTimeoutData,
    routes: routes,
    onRouteChange: onRouteChange,
    onStayLoggedIn: onStayLoggedIn,
    i18n: i18n
  }) : null, /*#__PURE__*/React__default.createElement(SuiteHeaderLogoutModal, {
    isOpen: showLogoutModal,
    onClose: function onClose() {
      return setShowLogoutModal(false);
    },
    onLogout: handleOnClick(SUITE_HEADER_ROUTE_TYPES.LOGOUT, logoutRoute),
    i18n: {
      heading: mergedI18N.profileLogoutModalHeading,
      primaryButton: mergedI18N.profileLogoutModalPrimaryButton,
      secondaryButton: mergedI18N.profileLogoutModalSecondaryButton,
      body: typeof mergedI18N.profileLogoutModalBody === 'function' ? mergedI18N.profileLogoutModalBody(appName || suiteName, userDisplayName) : translate(mergedI18N.profileLogoutModalBody, [['{solutionName}', appName || suiteName], ['{userName}', userDisplayName]])
    },
    testId: "".concat(testId, "-logout-modal")
  }), routes && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("span", {
    className: "".concat(settings.iotPrefix, "--suite-header-data"),
    "data-type": "workspaceId"
  }, routes.workspaceId), /*#__PURE__*/React__default.createElement("span", {
    className: "".concat(settings.iotPrefix, "--suite-header-data"),
    "data-type": "domain"
  }, routes.domain)), /*#__PURE__*/React__default.createElement(HeaderContainer, {
    render: function render(_ref7) {
      var isSideNavExpanded = _ref7.isSideNavExpanded,
        _onClickSideNavExpand = _ref7.onClickSideNavExpand;
      sideNavExpandedRef.current = isSideNavExpanded;
      return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Header, _extends({
        testId: testId,
        className: classnames("".concat(settings.iotPrefix, "--suite-header"), className),
        url: navigatorRoute,
        handleHeaderNameClick: handleHeaderNameClick,
        hasSideNav: hideMenuButton ? false : hasSideNav || sideNavProps !== null,
        onClickSideNavExpand: function onClickSideNavExpand(evt) {
          onSideNavToggled(evt);
          _onClickSideNavExpand(evt);
        },
        headerPanel: {
          className: "".concat(settings.iotPrefix, "--suite-header-app-switcher").concat(workspaces ? '-multiworkspace' : ''),
          // eslint-disable-next-line react/prop-types
          content: /*#__PURE__*/React__default.forwardRef(function (_ref8, ref) {
            var isExpanded = _ref8.isExpanded;
            return workspaces ? /*#__PURE__*/React__default.createElement(MultiWorkspaceSuiteHeaderAppSwitcher, {
              ref: ref,
              isAdminView: isAdminView,
              workspaces: workspaces,
              globalApplications: globalApplications,
              customApplications: customApplications,
              adminLink: routes === null || routes === void 0 ? void 0 : routes.admin,
              noAccessLink: (routes === null || routes === void 0 ? void 0 : routes.gettingStarted) || 'javascript:void(0)',
              onRouteChange: onRouteChange,
              i18n: {
                workspace: mergedI18N.switcherWorkspace,
                workspaces: mergedI18N.switcherWorkspaces,
                workspaceAdmin: mergedI18N.switcherWorkspaceAdmin,
                backToAppSwitcher: mergedI18N.switcherBackToAppSwitcher,
                selectWorkspace: mergedI18N.switcherSelectWorkspace,
                availableWorkspaces: mergedI18N.switcherAvailableWorkspaces,
                suiteAdmin: mergedI18N.switcherSuiteAdmin,
                global: mergedI18N.switcherGlobal,
                myApplications: mergedI18N.switcherMyApplications,
                allApplicationsLink: mergedI18N.switcherNavigatorLink,
                requestAccess: mergedI18N.switcherRequestAccess,
                learnMoreLink: mergedI18N.switcherLearnMoreLink
              },
              testId: "".concat(testId, "-app-switcher"),
              isExpanded: isExpanded
            }) : applications ? /*#__PURE__*/React__default.createElement(SuiteHeaderAppSwitcher, {
              ref: ref,
              applications: applications,
              customApplications: customApplications,
              allApplicationsLink: routes === null || routes === void 0 ? void 0 : routes.navigator,
              noAccessLink: (routes === null || routes === void 0 ? void 0 : routes.gettingStarted) || 'javascript:void(0)',
              onRouteChange: onRouteChange,
              i18n: {
                myApplications: mergedI18N.switcherMyApplications,
                allApplicationsLink: mergedI18N.switcherNavigatorLink,
                requestAccess: mergedI18N.switcherRequestAccess,
                learnMoreLink: mergedI18N.switcherLearnMoreLink
              },
              testId: "".concat(testId, "-app-switcher"),
              isExpanded: isExpanded
            }) : /*#__PURE__*/React__default.createElement(SuiteHeaderAppSwitcherLoading, {
              ref: ref,
              testId: "".concat(testId, "-app-switcher")
            });
          })
        },
        appName: suiteName,
        subtitle: appNameComponent || currentWorkspaceComponent || extraContentComponent ? /*#__PURE__*/React__default.createElement("div", {
          dir: "auto"
        }, currentWorkspaceComponent, appNameComponent, extraContentComponent) : null,
        actionItems: [].concat(_toConsumableArray(customActionItems), [{
          id: 'admin',
          label: mergedI18N.administrationIcon,
          className: ['admin-icon', !(routes !== null && routes !== void 0 && routes.admin) ? 'admin-icon__hidden' : null, isAdminView ? 'admin-icon__selected' : null].filter(function (i) {
            return i;
          }).join(' '),
          btnContent: /*#__PURE__*/React__default.createElement("span", {
            id: "suite-header-action-item-admin"
          }, /*#__PURE__*/React__default.createElement(Settings, {
            size: "20",
            fill: "white",
            "data-testid": "admin-icon",
            description: mergedI18N.settingsIcon
          })),
          onClick: function () {
            var _onClick = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(e) {
              var href, routeType;
              return _regeneratorRuntime.wrap(function _callee4$(_context4) {
                while (1) switch (_context4.prev = _context4.next) {
                  case 0:
                    e.preventDefault();
                    href = adminRoute;
                    routeType = SUITE_HEADER_ROUTE_TYPES.ADMIN;
                    if (isAdminView) {
                      href = navigatorRoute;
                      routeType = SUITE_HEADER_ROUTE_TYPES.NAVIGATOR;
                    }
                    handleOnClick(routeType, href)(e);
                  case 5:
                  case "end":
                    return _context4.stop();
                }
              }, _callee4);
            }));
            function onClick(_x2) {
              return _onClick.apply(this, arguments);
            }
            return onClick;
          }(),
          href: isAdminView ? navigatorRoute : adminRoute
        }, {
          id: 'help',
          label: mergedI18N.help,
          onClick: function onClick() {},
          btnContent: /*#__PURE__*/React__default.createElement("span", {
            id: "suite-header-action-item-help"
          }, /*#__PURE__*/React__default.createElement(Help, {
            size: "20",
            fill: "white",
            description: mergedI18N.help
          })),
          childContent: routes ? [].concat(_toConsumableArray(mergedCustomHelpLinks), _toConsumableArray(['whatsNew', 'gettingStarted', 'documentation', 'requestEnhancement', 'support'].map(function (item) {
            return {
              metaData: {
                element: 'a',
                'data-testid': "suite-header-help--".concat(item),
                href: routes[item],
                rel: 'noopener noreferrer',
                title: mergedI18N[item],
                onClick: handleOnClick(SUITE_HEADER_ROUTE_TYPES.DOCUMENTATION, routes[item], true)
              },
              content: /*#__PURE__*/React__default.createElement("span", {
                id: "suite-header-help-menu-".concat(item)
              }, mergedI18N[item])
            };
          })), [{
            metaData: {
              element: 'a',
              'data-testid': 'suite-header-help--about',
              href: routes.about,
              rel: 'noopener noreferrer',
              title: mergedI18N.about,
              onClick: handleOnClick(SUITE_HEADER_ROUTE_TYPES.ABOUT, routes.about)
            },
            content: /*#__PURE__*/React__default.createElement("span", {
              id: "suite-header-help-menu-about"
            }, mergedI18N.about)
          }]) : [{
            metaData: {
              element: 'div'
            },
            content: /*#__PURE__*/React__default.createElement("div", {
              className: "".concat(settings.iotPrefix, "--suite-header-help--loading"),
              "data-testid": "suite-header-help--loading"
            }, /*#__PURE__*/React__default.createElement(SkeletonText, {
              paragraph: true,
              lineCount: 6
            }))
          }]
        }, {
          id: 'user',
          label: 'user',
          btnContent: /*#__PURE__*/React__default.createElement("span", {
            id: "suite-header-action-item-profile"
          }, /*#__PURE__*/React__default.createElement(UserAvatar, {
            size: "20",
            "data-testid": "user-icon",
            fill: "white",
            description: mergedI18N.userIcon
          })),
          childContent: [{
            metaData: {
              element: 'div'
            },
            content: /*#__PURE__*/React__default.createElement("span", {
              id: "suite-header-profile-menu-profile",
              style: {
                width: '100%'
              }
            }, /*#__PURE__*/React__default.createElement(SuiteHeaderProfile, {
              displayName: userDisplayName,
              username: username,
              profileLink: routes === null || routes === void 0 ? void 0 : routes.profile,
              onProfileClick: handleOnClick(SUITE_HEADER_ROUTE_TYPES.PROFILE, routes === null || routes === void 0 ? void 0 : routes.profile),
              i18n: {
                profileTitle: mergedI18N.profileTitle,
                profileButton: mergedI18N.profileManageButton
              },
              testId: "".concat(testId, "-profile")
            }))
          }].concat(_toConsumableArray(customProfileLinks), [username ? {
            metaData: {
              className: "".concat(settings.iotPrefix, "--suite-header--logout"),
              element: 'a',
              'data-testid': 'suite-header-profile--logout',
              href: 'javascript:void(0)',
              title: mergedI18N.logout,
              onClick: function onClick() {
                return setShowLogoutModal(true);
              }
            },
            content: /*#__PURE__*/React__default.createElement("span", {
              id: "suite-header-profile-menu-logout"
            }, mergedI18N.logout)
          } : {
            metaData: {
              element: 'div'
            },
            content: /*#__PURE__*/React__default.createElement("div", {
              className: "".concat(settings.iotPrefix, "--suite-header--logout--loading"),
              "data-testid": "suite-header--logout--loading"
            }, /*#__PURE__*/React__default.createElement(ButtonSkeleton, null))
          }])
        }]).filter(function (i) {
          return i;
        }),
        showCloseIconWhenPanelExpanded: true,
        isSideNavExpanded: isSideNavExpanded
      }, otherHeaderProps)), sideNavProps ? /*#__PURE__*/React__default.createElement(SideNav, _extends({}, closeSideNavOnNavigation ? setOnClickDecorators(sideNavProps, _onClickSideNavExpand) : sideNavProps, {
        isSideNavExpanded: isSideNavExpanded,
        testId: "".concat(testId, "-side-nav")
      })) : null);
    }
  }));
};
SuiteHeader.defaultProps = defaultProps;
SuiteHeader.propTypes = propTypes;
SuiteHeader.ROUTE_TYPES = SUITE_HEADER_ROUTE_TYPES;
SuiteHeader.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "SuiteHeader",
  "props": {
    "className": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Add class name to the rendered Header component",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "appName": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Application name in suite (maps to subtitle in Header)",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "extraContent": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Extra content (a Tag, for example)",
      "type": {
        "name": "element"
      },
      "required": false
    },
    "userDisplayName": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Display name of current user",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "username": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Username of current user",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "isAdminView": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "If true, renders the admin button in Header as selected",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "hasSideNav": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "If true, will render the hamburger icon even if no sideNavProps are provided",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "routes": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "URLs for various routes on Header buttons and submenus",
      "type": {
        "name": "shape",
        "value": "import {\n  SuiteHeaderApplicationPropTypes,\n  SuiteHeaderWorkspacePropTypes,\n  SuiteHeaderI18NPropTypes,\n  SuiteHeaderRoutePropTypes,\n  SuiteHeaderSurveyDataPropTypes,\n} from './SuiteHeaderPropTypes';",
        "computed": true
      },
      "required": false
    },
    "applications": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Applications to render in AppSwitcher (not used anymore, only kept here for backwards compatibility)",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "shape",
          "value": "import {\n  SuiteHeaderApplicationPropTypes,\n  SuiteHeaderWorkspacePropTypes,\n  SuiteHeaderI18NPropTypes,\n  SuiteHeaderRoutePropTypes,\n  SuiteHeaderSurveyDataPropTypes,\n} from './SuiteHeaderPropTypes';",
          "computed": true
        }
      },
      "required": false
    },
    "workspaces": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Workspaces and applications to render in AppSwitcher",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "shape",
          "value": "import {\n  SuiteHeaderApplicationPropTypes,\n  SuiteHeaderWorkspacePropTypes,\n  SuiteHeaderI18NPropTypes,\n  SuiteHeaderRoutePropTypes,\n  SuiteHeaderSurveyDataPropTypes,\n} from './SuiteHeaderPropTypes';",
          "computed": true
        }
      },
      "required": false
    },
    "globalApplications": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "Applications that are not tied to workspaces",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "shape",
          "value": "import {\n  SuiteHeaderApplicationPropTypes,\n  SuiteHeaderWorkspacePropTypes,\n  SuiteHeaderI18NPropTypes,\n  SuiteHeaderRoutePropTypes,\n  SuiteHeaderSurveyDataPropTypes,\n} from './SuiteHeaderPropTypes';",
          "computed": true
        }
      },
      "required": false
    },
    "sideNavProps": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "side navigation component",
      "type": {
        "name": "shape",
        "value": "import SideNav, { SideNavPropTypes } from '../SideNav/SideNav';",
        "computed": true
      },
      "required": false
    },
    "surveyData": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "If surveyData is present, show an ActionableNotification",
      "type": {
        "name": "shape",
        "value": "import {\n  SuiteHeaderApplicationPropTypes,\n  SuiteHeaderWorkspacePropTypes,\n  SuiteHeaderI18NPropTypes,\n  SuiteHeaderRoutePropTypes,\n  SuiteHeaderSurveyDataPropTypes,\n} from './SuiteHeaderPropTypes';",
        "computed": true
      },
      "required": false
    },
    "idleTimeoutData": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "If idleTimeoutData is present, instantiate IdleLogoutConfirmationModal",
      "type": {
        "name": "shape",
        "value": "import IdleLogoutConfirmationModal, {\n  IdleLogoutConfirmationModalIdleTimeoutPropTypes,\n} from './IdleLogoutConfirmationModal/IdleLogoutConfirmationModal';",
        "computed": true
      },
      "required": false
    },
    "onStayLoggedIn": {
      "defaultValue": {
        "value": "() => {}",
        "computed": false
      },
      "description": "Function called when idle timer is restarted",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "onSideNavToggled": {
      "defaultValue": {
        "value": "async () => Promise.resolve(true)",
        "computed": false
      },
      "description": "Function called when side nav button is toggled",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "onRouteChange": {
      "defaultValue": {
        "value": "async () => Promise.resolve(true)",
        "computed": false
      },
      "description": "Function called before any route change. Returns a Promise<Boolean>. False means the redirect will not happen. This function should never throw an error.",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "i18n": {
      "defaultValue": {
        "value": "SuiteHeaderI18N.en",
        "computed": true
      },
      "description": "I18N strings",
      "type": {
        "name": "shape",
        "value": "import {\n  SuiteHeaderApplicationPropTypes,\n  SuiteHeaderWorkspacePropTypes,\n  SuiteHeaderI18NPropTypes,\n  SuiteHeaderRoutePropTypes,\n  SuiteHeaderSurveyDataPropTypes,\n} from './SuiteHeaderPropTypes';",
        "computed": true
      },
      "required": false
    },
    "customActionItems": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "Array of custom header action items",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "shape",
          "value": "import { HeaderActionItemPropTypes, ChildContentPropTypes } from '../Header/HeaderPropTypes';",
          "computed": true
        }
      },
      "required": false
    },
    "customHelpLinks": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "Array of custom help menu links",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "shape",
          "value": "import { HeaderActionItemPropTypes, ChildContentPropTypes } from '../Header/HeaderPropTypes';",
          "computed": true
        }
      },
      "required": false
    },
    "customProfileLinks": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "Array of custom profile menu links",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "shape",
          "value": "import { HeaderActionItemPropTypes, ChildContentPropTypes } from '../Header/HeaderPropTypes';",
          "computed": true
        }
      },
      "required": false
    },
    "customApplications": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "Array of custom applications",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "shape",
          "value": "import {\n  SuiteHeaderApplicationPropTypes,\n  SuiteHeaderWorkspacePropTypes,\n  SuiteHeaderI18NPropTypes,\n  SuiteHeaderRoutePropTypes,\n  SuiteHeaderSurveyDataPropTypes,\n} from './SuiteHeaderPropTypes';",
          "computed": true
        }
      },
      "required": false
    },
    "walkmePath": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Path to Walkme entry point",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "walkmeLang": {
      "defaultValue": {
        "value": "'en'",
        "computed": false
      },
      "description": "Walkme language code",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "'suite-header'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "isActionItemVisible": {
      "defaultValue": {
        "value": "() => true",
        "computed": false
      },
      "description": "a function that will be passed the actionItem object and returns a boolean to determine if that item should be shown",
      "type": {
        "name": "custom",
        "raw": "Header.propTypes.isActionItemVisible"
      },
      "required": false
    },
    "handleHeaderNameClick": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Optional callback when user clicks on header name",
      "type": {
        "name": "union",
        "value": [{
          "name": "func"
        }, {
          "name": "any"
        }]
      },
      "required": false
    },
    "hideMenuButton": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Force menu button to hide regardless of side nav props",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "closeSideNavOnNavigation": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Force side nav to close upon item click",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "suiteName": {
      "description": "Name of suite (maps to appName in Header)",
      "type": {
        "name": "string"
      },
      "required": true
    }
  }
};
var SuiteHeader$1 = SuiteHeader;

export { SuiteHeader$1 as default };
