// Copyright (c) 2009-2026 SAP SE, All Rights Reserved

/**
 * @fileoverview This file contains the UI5ApplicationContainerRenderer.
 * It handles the rendering of UI5-based application containers.
 */
sap.ui.define([
    "sap/ui/core/Renderer",
    "sap/ushell/appIntegration/ApplicationContainerRenderer"
], (
    Renderer,
    ApplicationContainerRenderer
) => {
    "use strict";

    /**
     * UI5ApplicationContainerRenderer extends the base ApplicationContainerRenderer.
     *
     * @alias sap.ushell.appIntegration.UI5ApplicationContainerRenderer
     * @namespace
     * @extends sap.ushell.appIntegration.ApplicationContainerRenderer
     *
     * @private
     */
    const UI5ApplicationContainerRenderer = Renderer.extend(ApplicationContainerRenderer);

    UI5ApplicationContainerRenderer.apiVersion = 2;

    /**
     * Renders the UI5 application container.
     * Delegates to the base renderer if not ready, otherwise renders the component container.
     *
     * @param {sap.ui.core.RenderManager} oRenderManager The render manager.
     * @param {sap.ushell.appIntegration.UI5ApplicationContainer} oContainer The container to render.
     *
     * @private
     */
    UI5ApplicationContainerRenderer.render = function (oRenderManager, oContainer) {
        if (!oContainer.getReadyForRendering()) {
            ApplicationContainerRenderer.render(oRenderManager, oContainer);
            return;
        }

        const oChild = oContainer.getAggregation("child");

        if (!oChild) {
            return;
        }

        oRenderManager.openStart("div", oContainer);
        oRenderManager.accessibilityState(oContainer);
        oRenderManager.attr("data-help-id", oContainer.getDataHelpId());
        oRenderManager.attr("data-sap-ushell-active", oContainer.getActive());
        oRenderManager.attr("data-sap-ushell-initial-app-id", oContainer.getInitialAppId());
        oRenderManager.attr("data-sap-ushell-current-app-id", oContainer.getCurrentAppId());
        oRenderManager.attr("data-sap-ushell-stateful-type", oContainer.getStatefulType());
        oRenderManager.attr("data-sap-ushell-framework-id", oContainer.getFrameworkId());
        oRenderManager.class("sapUShellApplicationContainer");
        oRenderManager.style("height", oContainer.getHeight());
        oRenderManager.style("width", oContainer.getWidth());
        oRenderManager.openEnd();

        oRenderManager.renderControl(oChild);

        oRenderManager.close("div");

        // mark the rendering as complete, this will suppress any further invalidation
        oContainer.setRenderComplete(true);
    };

    return UI5ApplicationContainerRenderer;
});
