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

/**
 * @fileOverview Main Controller for the Navigation Sample Application.
 *
 * Handles the main view with IconTabBar navigation between Overview and Navigation tabs.
 *
 * @since 1.147
 */
sap.ui.define([
    "sap/ui/core/mvc/Controller"
], (
    Controller
) => {
    "use strict";

    /**
     * Main controller managing the IconTabBar and route synchronization.
     *
     * @class
     * @extends sap.ui.core.mvc.Controller
     * @alias sap.ushell.sandbox.NavigationSample.controller.Main
     * @since 1.147
     * @private
     */
    return Controller.extend("sap.ushell.sandbox.NavigationSample.controller.Main", {

        /**
         * Initializes route matching to sync the IconTabBar selection.
         *
         * @private
         */
        onInit: function () {
            this.getOwnerComponent().getRouter().attachRouteMatched((oEvent) => {
                const sFilter = oEvent.getParameter("name");
                this.byId("mainTabs").setSelectedKey(sFilter);
            });
        },

        /**
         * Handles IconTabFilter selection and navigates to the corresponding route.
         *
         * @param {sap.ui.base.Event} oEvent - The select event from IconTabBar
         * @private
         */
        onIconTabFilterSelected: function (oEvent) {
            const sKey = oEvent.getParameter("key");
            this.getOwnerComponent().getRouter().navTo(sKey);
        }
    });
});
