"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtensionWebviewView = exports.WebviewViewShouldShowEvent = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const ide_core_browser_1 = require("@opensumi/ide-core-browser");
const common_1 = require("../../common");
class WebviewViewShouldShowEvent extends ide_core_browser_1.BasicEvent {
}
exports.WebviewViewShouldShowEvent = WebviewViewShouldShowEvent;
const ExtensionWebviewView = ({ viewId }) => {
    const containerRef = react_1.default.useRef(null);
    const eventBus = (0, ide_core_browser_1.useInjectable)(ide_core_browser_1.IEventBus);
    const extensionService = (0, ide_core_browser_1.useInjectable)(common_1.ExtensionService);
    react_1.default.useEffect(() => {
        const cancellationTokenSource = new ide_core_browser_1.CancellationTokenSource();
        const disposer = new ide_core_browser_1.Disposable({ dispose: () => cancellationTokenSource.cancel() });
        extensionService.eagerExtensionsActivated.promise.then(() => {
            if (cancellationTokenSource.token.isCancellationRequested) {
                return;
            }
            if (containerRef.current) {
                eventBus.fire(new WebviewViewShouldShowEvent({
                    viewType: viewId,
                    container: containerRef.current,
                    title: '', // mainLayoutService.getTabbarHandler(viewId).titl
                    cancellationToken: cancellationTokenSource.token,
                    disposer,
                }));
            }
        });
        return () => {
            disposer.dispose();
        };
    }, []);
    return (react_1.default.createElement("div", { style: { height: '100%', width: '100%', position: 'relative' }, className: 'webview-view-component', ref: containerRef }));
};
exports.ExtensionWebviewView = ExtensionWebviewView;
//# sourceMappingURL=extension-webview-view.js.map