"use strict";
exports.__esModule = true;
exports.PortalWithTheme = exports.usePortalContext = void 0;
var tslib_1 = require("tslib");
var react_1 = (0, tslib_1.__importStar)(require("react"));
var react_dom_1 = (0, tslib_1.__importDefault)(require("react-dom"));
var useForkRef_1 = require("../../hooks/useForkRef/useForkRef");
var Theme_1 = require("../Theme/Theme");
var PortalWithThemeContext_1 = require("./PortalWithThemeContext/PortalWithThemeContext");
exports.usePortalContext = PortalWithThemeContext_1.usePortalContext;
exports.PortalWithTheme = react_1["default"].forwardRef(function (_a, ref) {
    var children = _a.children, _b = _a.container, container = _b === void 0 ? window.document.body : _b, rest = (0, tslib_1.__rest)(_a, ["children", "container"]);
    var addRefs = (0, PortalWithThemeContext_1.usePortalContext)().addRefs;
    var themeRef = (0, react_1.useRef)(null);
    (0, react_1.useEffect)(function () {
        addRefs && addRefs([themeRef]);
    }, [themeRef]);
    return react_dom_1["default"].createPortal(react_1["default"].createElement(PortalWithThemeContext_1.PortalWithThemeProvider, null,
        react_1["default"].createElement(Theme_1.Theme, (0, tslib_1.__assign)({ ref: (0, useForkRef_1.useForkRef)([themeRef, ref]) }, rest), children)), container);
});
