"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PortalRoot = void 0;
const tslib_1 = require("tslib");
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const react_1 = tslib_1.__importDefault(require("react"));
const ide_core_browser_1 = require("@opensumi/ide-core-browser");
const common_1 = require("@opensumi/ide-theme/lib/common");
const extension_service_1 = require("../../common/extension.service");
const PortalRoot = (props) => {
    var _a;
    const [themeType, setThemeType] = react_1.default.useState(null);
    const extensionService = (0, ide_core_browser_1.useInjectable)(extension_service_1.AbstractViewExtProcessService);
    const themeService = (0, ide_core_browser_1.useInjectable)(common_1.IThemeService);
    react_1.default.useEffect(() => {
        const disposables = new ide_core_browser_1.DisposableCollection();
        themeService.getCurrentTheme().then((res) => setThemeType(res.type));
        disposables.push(themeService.onThemeChange((e) => {
            if (e.type && e.type !== themeType) {
                setThemeType(e.type);
            }
        }));
        return disposables.dispose.bind(disposables);
    }, []);
    const OriginalComponent = props.original;
    return (react_1.default.createElement(OriginalComponent, { ...props.otherProps, className: (0, classnames_1.default)((_a = props.otherProps) === null || _a === void 0 ? void 0 : _a.className, (0, common_1.getThemeTypeSelector)(themeType)), getContainer: () => {
            const portalRoot = extensionService.getPortalShadowRoot(props.extensionId);
            return portalRoot;
        } }));
};
exports.PortalRoot = PortalRoot;
//# sourceMappingURL=extension-portal-root.js.map