"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PageTemplate = void 0;
var _styled = _interopRequireDefault(require("@emotion/styled"));
var _react = require("react");
var _index = require("../../icons.generated/index.cjs");
var _OdysseyDesignTokensContext = require("../../OdysseyDesignTokensContext.cjs");
var _Typography = require("../../Typography.cjs");
var _useHasUiShell = require("../../ui-shell/useHasUiShell.cjs");
var _useMountLifecycleEffect = require("../../useMountLifecycleEffect.cjs");
var _DocumentationLink = require("./DocumentationLink.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 TemplateContainer = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens" && prop !== "hasUiShell" && prop !== "isFullWidth"
})(({
  hasUiShell,
  isFullWidth,
  odysseyDesignTokens
}) => ({
  maxWidth: isFullWidth ? "100%" : `calc(1440px + ${odysseyDesignTokens.Spacing6} + ${odysseyDesignTokens.Spacing6})`,
  marginInline: isFullWidth && !hasUiShell ? odysseyDesignTokens.Spacing6 : "auto",
  padding: hasUiShell ? 0 : odysseyDesignTokens.Spacing6
}));
const TemplateHeader = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(({
  odysseyDesignTokens
}) => ({
  display: "flex",
  alignItems: "flex-start",
  justifyContent: "space-between",
  gap: odysseyDesignTokens.Spacing4
}));
const TemplateHeaderPrimaryContent = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(({
  odysseyDesignTokens
}) => ({
  maxWidth: odysseyDesignTokens.TypographyLineLengthMax,
  [".MuiTypography-root:last-child"]: {
    marginBlockEnd: "0"
  }
}));
const TemplateHeaderSecondaryContent = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(({
  odysseyDesignTokens
}) => ({
  alignItems: "flex-end",
  display: "flex",
  flexDirection: "column",
  gap: odysseyDesignTokens.Spacing4,
  minHeight: odysseyDesignTokens.Spacing7,
  justifyContent: "center",
  whiteSpace: "nowrap"
}));
const TemplateHeaderButtons = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(({
  odysseyDesignTokens
}) => ({
  display: "flex",
  gap: odysseyDesignTokens.Spacing2
}));
const TemplateContent = (0, _styled.default)("div", {
  shouldForwardProp: prop => !["drawerVariant", "isDrawerOpen", "isFirstRender", "odysseyDesignTokens"].includes(prop)
})(({
  drawerVariant,
  isDrawerOpen,
  isFirstRender,
  odysseyDesignTokens
}) => ({
  "@keyframes animate-drawer-open": {
    "0%": {
      gridTemplateColumns: "minmax(0, 1fr) 0"
    },
    "100%": {
      gridTemplateColumns: "minmax(0, 1fr) 360px"
    }
  },
  "@keyframes animate-drawer-close": {
    "0%": {
      gridTemplateColumns: "minmax(0, 1fr) 360px"
    },
    "100%": {
      gridTemplateColumns: "minmax(0, 1fr) 0"
    }
  },
  display: "grid",
  gridGap: drawerVariant === "persistent" && !isDrawerOpen ? 0 : odysseyDesignTokens.Spacing4,
  gap: drawerVariant === "persistent" && !isDrawerOpen ? 0 : odysseyDesignTokens.Spacing4,
  marginBlock: odysseyDesignTokens.Spacing4,
  gridTemplateColumns: drawerVariant === "persistent" ? isDrawerOpen ? "minmax(0, 1fr) 360px" : "minmax(0, 1fr) 0" : "minmax(0, 1fr)",
  animation: drawerVariant === "persistent" && (!isFirstRender || isDrawerOpen) ? `animate-drawer-${isDrawerOpen ? "open" : "close"} 225ms cubic-bezier(0, 0, 0.2, 1)` : undefined
}));
const PageTemplate = ({
  children,
  description,
  documentationLink,
  documentationText,
  drawer,
  isFullWidth = false,
  primaryCallToActionComponent,
  secondaryCallToActionComponent,
  tertiaryCallToActionComponent,
  title
}) => {
  const odysseyDesignTokens = (0, _OdysseyDesignTokensContext.useOdysseyDesignTokens)();
  const {
    isOpen: isDrawerOpen,
    variant: drawerVariant
  } = drawer?.props ?? {};
  const hasUiShell = (0, _useHasUiShell.useHasUiShell)();
  const firstRenderRef = (0, _react.useRef)(true);
  const isFirstRender = firstRenderRef.current;
  const onMount = (0, _react.useCallback)(() => {
    firstRenderRef.current = false;
  }, []);
  (0, _useMountLifecycleEffect.useMountLifecycleEffect)({
    onMount
  });
  return (0, _jsxRuntime.jsxs)(TemplateContainer, {
    hasUiShell: hasUiShell,
    isFullWidth: isFullWidth,
    odysseyDesignTokens: odysseyDesignTokens,
    children: [(0, _jsxRuntime.jsxs)(TemplateHeader, {
      odysseyDesignTokens: odysseyDesignTokens,
      children: [(0, _jsxRuntime.jsxs)(TemplateHeaderPrimaryContent, {
        odysseyDesignTokens: odysseyDesignTokens,
        children: [title && (0, _jsxRuntime.jsx)(_Typography.Heading4, {
          children: title
        }), description && (0, _jsxRuntime.jsx)(_Typography.Paragraph, {
          children: description
        })]
      }), (0, _jsxRuntime.jsxs)(TemplateHeaderSecondaryContent, {
        odysseyDesignTokens: odysseyDesignTokens,
        children: [documentationLink && (0, _jsxRuntime.jsx)(_DocumentationLink.DocumentationLink, {
          href: documentationLink,
          icon: (0, _jsxRuntime.jsx)(_index.DocumentationIcon, {}),
          target: "_blank",
          children: documentationText
        }), (primaryCallToActionComponent || secondaryCallToActionComponent || tertiaryCallToActionComponent) && (0, _jsxRuntime.jsxs)(TemplateHeaderButtons, {
          odysseyDesignTokens: odysseyDesignTokens,
          children: [tertiaryCallToActionComponent, secondaryCallToActionComponent, primaryCallToActionComponent]
        })]
      })]
    }), (0, _jsxRuntime.jsxs)(TemplateContent, {
      drawerVariant: drawerVariant,
      isDrawerOpen: isDrawerOpen,
      isFirstRender: isFirstRender,
      odysseyDesignTokens: odysseyDesignTokens,
      children: [children, drawer]
    })]
  });
};
const MemoizedPageTemplate = exports.PageTemplate = (0, _react.memo)(PageTemplate);
MemoizedPageTemplate.displayName = "PageTemplate";
//# sourceMappingURL=PageTemplate.cjs.map