"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.NarrowUiShellContent = void 0;
var _Skeleton2 = _interopRequireDefault(require("@mui/material/Skeleton"));
var _styled = _interopRequireDefault(require("@emotion/styled"));
var _react = require("react");
var _reactErrorBoundary = require("react-error-boundary");
var _Button = require("../Buttons/Button.cjs");
var _hexToRgb = require("../hexToRgb.cjs");
var _Close = require("../icons.generated/Close.cjs");
var _More = require("../icons.generated/More.cjs");
var _OdysseyDesignTokensContext = require("../OdysseyDesignTokensContext.cjs");
var _InnerAppContainer = require("./InnerAppContainer.cjs");
var _SideNav = require("./SideNav/SideNav.cjs");
var _SideNavLogo = require("./SideNav/SideNavLogo.cjs");
var _HamburgerMenuIcon = require("./TopNav/HamburgerMenuIcon.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) 2022-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 StyledAppContentArea = (0, _styled.default)("div")({
  gridArea: "app-content",
  position: "relative",
  height: "100%",
  width: "100%"
});
const StyledAppContainer = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "appBackgroundColor" && prop !== "odysseyDesignTokens"
})(({
  appBackgroundColor
}) => ({
  backgroundColor: appBackgroundColor,
  height: "100%",
  overflow: "hidden",
  width: "100%"
}));
const StyledBannersContainer = (0, _styled.default)("div")({
  gridArea: "banners",
  zIndex: _uiShellSharedConstants.UI_SHELL_BASE_Z_INDEX
});
const StyledLeftSideContainer = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "isOpen"
})(({
  isOpen
}) => ({
  display: isOpen ? "block" : "none",
  height: "100%",
  position: "absolute",
  zIndex: _uiShellSharedConstants.UI_SHELL_OVERLAY_Z_INDEX
}));
const StyledRightSideContainer = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "isOpen" && prop !== "odysseyDesignTokens"
})(({
  isOpen,
  odysseyDesignTokens
}) => ({
  backgroundColor: odysseyDesignTokens.HueNeutralWhite,
  display: isOpen ? "block" : "none",
  height: "100%",
  maxWidth: _uiShellSharedConstants.SIDE_NAV_WIDTH,
  overflowY: "auto",
  position: "absolute",
  right: 0,
  width: _uiShellSharedConstants.SIDE_NAV_WIDTH,
  zIndex: _uiShellSharedConstants.UI_SHELL_OVERLAY_Z_INDEX
}));
const StyledMenuLogo = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(({
  odysseyDesignTokens
}) => ({
  alignItems: "center",
  display: "inline-flex",
  gap: odysseyDesignTokens.Spacing3
}));
const StyledLogoContainer = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(({
  odysseyDesignTokens
}) => ({
  height: _uiShellSharedConstants.TOP_NAV_HEIGHT,
  paddingBlock: odysseyDesignTokens.Spacing4,
  "svg, img": {
    maxHeight: "100%",
    width: "auto",
    maxWidth: "100%"
  }
}));
const StyledPageOverlay = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(({
  odysseyDesignTokens
}) => ({
  backgroundColor: (0, _hexToRgb.hexToRgb)(odysseyDesignTokens.HueNeutral900).asFormattedString.replace(/rgb\((.+)\)$/, "rgba($1, 0.26)"),
  gridArea: "app-content",
  height: "100vh",
  left: 0,
  position: "absolute",
  top: 0,
  width: "100vw",
  zIndex: _uiShellSharedConstants.UI_SHELL_BASE_Z_INDEX
}));
const StyledSideNavContainer = (0, _styled.default)("div")({
  height: "100%"
});
const StyledUiShellContainer = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(({
  odysseyDesignTokens
}) => ({
  backgroundColor: odysseyDesignTokens.HueNeutral50,
  display: "grid",
  gridGap: 0,
  gridTemplateAreas: `
    "banners"
    "top-nav"
    "app-content"
  `,
  gridTemplateColumns: "1fr",
  gridTemplateRows: "auto auto 1fr",
  height: "100vh",
  overflow: "hidden",
  width: "100vw"
}));
const StyledTopNav = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens" && prop !== "isContentScrolled" && prop !== "topNavBackgroundColor"
})(({
  odysseyDesignTokens,
  isContentScrolled,
  topNavBackgroundColor
}) => ({
  alignItems: "stretch",
  backgroundColor: odysseyDesignTokens.HueNeutralWhite || topNavBackgroundColor,
  boxShadow: isContentScrolled ? odysseyDesignTokens.DepthMedium : undefined,
  clipPath: "inset(0 0 -100vh 0)",
  display: "flex",
  flexDirection: "column",
  gridArea: "top-nav",
  height: "100%",
  justifyContent: "center",
  position: "relative",
  transition: `box-shadow ${odysseyDesignTokens.TransitionDurationMain} ${odysseyDesignTokens.TransitionTimingMain}`,
  zIndex: _uiShellSharedConstants.UI_SHELL_BASE_Z_INDEX
}));
const StyledTopNavMenu = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens" && prop !== "topNavBackgroundColor"
})(({
  odysseyDesignTokens,
  topNavBackgroundColor
}) => ({
  alignItems: "center",
  display: "flex",
  gap: odysseyDesignTokens.Spacing3,
  height: "100%",
  justifyContent: "space-between",
  maxHeight: _uiShellSharedConstants.TOP_NAV_HEIGHT,
  minHeight: _uiShellSharedConstants.TOP_NAV_HEIGHT,
  paddingBlock: odysseyDesignTokens.Spacing2,
  paddingInline: odysseyDesignTokens.Spacing3,
  transition: `box-shadow ${odysseyDesignTokens.TransitionDurationMain} ${odysseyDesignTokens.TransitionTimingMain}`,
  ...(topNavBackgroundColor === odysseyDesignTokens.HueNeutralWhite && {
    borderBottomColor: odysseyDesignTokens.HueNeutral100,
    borderBottomStyle: odysseyDesignTokens.BorderStyleMain,
    borderBottomWidth: odysseyDesignTokens.BorderWidthMain
  })
}));
const StyledTopNavSearch = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(({
  odysseyDesignTokens
}) => ({
  paddingBlock: odysseyDesignTokens.Spacing2,
  paddingInline: odysseyDesignTokens.Spacing3
}));
const NarrowUiShellContent = ({
  appElement,
  appElementScrollingMode,
  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 [isLeftSideMenuOpen, setIsLeftSideMenuOpen] = (0, _react.useState)(false);
  const [isRightSideMenuOpen, setIsRightSideMenuOpen] = (0, _react.useState)(false);
  const closeSideMenus = (0, _react.useCallback)(() => {
    setIsLeftSideMenuOpen(false);
    setIsRightSideMenuOpen(false);
  }, []);
  (0, _react.useEffect)(() => {
    const unsubscribeFromCloseRightSideMenu = uiShellContext?.subscribeToCloseRightSideMenu(() => {
      closeSideMenus();
    });
    const unsubscribeFromSideNavItemClicked = uiShellContext?.subscribeToCloseSideNavMenu(() => {
      closeSideMenus();
    });
    return () => {
      unsubscribeFromCloseRightSideMenu?.();
      unsubscribeFromSideNavItemClicked?.();
    };
  }, [closeSideMenus, uiShellContext]);
  const toggleLeftSideMenu = (0, _react.useCallback)(() => {
    setIsRightSideMenuOpen(false);
    setIsLeftSideMenuOpen(isLeftSideMenuOpen => !isLeftSideMenuOpen);
  }, []);
  const toggleRightSideMenu = (0, _react.useCallback)(() => {
    setIsLeftSideMenuOpen(false);
    setIsRightSideMenuOpen(isRightSideMenuOpen => !isRightSideMenuOpen);
  }, []);
  const {
    parentContainerRef
  } = (0, _useMatchAppElementToUiShellAppArea.useMatchAppElementToUiShellAppArea)({
    appElement,
    appElementScrollingMode,
    paddingMode: hasStandardAppContentPadding ? "compact" : "none",
    uiShellAppAreaRef,
    uiShellResizableRefs: [sideNavContainerRef, topNavContainerRef, uiShellAppAreaRef]
  });
  return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
    children: [(isLeftSideMenuOpen || isRightSideMenuOpen) && (0, _jsxRuntime.jsx)(StyledPageOverlay, {
      odysseyDesignTokens: odysseyDesignTokens,
      onClick: closeSideMenus
    }), (0, _jsxRuntime.jsxs)(StyledUiShellContainer, {
      odysseyDesignTokens: odysseyDesignTokens,
      ref: parentContainerRef,
      children: [(0, _jsxRuntime.jsx)(StyledBannersContainer, {
        children: optionalComponents?.banners
      }), (initialVisibleSections?.includes("TopNav") || topNavProps) && (0, _jsxRuntime.jsx)(_reactErrorBoundary.ErrorBoundary, {
        fallback: null,
        onError: onError,
        children: (0, _jsxRuntime.jsxs)(StyledTopNav, {
          isContentScrolled: isContentScrolled,
          odysseyDesignTokens: odysseyDesignTokens,
          topNavBackgroundColor: uiShellContext?.topNavBackgroundColor,
          children: [(0, _jsxRuntime.jsxs)(StyledTopNavMenu, {
            odysseyDesignTokens: odysseyDesignTokens,
            topNavBackgroundColor: uiShellContext?.sideNavBackgroundColor,
            children: [(0, _jsxRuntime.jsxs)(StyledMenuLogo, {
              odysseyDesignTokens: odysseyDesignTokens,
              children: [(sideNavProps?.isCollapsible || !sideNavProps?.isCollapsed) && (0, _jsxRuntime.jsx)(_Button.Button, {
                onClick: toggleLeftSideMenu,
                startIcon: (0, _jsxRuntime.jsx)(_HamburgerMenuIcon.HamburgerMenuIcon, {}),
                testId: "sidenav-menu--icon",
                variant: "floating"
              }), (0, _jsxRuntime.jsx)(StyledLogoContainer, {
                odysseyDesignTokens: odysseyDesignTokens,
                children: sideNavProps?.isLoading ? (0, _jsxRuntime.jsx)(_Skeleton2.default, {
                  height: 24,
                  variant: "rounded",
                  width: 67
                }) : (0, _jsxRuntime.jsx)(_SideNavLogo.SideNavLogo, {
                  ...sideNavProps?.logoProps
                })
              })]
            }), optionalComponents?.rightSideMenu && (0, _jsxRuntime.jsx)(_Button.Button, {
              onClick: toggleRightSideMenu,
              startIcon: isRightSideMenuOpen ? (0, _jsxRuntime.jsx)(_Close.CloseIcon, {}) : (0, _jsxRuntime.jsx)(_More.MoreIcon, {}),
              testId: "userprofile-menu--icon",
              variant: "floating"
            })]
          }), optionalComponents?.topNavLeftSide && (0, _jsxRuntime.jsx)(StyledTopNavSearch, {
            odysseyDesignTokens: odysseyDesignTokens,
            children: optionalComponents?.topNavLeftSide
          })]
        })
      }), (0, _jsxRuntime.jsxs)(StyledAppContentArea, {
        children: [(0, _jsxRuntime.jsxs)(StyledLeftSideContainer, {
          isOpen: isLeftSideMenuOpen,
          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)(StyledSideNavContainer, {
              children: (0, _jsxRuntime.jsx)(_SideNav.SideNav, {
                ...{
                  ...sideNavProps,
                  appName: undefined,
                  logoProps: undefined
                },
                ...(sideNavProps.hasCustomFooter && optionalComponents?.sideNavFooter ? {
                  footerComponent: optionalComponents.sideNavFooter,
                  footerItems: undefined,
                  hasCustomFooter: sideNavProps.hasCustomFooter
                } : {
                  footerItems: sideNavProps.footerItems,
                  hasCustomFooter: false
                }),
                isCollapsed: false,
                isCollapsible: false,
                isObtrusive: true,
                onCollapse: closeSideMenus
              })
            })
          })]
        }), (0, _jsxRuntime.jsx)(StyledRightSideContainer, {
          isOpen: isRightSideMenuOpen,
          odysseyDesignTokens: odysseyDesignTokens,
          children: (0, _jsxRuntime.jsx)(StyledSideNavContainer, {
            children: optionalComponents?.rightSideMenu
          })
        }), (0, _jsxRuntime.jsx)(StyledAppContainer, {
          appBackgroundColor: uiShellContext?.appBackgroundColor,
          ref: uiShellAppAreaRef,
          tabIndex: 0,
          children: (0, _jsxRuntime.jsx)(_InnerAppContainer.InnerAppContainer, {
            isContentScrolled: isContentScrolled
          })
        })]
      })]
    })]
  });
};
const MemoizedNarrowUiShellContent = exports.NarrowUiShellContent = (0, _react.memo)(NarrowUiShellContent);
MemoizedNarrowUiShellContent.displayName = "NarrowUiShellContent";
//# sourceMappingURL=NarrowUiShellContent.cjs.map