/**
 * Created by Benny on 12.10.2014.
 */

"use strict";

var TB = TB || {};
TB.Control = TB.Control || {};

TB.Control.Content =  {
    help : function() {
        TB.GUI.showLoader();
        var page = new TB.Page( 'help' );
        TB.GUI.hideLoader();
        TB.GUI.show(page, {});
    },

    about : function() {
        TB.GUI.showLoader();
        var page = new TB.Page( 'about' );
        TB.GUI.hideLoader();
        TB.GUI.show(page, { version: TB.Client.VERSION });
    },

    pricing: function() {
        if ( TB.Env.isNativeMobile() )
        {
            TB.Ext.Notification.show( 'Seite nicht verfügbar auf mobilen Endgeräten', TB.Ext.Notification.TYPE_INFO );
            return;
        }
        TB.GUI.showLoader();
        TB.Service.request(
            'Team',
            'load',
            {} ,
            function( data ) {

                var page = new TB.Page( 'pricing' );
                TB.GUI.hideLoader();
                TB.GUI.show( page, {team: data.team, numProfiles : data.profiles.length } );
                /*
                page.$container.find( '.btn-premium' ).click( function() {
                    TB.Ext.Alert.infoPremium();
                });
                */
        });
    },

    support : function( params ) {
        var page = new TB.Page( 'support' ),
            origin = ( params && params.o ) ? params.o : null;
        TB.GUI.show( page, { o : origin } );
        page.$container.find( '#btn_support_create_cancel').click( function() {
            TB.Controller.do('News', 'index');
        });
        page.$container.find( '#btn_support_create_submit').click( function() {
            TB.Service.request(
                'Content',
                'requestSupport',
                {
                    'supportcategory' : page.$container.find( 'select[name="support-category"]').val(),
                    'supportmessage' : page.$container.find( '#supportmessage').val()
                },
                function(res) {
                    TB.Ext.Notification.show( 'Wir haben deine Supportanfrage erhalten und werden uns so bald wie möglich bei dir melden.', TB.Ext.Notification.TYPE_SUCCESS );
                    TB.Controller.do( 'News', 'index' );
                }
            );
            return false;
        });
    },


    offline : function() {
        TB.GUI.hideLoader();
        var page = new TB.Page('content'),
            content = {
                content: '<span class="label label-danger">Du scheinst gerade kein Internet zu haben.</span>',
                page_title: 'Offline'
            };
        TB.GUI.show(page, { content: content });
    }
};