/*
 * app.nav.js
 * Handle dynamic navigation related operations
 * toobar, menu, fab etc
 *
*/

/*jslint          browser : true,  continue : true,
  devel  : true,  indent  : 2,     maxerr   : 50,
  newcap : true,  nomen   : true,  plusplus : true,
  regexp : true,  sloppy  : true,  vars     : false,
  white  : true
*/
/*global $, app */

app.nav = (function () {
    var contextClear, contextAddButton, contextAddLink, backUrl, backRemove, moreMenuInitialized, 
    setContextTitle, setSelectedMenuItem;



    // ///////////////////////////////////////////
    // //Set context menu title
    // //
    // var setContextTitle = function (title) {
    //     $("#gz-context-title").html(title + "...");
    // }

    ////////////////////////////////////////////////
    //Clear the contents of the context menu (reset it)
    //
    contextClear = function () {
        $("#gz-context-group").empty();
        $("#gz-context-group").addClass("invisible");

    };



    ////////////////////////////////////////////////
    //Add a non nav button item to the context menu 
    //
    contextAddButton = function (id, title, icon, clickHandler) {
        var $group=$("#gz-context-group");
        $group.removeClass("invisible");

        var iconClass = '';
        if (icon) {
            iconClass = "mdi mdi-" + icon;
        }
       $group.append(
            '<button type="button" id="' + id + '" class="btn btn-outline-dark ' + iconClass + '" href="#">' + title + '</a>'
        );       
        
        $('#' + id).bind('click', clickHandler);

    };

//  <button type="button" class="btn btn-outline-dark mdi mdi-key">Left</button>

    ////////////////////////////////////////////////
    //Add an url item to the context menu handling 
    //phone vs larger sizes
    //
    contextAddLink = function (url, title, icon) {
        var $group=$("#gz-context-group");
        $group.removeClass("invisible");
        var iconClass = '';
        if (icon) {
            iconClass = "mdi mdi-" + icon;
        }
        $group.append(
            '<a class="btn btn-outline-dark ' + iconClass + '" href="#!/' + encodeURI(url) + '">' + title + '</a>'
        );
    };


    ////////////////////////////////////////////////
    //Set the active class on the selected menu item
    //
    setSelectedMenuItem = function (selectedMenuItem) {
        $(".nav-item").removeClass("active");
        if (selectedMenuItem) {
            $("#" + selectedMenuItem).addClass("active");
        }


    };

   



    return {
        contextClear: contextClear,
        contextAddButton: contextAddButton,
        contextAddLink: contextAddLink, 
        setContextTitle: setContextTitle,
        setSelectedMenuItem: setSelectedMenuItem

    };
}());
