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

"use strict";

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

app.core.Controller = {

    init: function () {
        AHDF.Router.on( app.core.Controller.process );
        AHDF.Router.enable();
    }

    ,

    process : function( ctrl, action, params ) {

        var action = ( action ) ? action.toLowerCase() : 'index',
            ctrl = ctrl;

        // Handling default actions
        if ( !ctrl ) {
            if ( !app.core.User.isLoggedIn() ) {
                ctrl = 'auth';
            } else {
                ctrl = 'dashboard';
            }
        }

        ctrl = AHDF.Util.capitalizeFirstLetter( ctrl );

        // @todo Add ACL checks
        if ( app.ctrl[ ctrl ] && app.ctrl[ ctrl ][ action ] ) {
            app.ctrl[ ctrl ][ action ]( params );
        } else {
            // 404
            console.log( 404 );
        }
    }

    ,

    redirect : function( ctrl, action, params ) {
        AHDF.Router.setHash( ctrl, action, params );
    }
};