<header>
    <h2>
        <i class="icon-wrench"></i>
        {{ PMF_LANG['ad_menu_translations'] }}
        {% if renderAddNewTranslationButton %}
        <div class="pull-right">
            <a class="btn btn-success" href="?action=transadd">
                <i class="icon-plus"></i>
                {{ PMF_LANG['msgTransToolAddNewTranslation'] }}
            </a>
        </div>
        {% endif %}
    </h2>
</header>

<p>{{ PMF_LANG['msgChooseLanguageToTranslate'] }}:</p>

{% if not isTransDirWritable %}
<p class="alert alert-error">{{ PMF_LANG['msgLangDirIsntWritable'] }}</p>
{% endif %}

<table class="table table-striped">
    <thead>
    <tr>
        <th>{{ PMF_LANG['msgTransToolLanguage'] }}</th>
        <th colspan="3">{{ PMF_LANG['msgTransToolActions'] }}</th>
        <th>{{ PMF_LANG['msgTransToolWritable'] }}</th>
        <th>{{ PMF_LANG['msgTransToolPercent'] }}</th>
    </tr>
    </thead>
    <tbody>
        {% for currentTranslation in translations %}
        <tr class="lang_{{ currentTranslation['lang'] }}_container">
            <td>{{ currentTranslation['name'] }}</td>
            {% if currentTranslation['renderEditButton'] %}
            <td>
                <a class="btn btn-primary" href="{{ currentTranslation['editButtonUrl'] }}" >
                    <i class="icon-edit icon-white"></i>
                    {{ PMF_LANG['msgEdit'] }}
                </a>
            </td>
            {% else %}
            <td>{{ PMF_LANG['msgEdit'] }}</td>
            {% endif %}
            {% if currentTranslation['renderDeleteButton'] %}
            <td>
                <a class="btn btn-danger" href="javascript: del('{{ currentTranslation['lang'] }}');" >
                    <i class="icon-remove icon-white"></i>
                    {{ PMF_LANG['msgDelete'] }}
                </a>
            </td>
            {% else %}
            <td>{{ PMF_LANG['msgDelete'] }}</td>
            {% endif %}
            {% if currentTranslation['renderSendToTeamButton'] %}
            <td>
                <a class="btn btn-success" href="javascript: sendToTeam('{{ currentTranslation['lang'] }}');" >
                    <i class="icon-upload icon-white"></i>
                    {{ PMF_LANG['msgTransToolSendToTeam'] }}
                </a>
            </td>
            {% else %}
            <td>{{ PMF_LANG['msgTransToolSendToTeam'] }}</td>
            {% endif %}
            {% if currentTranslation['isLangFileWritable'] %}
            <td><i class="icon-ok-circle"></i> {{ PMF_LANG['msgYes'] }}</td>
            {% else %}
            <td><i class="icon-ban-circle"></i> {{ PMF_LANG['msgNo'] }}</td>
            {% endif %}
            <td>{{ currentTranslation['translatedPercentage'] }}</td>
        </tr>
        {% endfor %}
    </tbody>
</table>
{% autoescape 'js' %}
<script>
    /**
     * Remove a language file
     *
     * @param string lang Language to remove
     *
     * @return void
     */
    function del(lang)
    {
        if (!confirm('{{ PMF_LANG['msgTransToolSureDeleteFile'] }}')) {
        return;
    }

        $('#saving_data_indicator').html('<img src="images/indicator.gif" /> {{ PMF_LANG['msgRemoving3Dots'] }}');

        $.get('index.php?action=ajax&ajax=trans&ajaxaction=remove_lang_file',
                {translang: lang},
                function(retval, status) {
                    if (1*retval > 0 && 'success' == status) {
                        $('.lang_' + lang + '_container').fadeOut('slow');
                        $('#saving_data_indicator').html('{{ PMF_LANG['msgTransToolFileRemoved'] }}');
                    } else {
                        $('#saving_data_indicator').html('{{ PMF_LANG['msgTransToolErrorRemovingFile'] }}');
                        alert('{{ PMF_LANG['msgTransToolErrorRemovingFile'] }}');
                    }
                }
        );
    }

    /**
     * Send a translation file to the phpMyFAQ team
     *
     * @param string lang
     *
     * @return void
     */
    function sendToTeam(lang)
    {
        $('#saving_data_indicator').html('<img src="images/indicator.gif" /> {{ PMF_LANG['msgSending3Dots'] }}');

        var msg = '';;

        $.get('index.php?action=ajax&ajax=trans&ajaxaction=send_translated_file',
                {translang: lang},
                function(retval, status) {
                    if (1*retval > 0 && 'success' == status) {
                        msg = '{{ PMF_LANG['msgTransToolFileSent'] }}';
                    } else {
                        msg = '{{ PMF_LANG['msgTransToolErrorSendingFile'] }}';
                    }
                }
        );

        $('#saving_data_indicator').html('{{ PMF_LANG['msgTransToolFileSent'] }}');
        alert('{{ PMF_LANG['msgTransToolFileSent'] }}');
    }
</script>
{% endautoescape %}