<div class="row">
    <div class="col-xs-10">
        <h3>News</h3>
    </div>
    <div class="col-xs-2">
        <h3>
            <button id="btn-coach-help"
                    class="btn btn-link pull-right coach-help">
                <i class="glyphicon glyphicon-question-sign"></i>&nbsp;Hilfe
            </button>
        </h3>
    </div>
</div>

<% if ( TB.Env.isWebAndroid() ) {   %>

<div class="row">
    <div class="col-md-12">
        <div class="well well-lg text-center">
            <a href="https://play.google.com/store/apps/details?id=de.tbuddy.androidapp" target="_blank">
                <img class="img-responsive" style="margin: auto" src="img/tbuddy-app-banner-android.png" />
            </a>
        </div>
    </div>
</div>

<% } else if ( TB.Env.isWebIOS() ) {    %>

<div class="row">
    <div class="col-md-12">
        <div class="well well-lg text-center">
            <a href="https://itunes.apple.com/de/app/tbuddy-einfach-furs-team/id1078186571?mt=8" target="_blank">
                <img class="img-responsive" style="margin: auto" src="img/tbuddy-app-banner-ios.png" />
            </a>
        </div>
    </div>
</div>

<% }    %>


<% if ( data.news.length > 0 ) {    %>
    <%
        var lastDate = new Date(0);
        data.news = data.news.reverse();
    %>

<!--
        <div class="row">
            <div class="col-md-12 text-center">
                <a href="https://play.google.com/store/apps/details?id=de.tbuddy.androidapp&utm_source=global_co&utm_medium=prtnr&utm_content=Mar2515&utm_campaign=PartBadge&pcampaignid=MKT-AC-global-none-all-co-pr-py-PartBadges-Oct1515-1">
                    <img class="img-responsive" alt="Get it on Google Play" src="img/tbuddy-app-banner-android.png" />
                </a>
            </div>
        </div>
-->
        <% for ( var i=0; i < data.news.length; i++ ) { %>

            <%
                var currentDate = TB.Utils.getDateFromUnixTimestamp( data.news[i].created ), txtParams = [], authorProfileName;

                for ( var pi=0; pi < data.profiles.length; pi++ ) {
                    if ( data.profiles[pi].id == data.news[i].author_profile_id ) {
                        authorProfileName = TB.GUI.playerName ( data.profiles[pi] );
                        break;
                    }
                }

                switch( data.news[i].ref_content_type ) {
                    case 'appointment':
                        txtParams[0] = '<span class="label">' + authorProfileName + '</span>';
                        if ( data.news[i].txt_key_params_sr.serial_id == "0" ) {
                            txtParams[1] = 'Serientermin';
                        } else {
                            txtParams[1] = data.news[i].txt_key_params_sr.subject ? 'Termin' : 'Spieltermin';
                        }
                        txtParams[2] = data.news[i].txt_key_params_sr.subject ? '<span class="label label-primary">' + data.news[i].txt_key_params_sr.subject + '</span>' : '<span class="label label-primary">' + data.news[i].txt_key_params_sr.home + '</span> : <span class="label label-primary">' + data.news[i].txt_key_params_sr.guest + '</span>';
                        txtParams[3] = moment( new Date( data.news[i].txt_key_params_sr.starttime * 1000 ) ).format( 'Do MMMM YYYY [um] H:mm [Uhr]');
                    break;

                    case 'team':
                        txtParams[0] = '<span class="label label-primary">' + data.news[i].txt_key_params_sr.display_name + '</span>';
                        txtParams[1] = '<span class="label label-success">' + data.news[i].txt_key_params_sr.first_name + ' ' + data.news[i].txt_key_params_sr.last_name + '</span>';
                    break;

                    case 'profile':
                        txtParams[0] = '<span class="label label-success">' + data.news[i].txt_key_params_sr.first_name + ' ' + data.news[i].txt_key_params_sr.last_name + '</span>';
                        txtParams[1] = '<span class="label label-primary">' + data.news[i].txt_key_params_sr.team_name + '</span>';
                    break;

                    case 'attendee':
                        txtParams[0] = '<span class="label">' + authorProfileName + '</span>';
                        txtParams[1] = data.news[i].txt_key_params_sr.appointment.subject ? 'Termin' : 'Spieltermin';
                        txtParams[2] = data.news[i].txt_key_params_sr.appointment.subject ? '<span class="label label-primary">' + data.news[i].txt_key_params_sr.appointment.subject + '</span>' : '<span class="label label-default">' + data.news[i].txt_key_params_sr.appointment.home + '</span> : <span class="label label-default">' + data.news[i].txt_key_params_sr.appointment.guest + '</span>';
                        txtParams[3] = moment( new Date( data.news[i].txt_key_params_sr.appointment.starttime * 1000 ) ).format( 'Do MMMM YYYY');
                        switch( data.news[i].txt_key ) {
                            case 'txt_attendee_created_accepted':
                            case 'txt_attendee_updated_to_accepted':
                            case 'txt_attendee_updated_to_accepted_with_comment':
                                txtParams[4] = '<span class="label label-success">zugesagt</span>';
                            break;
                            case 'txt_attendee_created_declined':
                            case 'txt_attendee_updated_to_declined':
                            case 'txt_attendee_updated_to_declined_with_comment':
                                txtParams[4] = '<span class="label label-danger">abgesagt</span>';
                            break;

                            default:
                                txtParams[4] = '';
                        }
                        txtParams[5] = data.news[i].txt_key_params_sr.new_comment ? '&quot;<i>' + data.news[i].txt_key_params_sr.new_comment + '</i>&quot;' : '';
                    break;

                    case 'custom':
                        txtParams[0] = '<span class="label">Nachricht vom Coach: ' + authorProfileName + '</span>';
                        txtParams[1] = data.news[i].txt_key_params_sr.custom_content;
                    break;

                    case 'chat':
                        txtParams[0] = '<span class="label">Nachricht von: ' + authorProfileName + '</span>';
                        txtParams[1] = data.news[i].txt_key_params_sr.chat_content;
                    break;

                    case 'tbuddy_news':
                        txtParams[0] = '<span class="label">' + data.news[i].txt_key_params_sr.news_head + '</span>';
                        txtParams[1] = data.news[i].txt_key_params_sr.news_body;
                    break;

                }
            %>

            <div class="row">
                <div class="col-md-12">
                    <div class="well well-lg <%= data.news[i].ref_content_type === 'tbuddy_news' ? 'well-tbuddy' : '' %>">
                        <% if ( data.news[i].ref_content_type === 'tbuddy_news' ) { %>
                            <img src="http://client.tbuddy.de/img/tb-icon.png" style="margin: 0px 4px;"class="pull-right" />
                            <%= TB._( data.news[i].txt_key, txtParams ) %>
                        <% } else { %>
                            <%= TB._( data.news[i].txt_key, txtParams ) %>
                        <% }    %>
                        <div class="clearfix">
                            <small><%= moment( new Date( data.news[i].created * 1000 ) ).fromNow() %></small>
                            <% if ( ( data.news[i].ref_content_type == 'custom' || data.news[i].ref_content_type == 'chat' ) && ( TB.GUI.isTrainer() || TB.GUI.isCoTrainer() ) ) {  %>
                            <button type="button" class=" btn btn-default btn-xs pull-right"
                                    data-action="delete"
                                    data-news_id="<%= data.news[i].id %>">
                                <span class="glyphicon glyphicon-trash"></span>
                            </button>
                            <% }    %>
                        </div>
                    </div>
                </div>
            </div>

        <% }    %>

<div class="row">
    <div class="col-md-12">
        <div class="alert alert-info hide" role="alert" data-id="new-news-alert">
            Schon wieder was passiert. <a href="javascript: TB.Controller.reload();" class="alert-link">Neuigkeiten laden.</a>
        </div>
    </div>
</div>

<% } else {     %>
    <div class="row">
        <div class="col-md-12">
            <h4>Nichts Neues passiert in letzter Zeit.</h4>
        </div>
    </div>
<% }    %>


