function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var _excluded = ["gutterX"],
  _excluded2 = ["transparent"],
  _excluded3 = ["children"],
  _excluded4 = ["minSections"],
  _excluded5 = ["children", "open"];
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _regeneratorRuntime() { "use strict"; var r = _regenerator(), e = r.m(_regeneratorRuntime), t = (Object.getPrototypeOf ? Object.getPrototypeOf(e) : e.__proto__).constructor; function n(r) { var e = "function" == typeof r && r.constructor; return !!e && (e === t || "GeneratorFunction" === (e.displayName || e.name)); } var o = { "throw": 1, "return": 2, "break": 3, "continue": 3 }; function a(r) { var e, t; return function (n) { e || (e = { stop: function stop() { return t(n.a, 2); }, "catch": function _catch() { return n.v; }, abrupt: function abrupt(r, e) { return t(n.a, o[r], e); }, delegateYield: function delegateYield(r, o, a) { return e.resultName = o, t(n.d, _regeneratorValues(r), a); }, finish: function finish(r) { return t(n.f, r); } }, t = function t(r, _t, o) { n.p = e.prev, n.n = e.next; try { return r(_t, o); } finally { e.next = n.n; } }), e.resultName && (e[e.resultName] = n.v, e.resultName = void 0), e.sent = n.v, e.next = n.n; try { return r.call(this, e); } finally { n.p = e.prev, n.n = e.next; } }; } return (_regeneratorRuntime = function _regeneratorRuntime() { return { wrap: function wrap(e, t, n, o) { return r.w(a(e), t, n, o && o.reverse()); }, isGeneratorFunction: n, mark: r.m, awrap: function awrap(r, e) { return new _OverloadYield(r, e); }, AsyncIterator: _regeneratorAsyncIterator, async: function async(r, e, t, o, u) { return (n(e) ? _regeneratorAsyncGen : _regeneratorAsync)(a(r), e, t, o, u); }, keys: _regeneratorKeys, values: _regeneratorValues }; })(); }
function _regeneratorValues(e) { if (null != e) { var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"], r = 0; if (t) return t.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) return { next: function next() { return e && r >= e.length && (e = void 0), { value: e && e[r++], done: !e }; } }; } throw new TypeError(_typeof(e) + " is not iterable"); }
function _regeneratorKeys(e) { var n = Object(e), r = []; for (var t in n) r.unshift(t); return function e() { for (; r.length;) if ((t = r.pop()) in n) return e.value = t, e.done = !1, e; return e.done = !0, e; }; }
function _regeneratorAsync(n, e, r, t, o) { var a = _regeneratorAsyncGen(n, e, r, t, o); return a.next().then(function (n) { return n.done ? n.value : a.next(); }); }
function _regeneratorAsyncGen(r, e, t, o, n) { return new _regeneratorAsyncIterator(_regenerator().w(r, e, t, o), n || Promise); }
function _regeneratorAsyncIterator(t, e) { function n(r, o, i, f) { try { var c = t[r](o), u = c.value; return u instanceof _OverloadYield ? e.resolve(u.v).then(function (t) { n("next", t, i, f); }, function (t) { n("throw", t, i, f); }) : e.resolve(u).then(function (t) { c.value = t, i(c); }, function (t) { return n("throw", t, i, f); }); } catch (t) { f(t); } } var r; this.next || (_regeneratorDefine2(_regeneratorAsyncIterator.prototype), _regeneratorDefine2(_regeneratorAsyncIterator.prototype, "function" == typeof Symbol && Symbol.asyncIterator || "@asyncIterator", function () { return this; })), _regeneratorDefine2(this, "_invoke", function (t, o, i) { function f() { return new e(function (e, r) { n(t, i, e, r); }); } return r = r ? r.then(f, f) : f(); }, !0); }
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { if (r) i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n;else { var o = function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); }; o("next", 0), o("throw", 1), o("return", 2); } }, _regeneratorDefine2(e, r, n, t); }
function _OverloadYield(e, d) { this.v = e, this.k = d; }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
import throttle from 'lodash.throttle';
import React from 'react';
import { AnchorNavigation } from '../AnchorNavigation/AnchorNavigation';
import { useAnchorNavigationContext } from '../AnchorNavigation/AnchorNavigationProvider';
import { Grid as BaseGrid } from '../Grid/Grid';
import { TearsheetContext } from '../Tearsheet/Tearsheet';
import { useResize } from '../_hooks/Resize';
import { useScroll } from '../_hooks/Scroll';
import { useUpdateEffect } from '../_hooks/useUpdateEffect';
import { addSubcomponents } from '../_utils/addSubcomponents';
import { mergeRefs } from '../_utils/mergeRefs';
import { pageLayoutRootDataAttr } from './PageLayout.constants';
import { animationDuration, StyledAside, StyledAsideFluidContainer, StyledAsidePanel, StyledBody, StyledContent, StyledFooter, StyledNavigation, StyledPageBanner, StyledPageBreadcrumbs, StyledPageContainer, StyledPageHeader, StyledPageMain, StyledPageTabs, StyledPageTitle } from './PageLayout.styles';
import { getBottomOffsetForFooterUseCase, getGlobalBottomOffset, getGlobalTopOffset, getIsIntersectingVertically, getRightOffset, wait } from './PageLayout.utils';
var defaultAsideIsOpen = false;
export var PageContext = /*#__PURE__*/React.createContext({
  bodyRef: /*#__PURE__*/React.createRef(),
  footerRef: /*#__PURE__*/React.createRef(),
  containerRef: /*#__PURE__*/React.createRef(),
  navigationRef: /*#__PURE__*/React.createRef(),
  aside: {
    open: function open() {
      return Promise.resolve();
    },
    close: function close() {
      return Promise.resolve();
    },
    isOpen: defaultAsideIsOpen
  }
});

