/**
 * Created by Benny on 29.03.2016.
 */

"use strict";

var app = app || {};
app.core = app.core || {};

app.core.View = {

    $body : null,
    $main : null,

    init : function() {
        this.$body = $( 'body' );
        this.$body.append( AHDF.Tmpl.get( 'tpl_mainlayout' ) );
        this.$main = this.$body.find( '#wrapper' );

        // Init mainlayout events
        $('.navbar-minimalize').click(function () {
            $("body").toggleClass("mini-navbar");
            SmoothlyMenu();
        });
    }

    ,

    showLogin : function() {
        this.$main.hide();
        this.$body.addClass( 'gray-bg' );
        this.$body.append( AHDF.Tmpl.get( 'tpl_login' ) );
    }

    ,

    hideLogin : function() {
        this.$body.removeClass( 'gray-bg' );
        $( '#container-login').remove();
        this.$main.show();
    }

    ,

    showPage : function( page, params ) {
        if ( AHDF.StateManager.exitCurrent() ) {
            this.setTitle( page.title );
            this.setContent( page.content);
            AHDF.StateManager.enterNew( page, params );
            this.$main.show();
        }
    }

    ,

    setTitle : function( title ) {
        this.$main.find( 'h2[data-id="content-title"]').html( title );
    }

    ,

    setContent : function( content ) {
        this.$main.find( 'div.wrapper-content').html( content);
    }

    ,

    createPage : function( params ) {
        var page = AHDF.StateManager.createState(),
            params = params || {},
            breadcrumb = params.breadcrumb || null;

        // State specific
        page.onEnter = params.onEnter || null;
        page.onExit = params.onExit || null;

        // Add page specific data to state
        page.title = params.title || null;
        page.breadcrumb = params.breadcrumb || null;
        page.content = params.content || '';

        return page;
    }

};