<% if ( TB.Client.can( TB.ACL.RIGHTS.NEWS_CREATECHAT ) ) {  %>
<nav class="navbar navbar-fixed-bottom chatbox">
    <div class="container">
        <div class="row">
            <div class="col-lg-12">
                <div class="input-group create-chat">
                    <div class="input-group-btn">
                        <div class="btn-group dropup">
                            <button type="button"
                                    id="btn_news_config"
                                    data-toggle="dropdown"
                                    aria-haspopup="true"
                                    aria-expanded="false"
                                    class="btn btn-default dropdown-toggle"><i class="glyphicon glyphicon-cog"></i>
                            </button>
                            <ul class="dropdown-menu">
                                <li>
                                    <button class="btn btn-link"
                                            data-current-val="<%= data.news_filter %>"
                                            data-dropdown-action="toggle-chat-filter">
                                        Filter Chat&nbsp;<i class="glyphicon glyphicon-<%= ( 'custom' == data.news_filter ) ? 'check' : 'unchecked' %>"></i>
                                    </button>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <input type="text"
                           class="form-control ladda-button"
                           id="chat_content"
                           data-style="zoom-in"
                           data-size="l"
                           placeholder="Chat Nachricht" />
                    <span class="input-group-btn">
                        <button type="submit"
                                id="btn_news_chat"
                                class="btn btn-primary"><i class="glyphicon glyphicon-send"></i>
                    </span>
                </div>
            </div>
        </div>
    </div>
</nav>
<% }  %>