"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.WideUiShellContent = void 0;
var _styled = _interopRequireDefault(require("@emotion/styled"));
var _react = require("react");
var _reactErrorBoundary = require("react-error-boundary");
var _OdysseyDesignTokensContext = require("../OdysseyDesignTokensContext.cjs");
var _AppSwitcher = require("./AppSwitcher/AppSwitcher.cjs");
var _InnerAppContainer = require("./InnerAppContainer.cjs");
var _SideNav = require("./SideNav/SideNav.cjs");
var _TopNav = require("./TopNav/TopNav.cjs");
var _uiShellContentTypes = require("./uiShellContentTypes.cjs");
var _UiShellProvider = require("./UiShellProvider.cjs");
var _uiShellSharedConstants = require("./uiShellSharedConstants.cjs");
var _useMatchAppElementToUiShellAppArea = require("./useMatchAppElementToUiShellAppArea.cjs");
var _useScrollState = require("./useScrollState.cjs");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/*!
 * Copyright (c) 2024-present, Okta, Inc. and/or its affiliates. All rights reserved.
 * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
 *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and limitations under the License.
 */

const appSwitcherDefaultAppIcons = [];
const StyledAppContainer = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "appBackgroundColor" && prop !== "odysseyDesignTokens"
})(({
  appBackgroundColor
}) => ({
  backgroundColor: appBackgroundColor,
  gridArea: "app-content",
  position: "relative"
}));
const StyledAppSwitcherContainer = (0, _styled.default)("div")({
  gridArea: "app-switcher"
});
const StyledBannersContainer = (0, _styled.default)("div")({
  gridArea: "banners"
});
const StyledSideNavContainer = (0, _styled.default)("div")({
  gridArea: "side-nav"
});
const StyledShellContainer = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(({
  odysseyDesignTokens
}) => ({
  backgroundColor: odysseyDesignTokens.HueNeutral50,
  display: "grid",
  gridGap: 0,
  gridTemplateAreas: `
    "banners banners banners"
    "app-switcher side-nav top-nav"
    "app-switcher side-nav app-content"
  `,
  gridTemplateColumns: "auto auto 1fr",
  gridTemplateRows: "auto auto 1fr",
  height: "100vh",
  width: "100vw"
}));
const StyledTopNavContainer = (0, _styled.default)("div")({
  gridArea: "top-nav"
});
const WideUiShellContent = ({
  appElement,
  appElementScrollingMode,
  appSwitcherProps,
  hasStandardAppContentPadding = true,
  hasSideNavProps,
  initialVisibleSections = ["TopNav", "SideNav", "AppSwitcher"],
  onError = console.error,
  optionalComponents,
  sideNavProps,
  topNavProps
}) => {
  const odysseyDesignTokens = (0, _OdysseyDesignTokensContext.useOdysseyDesignTokens)();
  const uiShellContext = (0, _UiShellProvider.useUiShellContext)();
  const {
    isContentScrolled
  } = (0, _useScrollState.useScrollState)(appElement);
  const sideNavContainerRef = (0, _react.useRef)(null);
  const topNavContainerRef = (0, _react.useRef)(null);
  const uiShellAppAreaRef = (0, _react.useRef)(null);
  const {
    parentContainerRef
  } = (0, _useMatchAppElementToUiShellAppArea.useMatchAppElementToUiShellAppArea)({
    appElement,
    appElementScrollingMode,
    paddingMode: hasStandardAppContentPadding ? "comfortable" : "none",
    uiShellAppAreaRef,
    uiShellResizableRefs: [sideNavContainerRef, topNavContainerRef, uiShellAppAreaRef]
  });
  return (0, _jsxRuntime.jsxs)(StyledShellContainer, {
    odysseyDesignTokens: odysseyDesignTokens,
    ref: parentContainerRef,
    children: [(0, _jsxRuntime.jsx)(StyledBannersContainer, {
      children: optionalComponents?.banners
    }), (0, _jsxRuntime.jsxs)(StyledAppSwitcherContainer, {
      children: [initialVisibleSections?.includes("AppSwitcher") && !appSwitcherProps && (0, _jsxRuntime.jsx)(_reactErrorBoundary.ErrorBoundary, {
        fallback: null,
        onError: onError,
        children: (0, _jsxRuntime.jsx)(_AppSwitcher.AppSwitcher, {
          appIcons: appSwitcherDefaultAppIcons,
          isLoading: true,
          selectedAppName: ""
        })
      }), appSwitcherProps && appSwitcherProps !== _uiShellContentTypes.TURN_OFF_APP_SWITCHER && (0, _jsxRuntime.jsx)(_reactErrorBoundary.ErrorBoundary, {
        fallback: null,
        onError: onError,
        children: (0, _jsxRuntime.jsx)(_AppSwitcher.AppSwitcher, {
          ...appSwitcherProps
        })
      })]
    }), (0, _jsxRuntime.jsxs)(StyledSideNavContainer, {
      ref: sideNavContainerRef,
      children: [initialVisibleSections?.includes("SideNav") && !hasSideNavProps && (0, _jsxRuntime.jsx)(_reactErrorBoundary.ErrorBoundary, {
        fallback: null,
        onError: onError,
        children: (0, _jsxRuntime.jsx)(_SideNav.SideNav, {
          isLoading: true,
          sideNavItems: _uiShellSharedConstants.emptySideNavItems
        })
      }), hasSideNavProps && sideNavProps && (0, _jsxRuntime.jsx)(_reactErrorBoundary.ErrorBoundary, {
        fallback: null,
        onError: onError,
        children: (0, _jsxRuntime.jsx)(_SideNav.SideNav, {
          ...sideNavProps,
          ...(sideNavProps.hasCustomFooter && optionalComponents?.sideNavFooter ? {
            footerComponent: optionalComponents.sideNavFooter,
            footerItems: undefined,
            hasCustomFooter: sideNavProps.hasCustomFooter
          } : {
            footerItems: sideNavProps.footerItems,
            hasCustomFooter: false
          })
        })
      })]
    }), (0, _jsxRuntime.jsxs)(StyledTopNavContainer, {
      ref: topNavContainerRef,
      children: [initialVisibleSections?.includes("TopNav") && topNavProps === undefined && (0, _jsxRuntime.jsx)(_reactErrorBoundary.ErrorBoundary, {
        fallback: null,
        onError: onError,
        children: (0, _jsxRuntime.jsx)(_TopNav.TopNav, {
          leftSideComponent: optionalComponents?.topNavLeftSide,
          rightSideComponent: optionalComponents?.topNavRightSide
        })
      }), topNavProps && (0, _jsxRuntime.jsx)(_reactErrorBoundary.ErrorBoundary, {
        fallback: null,
        onError: onError,
        children: (0, _jsxRuntime.jsx)(_TopNav.TopNav, {
          ...topNavProps,
          leftSideComponent: optionalComponents?.topNavLeftSide,
          rightSideComponent: optionalComponents?.topNavRightSide
        })
      })]
    }), (0, _jsxRuntime.jsx)(StyledAppContainer, {
      appBackgroundColor: uiShellContext?.appBackgroundColor,
      ref: uiShellAppAreaRef,
      tabIndex: 0,
      children: (0, _jsxRuntime.jsx)(_InnerAppContainer.InnerAppContainer, {
        isContentScrolled: isContentScrolled
      })
    })]
  });
};
const MemoizedWideUiShellContent = exports.WideUiShellContent = (0, _react.memo)(WideUiShellContent);
MemoizedWideUiShellContent.displayName = "WideUiShellContent";
//# sourceMappingURL=WideUiShellContent.cjs.map