// Copyright (c) 2009-2026 SAP SE, All Rights Reserved
/**
 * @fileOverview Utility functions for FioriElements.
 */
sap.ui.define([
    "sap/base/util/deepExtend",
    "sap/ushell/Container",
    "sap/ushell/utils",
    "sap/ushell/utils/UrlParsing"
], (
    deepExtend,
    Container,
    ushellUtils,
    UrlParsing
) => {
    "use strict";

    /**
     * @alias sap.ushell.api.FioriElements
     * @namespace
     *
     * @since 1.144.0
     * @private
     * @ui5-restricted sap.suite.ui.generic, sap.fe.v2
     */
    const FioriElements = {};

    /**
     * FioriElements applies the custom "dirty state" handling before navigation.
     * On explace navigation the dirty state handling is not required.
     *
     * @param {sap.ushell.services.Navigation.Target} oTarget The navigation target.
     * @returns {Promise<boolean>} Whether the navigation is explace or not
     *
     * @since 1.144.0
     * @private
     * @ui5-restricted sap.suite.ui.generic, sap.fe.v2
     */
    FioriElements.isExplaceNavigation = async function (oTarget) {
        const oArgsClone = deepExtend({}, oTarget);
        const sHashFragment = UrlParsing.constructShellHash(oArgsClone);
        const NavTargetResolutionInternal = await Container.getServiceAsync("NavTargetResolutionInternal");
        const oResolvedHashFragment = await ushellUtils.promisify(NavTargetResolutionInternal.resolveHashFragment(`#${sHashFragment}`));

        const bIsExplaceNavigation = oResolvedHashFragment.targetNavigationMode === "explace" || oResolvedHashFragment.targetNavigationMode === "frameless";

        return bIsExplaceNavigation;
    };

    return FioriElements;
});
