"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BottomPanePortal = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const nano_theme_1 = require("nano-theme");
const EntangledPortal_1 = require("../../../../components/EntangledPortal");
const spanClass = (0, nano_theme_1.rule)({
    pe: 'none',
});
const gap = 4;
const position = (base, dest) => {
    let x = base.x - (dest.width >> 1);
    let y = base.y;
    if (x < gap)
        x = gap;
    else if (x + dest.width + gap > window.innerWidth)
        x = window.innerWidth - dest.width - gap;
    const { scrollY } = window;
    const body = document.body;
    const html = document.documentElement;
    const pageHeight = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
    if (base.y + dest.height + scrollY > pageHeight)
        y = base.y - (base.y + dest.height + scrollY - pageHeight);
    return [x, y];
};
const span = { className: spanClass };
const entangledProps = {
    position,
    span,
};
const BottomPanePortal = ({ children }) => {
    return React.createElement(EntangledPortal_1.EntangledPortal, { ...entangledProps }, children);
};
exports.BottomPanePortal = BottomPanePortal;
//# sourceMappingURL=BottomPanePortal.js.map