// for some reason this does not appear in the deprecated in typedoc generated json, but Page.Row does
/**
 * @parent Page
 * @deprecated A wrapper around Grid, please use Grid instead. Page already sets
 * a default gutterX in context for children grid components.
 *
 * BEFORE `Page.Grid`, `Page.Row`, `Page.Column`
 *
 * AFTER `Grid` `Grid.Row` `Grid.Col`
 * @deprecatedSince 12
 */
export var Grid = function Grid(_ref) {
  var gutterX = _ref.gutterX,
    props = _objectWithoutProperties(_ref, _excluded);
  return /*#__PURE__*/React.createElement(BaseGrid, _extends({
    gutterX: gutterX !== null && gutterX !== void 0 ? gutterX : 'lg'
  }, props));
};

/**
 * @parent Page
 * @deprecated A wrapper around Grid, please use Grid instead. Page already sets
 * a default gutterX in context for children grid components.
 *
 * BEFORE `Page.Row` AFTER `Grid.Row`
 * @deprecatedSince 12
 */
export var Row = BaseGrid.Row;

/**
 * @parent Page
 * @deprecated A wrapper around Grid, please use Grid instead. Page already sets
 * a default gutterX in context for children grid components.
 *
 * BEFORE `Page.Column` AFTER `Grid.Col`
 * @deprecatedSince 12
 */
