/**
 * (c) by aheadware.com
 */

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

app.state.Support = function()
{
    var state = app.core.StateManager.createState( 'support' );

    state.onEnter = function( p )
    {
        let $content = app.core.View.getContent();

        app.gui.PageLoader.show();

        app.core.View.setContent(
            app.core.View.getTemplate( 'support' )
        );

        $content.find( '[data-id="btn-send"]' ).first().click( function()
        {
            let $form = $content.find( '[data-id="form-support"]' ).first(),
                isValid = app.util.Form.bootstrapValidate( $form );

            if ( isValid )
            {
                app.gui.PageLoader.show();

                app.core.Rpc.call(
                    'Content',
                    'requestSupport',
                    {
                        message : app.util.Helper.trim( $form.find( '[data-id="textarea-message"]' ).first().val() ),
                        reason : $form.find( '[data-id="select-reason"]' ).first().val()
                    },
                    function()
                    {
                        app.core.View.toastSuccess( _lc( 'SUPPORT_IS_ON_THE_WAY' ) );
                        app.core.Controller.redirect( '#/home' );
                        app.gui.PageLoader.hide();
                    }
                )
            }
        });

        setTimeout( function()
        {
            app.gui.PageLoader.hide();

        }, 1500 );
    };

    return state;
};