{% load i18n %}
{% load statistics_resources %}
{% load truncate %}
{% load permissions %}
{% load team_tags %}
{% load locks_tags %}
{% load upload_manager_tags %}
{% load watches_tags %}
{% load txcommontags %}

{% get_permission "project_perm.maintain" for request.user and resource.project as "is_maintainer" %}
<div class="actions_popup">
  <div class="first_level title_wrapper">
    <span class="breadcrumb" >
      <a href="{% url project_detail project.slug %}">{{project.name|truncate_chars_middle:"40"}}</a> »
      <a href="{% url resource_detail project.slug resource.slug %}">{{resource.name|truncate_chars_middle:"40"}}</a> »
      {{ target_language }}
    </span>
    <span class="favourite_wrapper">
      {% watch_toggle resource target_language %}
    </span>
    <div class="details_font">
        {% blocktrans with stats.total_entries as total_entries %} Total:&nbsp;{{ total_entries }} strings,{% endblocktrans %}
        {% blocktrans with stats.words as wordcount %} {{ wordcount }} words{% endblocktrans %}
    </div>
  </div>
  <div class="first_level">
    <span class="translate_button_wrapper">
    {% if team %}
      {% comment %} This permission is provided only if team is available{% endcomment %}
      {% get_permission "project_perm.submit_file" for request.user and team as "can_submit_translation" %}
    {% else %}
      {% comment %} This permission is provided if team is not available and then only the maintainers can access lotte via "Translate Now" {% endcomment %}
      {% get_permission "project_perm.submit_file" for request.user and project as "can_submit_translation" %}
    {% endif %}

      {% ifequal resource.source_language target_language %}
        {% blocktrans %} 
        <span title="You cannot translate the source language strings.">This is the Source Language</span>
        {% endblocktrans %}
      {% else %}
        {% if can_submit_translation or request.user.is_superuser %}
          <a class="i16 tick buttonized2" id="translate_now" href="{% url translate_resource project.slug resource.slug target_language.code %}">{% trans "Translate Now" %}</a>
        {% else %}
          <a class="i16 tick_disabled buttonized2_disabled tipsy_enable" id="translate_now" 
          title="{% blocktrans with target_language.name as lang_name %}To translate, you need to be a member of the {{ lang_name }} team.{% endblocktrans %}">{% trans "Translate Now" %}</a>
        {% endif %}
    {% endifequal %}

    </span>
    <div class="stats_wrapper">
      {% with 300 as barwidth %}
      <div class="stats tipsy_enable" style='width:{{ barwidth|add:"60" }}px;' title="{% trans "Translated: " %}{{ stats.num_translated }}<br />{% trans "Untranslated: " %}{{ stats.num_untranslated }}">
          <div class="stats_string_resource_actions" >
              {{ stats.trans_percent }}% 
          </div> 
          {% stats_bar_actions stats barwidth %}
      </div>
      {% endwith %}
      <div class="details_font stats_details_string">
      {{ stats.num_untranslated }} {% trans "remaining strings" %}
      </div>
    </div>
  </div>
  <div class="first_level more_actions">
        <ul class="right">
          <li class="top">
            <span id="view_strings" class="i16 find">
            <a href="{% url view_strings resource.project.slug resource.slug target_language.code %}">{% trans "View strings online" %}</a>
            </span>
          </li>
          {% if team %}
          <li>
            <span class="i16 team"><a href="{% url team_detail project.slug target_language.code %}">{% trans "Visit language team" %}</a></span>
          </li>
          {% endif %}
          {% ifnotequal resource.source_language target_language %}
          <li>
            {% if request.user.is_authenticated %}
              {% if is_maintainer or request.user.is_superuser or user_teams %}
              <span class="i16 clone">
                <a class="language_chooser_trigger" style="cursor:pointer" >{% trans "Clone to new language" %}</a>
              </span>
              <span class="tipsy_enable" title="Copy all the translations from this language to a new (chosen) language in the specific resource. This will copy the pluralized translations too, if and only if the two languages have exactly the same plural rules." style="border:0">(?)</span>
              <div class="language_chooser" style="visibility:hidden;margin-top:4px">
                <select style="margin-left:24px">
                  <option value="" selected="selected">---------</option>
                {% if is_maintainer or request.user.is_superuser %}
                  {% for language in languages %}
                    <option {% if language.id|in_list:disabled_languages_ids %}disabled="disabled"{% endif %} value="{{ language.code }}">{{ language.name }}</option>
                  {% endfor %}
                {% else %}
                  {% for team in user_teams %}
                    <option {% if team.language.id|in_list:disabled_languages_ids %}disabled="disabled"{% endif %} value="{{ team.language.code }}">{{ team.language.name }}</option>
                  {% endfor %}
                {% endif %}
                </select>
                <a class="i16 action buttonized">Go</a>
              </div>
              {% else %}
                <span class="i16 clone">
                  <a class="language_chooser_trigger disabled" style="cursor:pointer" >{% trans "Clone to new language" %}</a>
                </span>
                <span class="tipsy_enable" title="Copy all the translations from this language to a new (chosen) language in the specific resource. This will copy the pluralized translations too, if and only if the two languages have exactly the same plural rules." style="border:0">(?)</span>
              {% endif %}
            {% else %}
              <span class="i16 clone">
                <a class="language_chooser_trigger disabled" style="cursor:pointer" >{% trans "Clone to new language" %}</a>
              </span>
              <span class="tipsy_enable" title="Copy all the translations from this language to a new (chosen) language in the specific resource. This will copy the pluralized translations too, if and only if the two languages have exactly the same plural rules." style="border:0">(?)</span>
            {% endif %}
          </li>
          {% endifnotequal %}
        </ul>
        <ul>
          <li class="top">
            <span class="i16 get_file">
            {% if request.user.is_authenticated %}
                <a href="{% url download_translation resource.project.slug resource.slug target_language.code %}">{% trans "Download for viewing" %}</a>
            {% else %}
                <a class="disabled" style="cursor:pointer" title='{% trans "You must login to be able to download the translations." %}'>{% trans "Download for viewing" %}</a>
            {% endif %}
			</span>
          </li>
          {% ifnotequal resource.source_language target_language %}
          <li>
            {% if request.user.is_authenticated %}
            <span id="download_for_translation" class="i16 lock">
              <a style="cursor:pointer" {% if lock %}{% ifnotequal request.user lock.owner %}class="disabled" title="Resource cannot be locked"{% endifnotequal %}{% endif %}>{% trans "Download for translation" %}</a>
            </span>
            {% else %}
            <span id="download_for_translation" class="i16 lock">
              <a class="disabled" style="cursor:pointer" title='{% trans "You must login to use this action" %}'>{% trans "Download for translation" %}</a>
            </span>
            {% endif %}
            <span class="tipsy_enable" title="Lock the file under your ownership and download it locally to edit it, in one action." style="border:0">(?)</span>
            <div class="error_notes"></div>
          </li>
          <li>
            {% if can_submit_translation %}
                <div class="upload_action_wrapper" style="padding:0.5em 0">
                {% upload_resource_translation_button request resource target_language %}
                </div>
            {% endif %}
          </li>
          {% endifnotequal %}
        </ul>
  </div>
  <div class="first_level last_update">
        <ul>
          {% ifnotequal resource.source_language target_language %}
            {% lock_resource_action resource target_language %}
          {% endifnotequal %}
          <li>
            <span class="i16 clock">
              {% with stat.last_update as last_update %}
              {% with stat.last_committer as last_committer %}
              {% if last_update %}
                {% blocktrans %}Translation last updated {% endblocktrans %}
                {% if last_committer %}
                  {% trans "by" %}
                  <strong>{{ last_committer }}</strong> ({{ last_update|timesince }})
                {% else %}
                  {{ last_update|timesince }}
                {% endif %}
              {% else %}
                {% trans "No translation yet" %}
              {% endif %}
              {% endwith %}
              {% endwith %}
            </span>
          </li>
        </ul>
  </div>
  {% ifnotequal resource.source_language target_language %}
  {% if perms.projects.delete_resource or is_maintainer or request.user.is_superuser %}
  <div class="first_level footer_action">
    <a class="i16 delete" href="{% url resource_translations_delete project.slug resource.slug target_language.code %}">{% trans "Delete translations" %}</a>
  <div>
  {% endif %}
  {% endifnotequal %}
</div>
