import { __assign } from "tslib";
import React from "react";
import ReactDOM from "react-dom";
import { LIGHT_THEME } from "../Pallette/themes";
import ThemeProvider from "../ThemeProvider/ThemeProvider";
import Banner from "./Banner";
export var bannerShow = function (property, theme, idContainer) {
    var container = getContainerBanner(property.type, idContainer);
    var bannerClose = function () {
        ReactDOM.unmountComponentAtNode(container);
        container.remove();
    };
    var handlePrimaryClick = function () {
        var _a;
        (_a = property.onPrimaryClick) === null || _a === void 0 ? void 0 : _a.call(property);
        bannerClose();
    };
    ReactDOM.render(React.createElement(ThemeProvider, { theme: theme || LIGHT_THEME },
        React.createElement(Banner, __assign({ onPrimaryClick: handlePrimaryClick }, property))), container);
    return bannerClose;
};
export var getContainerBanner = function (type, idContainer) {
    var _a;
    var container = document.createElement("div");
    if (idContainer) {
        var root = document.getElementById(idContainer);
        if (type === "shifting") {
            root === null || root === void 0 ? void 0 : root.prepend(container);
        }
        else {
            root === null || root === void 0 ? void 0 : root.appendChild(container);
        }
    }
    else if (type === "shifting") {
        (_a = document.body) === null || _a === void 0 ? void 0 : _a.prepend(container);
    }
    else {
        document.body.appendChild(container);
    }
    return container;
};