export var Column = BaseGrid.Col;
var PageHeader = /*#__PURE__*/React.forwardRef(function PageHeader(_ref2, ref) {
  var transparent = _ref2.transparent,
    props = _objectWithoutProperties(_ref2, _excluded2);
  return /*#__PURE__*/React.createElement(StyledPageHeader, _extends({
    $transparent: transparent
  }, props, {
    ref: ref
  }));
});
var PageBody = /*#__PURE__*/React.forwardRef(function PageBody(_ref3, ref) {
  var children = _ref3.children,
    props = _objectWithoutProperties(_ref3, _excluded3);
  var _React$useContext = React.useContext(PageContext),
    bodyRef = _React$useContext.bodyRef;
  var navigation;
  var content = [];
  React.Children.forEach(children, function (child) {
    if (! /*#__PURE__*/React.isValidElement(child)) return;
    if (child.type === PageBodyNavigation) {
      navigation = child;
    } else {
      content.push(child);
    }
  });
  if (!navigation) {
    return /*#__PURE__*/React.createElement(StyledBody, _extends({
      children: children
    }, props, {
      ref: mergeRefs(ref, bodyRef)
    }));
  }
  return /*#__PURE__*/React.createElement(StyledBody, _extends({}, props, {
    ref: mergeRefs(ref, bodyRef)
  }), /*#__PURE__*/React.createElement(StyledNavigation, null, navigation), /*#__PURE__*/React.createElement(StyledContent, null, content));
});
export var PageBodyNavigation = /*#__PURE__*/React.forwardRef(function (_ref4, ref) {
  var _props$sections$lengt, _props$sections, _props$sections2, _props$selected, _props$onSelect;
  var _ref4$minSections = _ref4.minSections,
    minSections = _ref4$minSections === void 0 ? 2 : _ref4$minSections,
    props = _objectWithoutProperties(_ref4, _excluded4);
  var _React$useContext2 = React.useContext(PageContext),
    navigationRef = _React$useContext2.navigationRef;
  var _useAnchorNavigationC = useAnchorNavigationContext(),
    sections = _useAnchorNavigationC.sections,
    selected = _useAnchorNavigationC.selected,
    onSelect = _useAnchorNavigationC.onSelect;
  var sectionsLength = (_props$sections$lengt = (_props$sections = props.sections) === null || _props$sections === void 0 ? void 0 : _props$sections.length) !== null && _props$sections$lengt !== void 0 ? _props$sections$lengt : sections.length;
  if (sectionsLength < minSections) return null;
  return /*#__PURE__*/React.createElement(AnchorNavigation, _extends({
    ref: mergeRefs(ref, navigationRef),
    sections: (_props$sections2 = props.sections) !== null && _props$sections2 !== void 0 ? _props$sections2 : sections,
    selected: (_props$selected = props.selected) !== null && _props$selected !== void 0 ? _props$selected : selected,
    onSelect: (_props$onSelect = props.onSelect) !== null && _props$onSelect !== void 0 ? _props$onSelect : onSelect
  }, props));
});
var PageFooter = /*#__PURE__*/React.forwardRef(function PageFooter(props, ref) {
  var _React$useContext3 = React.useContext(PageContext),
    bodyRef = _React$useContext3.bodyRef,
    footerRef = _React$useContext3.footerRef,
    aside = _React$useContext3.aside;
  var _React$useContext4 = React.useContext(TearsheetContext),
    addListener = _React$useContext4.addListener;
  var _React$useState = React.useState(false),
    _React$useState2 = _slicedToArray(_React$useState, 2),
    isIntersectingWithBody = _React$useState2[0],
    setIsIntersectingWithBody = _React$useState2[1];
  function calculateIntersections() {
    if (!footerRef.current || !bodyRef.current) {
      return;
    }
    setIsIntersectingWithBody(getIsIntersectingVertically(bodyRef.current, footerRef.current));
  }
  React.useEffect(function () {
    var _bodyRef$current;
    var tabWasPressed = false;
    var onActiveElementChange = function onActiveElementChange() {
      if (tabWasPressed && footerRef.current && document.activeElement && getIsIntersectingVertically(document.activeElement, footerRef.current)) {
        document.activeElement.scrollIntoView();
      }
    };
    var onKeyDown = function onKeyDown(e) {
      if (e.code === 'Tab') {
        tabWasPressed = true;
        // setTimeout is added to the end of async queue
        // after all already attached eventListeners
        // `tabWasPressed` marked as `false` after all events
        // which can be triggered by pressing Tab
        setTimeout(function () {
          tabWasPressed = false;
        }, 0);
      }
    };
    (_bodyRef$current = bodyRef.current) === null || _bodyRef$current === void 0 ? void 0 : _bodyRef$current.addEventListener('focusin', onActiveElementChange);
    document.addEventListener('keydown', onKeyDown, true);
    return function () {
      var _bodyRef$current2;
      (_bodyRef$current2 = bodyRef.current) === null || _bodyRef$current2 === void 0 ? void 0 : _bodyRef$current2.removeEventListener('focusin', onActiveElementChange);
      document.removeEventListener('keydown', onKeyDown, true);
    };
  }, []);
  React.useEffect(function () {
    return addListener('scroll', calculateIntersections);
  }, []);
  React.useEffect(calculateIntersections, []);
  useScroll({
    onScroll: calculateIntersections
  });
  useResize({
    onResize: calculateIntersections
  });
  return /*#__PURE__*/React.createElement(StyledFooter, _extends({}, props, {
    $isAsideOpen: aside.isOpen,
    $hasShadow: isIntersectingWithBody,
    "data-sticky": isIntersectingWithBody ? 'sticky' : '',
    ref: mergeRefs(ref, footerRef)
  }));
});
var PageAside = /*#__PURE__*/React.forwardRef(function PageAside(_ref5, ref) {
  var children = _ref5.children,
    controlledIsOpen = _ref5.open,
    props = _objectWithoutProperties(_ref5, _excluded5);
  var _React$useContext5 = React.useContext(PageContext),
    _React$useContext5$as = _React$useContext5.aside,
    contextIsOpen = _React$useContext5$as.isOpen,
    open = _React$useContext5$as.open,
    close = _React$useContext5$as.close;
  var _React$useContext6 = React.useContext(TearsheetContext),
    tearsheetPlacement = _React$useContext6.placement,
    addTearsheetListener = _React$useContext6.addListener;
  var _React$useContext7 = React.useContext(PageContext),
    footerRef = _React$useContext7.footerRef,
    containerRef = _React$useContext7.containerRef;
  var innerRef = React.useRef(null);
  var _React$useState3 = React.useState(null),
    _React$useState4 = _slicedToArray(_React$useState3, 2),
    topOffset = _React$useState4[0],
    setTopOffset = _React$useState4[1];
  var _React$useState5 = React.useState(0),
    _React$useState6 = _slicedToArray(_React$useState5, 2),
    bottomOffset = _React$useState6[0],
    setBottomOffset = _React$useState6[1];
  var _React$useState7 = React.useState(0),
    _React$useState8 = _slicedToArray(_React$useState7, 2),
    rightOffset = _React$useState8[0],
    setRightOffset = _React$useState8[1];
  var initialIsOpen = controlledIsOpen !== null && controlledIsOpen !== void 0 ? controlledIsOpen : contextIsOpen;
  var _React$useState9 = React.useState(initialIsOpen ? 'open' : 'closed'),
    _React$useState0 = _slicedToArray(_React$useState9, 2),
    animationStatus = _React$useState0[0],
    setAnimationStatus = _React$useState0[1];
  var _React$useState1 = React.useState(initialIsOpen),
    _React$useState10 = _slicedToArray(_React$useState1, 2),
    isOpen = _React$useState10[0],
    setIsOpen = _React$useState10[1];
  var throttledToggle = React.useCallback(throttle(function (isOpen) {
    if (isOpen) {
      open();
    } else {
      close();
    }
  },
  // wait just a little longer than the animation duration to avoid odd blinking
  animationDuration.panel + 100, {
    trailing: true
  }), []);
  React.useEffect(function () {
    throttledToggle(controlledIsOpen);
  }, [controlledIsOpen, throttledToggle]);
  React.useEffect(function () {
    setIsOpen(contextIsOpen);
  }, []);
  useUpdateEffect(function () {
    ;
    _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
      return _regeneratorRuntime().wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            if (!contextIsOpen) {
              _context.next = 9;
              break;
            }
            setIsOpen(true);

            // allow browsers to recalculate the layout
            _context.next = 4;
            return wait(0);
          case 4:
            setAnimationStatus('opening');
            _context.next = 7;
            return wait(animationDuration.panel);
          case 7:
            setAnimationStatus('open');
            return _context.abrupt("return");
          case 9:
            setAnimationStatus('closing');
            _context.next = 12;
            return wait(animationDuration.panel);
          case 12:
            setAnimationStatus('closed');
            setIsOpen(false);
          case 14:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }))();
  }, [contextIsOpen]);
  function calculateOffsets() {
    calculateHorizontalOffsets();
    calculateVerticalOffsets();
  }
  function calculateHorizontalOffsets() {
    if (!containerRef.current) {
      return;
    }
    setRightOffset(getRightOffset(containerRef.current));
  }
  function calculateVerticalOffsets() {
    if (!innerRef.current || !containerRef.current) {
      return;
    }
    var globalTopOffset = getGlobalTopOffset(containerRef.current);
    setTopOffset(globalTopOffset);
    var globalBottomOffset = getGlobalBottomOffset(containerRef.current);
    setBottomOffset(globalBottomOffset);
    if (!footerRef.current) {
      return;
    }
    var bottomOffset = getBottomOffsetForFooterUseCase(footerRef.current, globalBottomOffset);
    if (bottomOffset !== null) {
      setBottomOffset(bottomOffset);
    }
  }
  useScroll({
    onScroll: calculateOffsets
  });
  useResize({
    onResize: calculateOffsets
  });
  React.useEffect(function () {
    if (tearsheetPlacement) {
      return addTearsheetListener('afterShow', calculateOffsets);
    }
    calculateOffsets();
  }, []);
  useUpdateEffect(calculateOffsets, [contextIsOpen, animationStatus]);
  var asideOpen = ['open', 'opening'].includes(animationStatus);
  var asideClosed = ['closed', 'closing'].includes(animationStatus);
  return isOpen ? /*#__PURE__*/React.createElement(StyledAside, _extends({}, props, {
    $open: asideOpen,
    $closed: asideClosed,
    ref: mergeRefs(ref, innerRef, calculateOffsets)
  }), /*#__PURE__*/React.createElement(StyledAsideFluidContainer, {
    $open: asideOpen,
    $closed: asideClosed
  }, /*#__PURE__*/React.createElement(StyledAsidePanel, {
    $offsetTop: topOffset,
    $rightOffset: rightOffset,
    $minusHeight: (topOffset !== null && topOffset !== void 0 ? topOffset : 0) + bottomOffset,
    $closing: animationStatus === 'closing',
    $opening: animationStatus === 'opening',
    $closed: animationStatus === 'closed',
    $altAnimation: tearsheetPlacement === 'left'
  }, children))) : null;
});
var PageContainer = /*#__PURE__*/React.forwardRef(function PageContainer(props, ref) {
  var _React$useState11 = React.useState(defaultAsideIsOpen),
    _React$useState12 = _slicedToArray(_React$useState11, 2),
    isAsideOpen = _React$useState12[0],
    setIsAsideOpen = _React$useState12[1];
  var openAside = function openAside() {
    setIsAsideOpen(true);
    return wait(animationDuration.panel);
  };
  var closeAside = function closeAside() {
    setIsAsideOpen(false);
    return wait(animationDuration.panel);
  };
  var containerRef = React.useRef(null);
  var bodyRef = React.useRef(null);
  var navigationRef = React.useRef(null);
  var footerRef = React.useRef(null);
  return /*#__PURE__*/React.createElement(PageContext.Provider, {
    value: {
      bodyRef: bodyRef,
      footerRef: footerRef,
      containerRef: containerRef,
      navigationRef: navigationRef,
      aside: {
        open: openAside,
        close: closeAside,
        isOpen: isAsideOpen
      }
    }
  }, /*#__PURE__*/React.createElement(StyledPageContainer, _extends({
    "data-core-react": "page"
  }, props, {
    ref: mergeRefs(ref, containerRef)
  })));
});
var PageMain = /*#__PURE__*/React.forwardRef(function PageMain(props, ref) {
  var _React$useContext8 = React.useContext(TearsheetContext),
    tearsheetPlacement = _React$useContext8.placement;
  var attrs = _defineProperty({}, pageLayoutRootDataAttr, true);
  return /*#__PURE__*/React.createElement(Grid, {
    gutterX: "lg"
  }, /*#__PURE__*/React.createElement(StyledPageMain, _extends({}, props, attrs, {
    ref: ref,
    $tearsheetPlacement: tearsheetPlacement
  })));
});
var PageBreadcrumbs = /*#__PURE__*/React.forwardRef(function PageBreadcrumbs(props, ref) {
  return /*#__PURE__*/React.createElement(StyledPageBreadcrumbs, _extends({
    ref: ref
  }, props));
});
var PageBanner = /*#__PURE__*/React.forwardRef(function PageBanner(props, ref) {
  return /*#__PURE__*/React.createElement(StyledPageBanner, _extends({
    ref: ref
  }, props));
});
var PageTitle = /*#__PURE__*/React.forwardRef(function PageTitle(props, ref) {
  return /*#__PURE__*/React.createElement(StyledPageTitle, _extends({
    ref: ref
  }, props));
});
var PageTabs = /*#__PURE__*/React.forwardRef(function PageTabs(props, ref) {
  return /*#__PURE__*/React.createElement(StyledPageTabs, _extends({
    ref: ref
  }, props));
});
Grid.displayName = 'Page.Grid';
PageHeader.displayName = 'Page.Header';
PageBanner.displayName = 'Page.Banner';
PageBreadcrumbs.displayName = 'Page.Breadcrumbs';
PageTitle.displayName = 'Page.Title';
PageTabs.displayName = 'Page.Tabs';
PageBody.displayName = 'Page.Body';
PageFooter.displayName = 'Page.Footer';
PageAside.displayName = 'Page.Aside';
PageContainer.displayName = 'Page';
PageMain.displayName = 'Page.Main';

/**
  Building block elements for layout that should be used to build a common skeleton of a page.
  - Page
    - Page.Main
      - Page.Header
        - Page.Breadcrumbs
          - Breadcrumbs
        - Page.Banner
          - Banner
        - Page.Title
          - Title or H1
        - Page.Tabs
          - Tabs
      - Page.Body
      - Page.Footer
    - Page.Aside
Other helpers, such as Page.Grid, Page.Row and Page.Column are thin wrappers over Grid components and share the same API.
 */
export var Page = addSubcomponents({
  Header: PageHeader,
  Banner: PageBanner,
  Breadcrumbs: PageBreadcrumbs,
  Title: PageTitle,
  Tabs: PageTabs,
  Footer: PageFooter,
  Body: PageBody,
  Main: PageMain,
  Aside: PageAside,
  // Grid utilities
  /**
   * @deprecated A wrapper around Grid, please use Grid instead. Page already sets
   * a default gutterX in context for children grid components.
   *
   * BEFORE `Page.Grid` AFTER `Grid` (or `Grid gutterX="lg"`)
   * @deprecatedSince 12
   */
  Grid: Grid,
  /**
   * @deprecated A wrapper around Grid, please use Grid instead. Page already sets
   * a default gutterX in context for children grid components.
   *
   * BEFORE `Page.Column` AFTER `Grid.Col`
   * @deprecatedSince 12
   */
  Column: Column,
  /**
   * @deprecated A wrapper around Grid, please use Grid instead. Page already sets
   * a default gutterX in context for children grid components.
   *
   * BEFORE `Page.Row` AFTER `Grid.Row`
   * @deprecatedSince 12
   */
  Row: Row
}, PageContainer);
//# sourceMappingURL=PageLayout.js.map