{% extends "layout.html" %}
{% import "partials/resourcenav.html" as rnav with context %}

{% block title %}
<title>
  {{tracker.name}}
  &mdash;
  {{ cfg("sr.ht", "site-name") }} todo
</title>
{% endblock %}

{% block head %}
{% if tracker.visibility.value == 'UNLISTED' %}
<meta name="robots" content="noindex">
{% endif %}
{% endblock %}

{% block body %}
{% block pagenav %}
{% set fluid = view == "tickets" %}
{{ rnav.project_nav(tracker, projects, fluid=fluid) }}
<div class="header-tabbed resource-nav">
  <div class="{{ "container-fluid" if fluid else "container" }}">
    {% if len(projects) == 1 and projects[0].name != tracker.name %}
    <h3>{{tracker.name}}</h3>
    {% endif %}

    <ul class="nav nav-tabs">
      {% if tracker.visibility.value != "PUBLIC" %}
      <li
        class="nav-item nav-text vis-{{tracker.visibility.value.lower()}}"
        {% if tracker.visibility.value == "UNLISTED" %}
        title="This tracker is only visible to those who know the URL."
        {% elif tracker.visibility.value == "PRIVATE" %}
        title="This tracker is only visible to those who were invited to view it."
        {% endif %}
      >
        {% if tracker.visibility.value == "UNLISTED" %}
        Unlisted
        {% elif tracker.visibility.value == "PRIVATE" %}
        Private
        {% endif %}
      </li>
      {% endif %}

      {% macro tab(link, title, active) %}
      <li class="nav-item">
        <a
           class="nav-link {{ "active" if active else "" }}"
           href="{{ link }}"
         >{{title}}</a>
      </li>
      {% endmacro %}

      {{ tab(url_for("tracker.tracker_GET",
        owner=tracker.owner.canonical_name,
        name=tracker.name), "open tickets",
        view == "tickets" and not search) }}
      {{ tab(url_for("tracker.tracker_GET",
        owner=tracker.owner.canonical_name,
        name=tracker.name, search="status:closed"),
        "closed tickets",
        view == "tickets" and search in ["status:closed", "status:resolved"]) }}
      {% if search and search not in ["status:closed", "status:resolved"] %}
      {{ tab(url_for("tracker.tracker_GET",
        owner=tracker.owner.canonical_name,
        name=tracker.name,
        search=search), "search results", True) }}
      {% endif %}
      {{ tab(url_for("tracker.tracker_labels_GET",
        owner=tracker.owner.canonical_name,
        name=tracker.name), "labels", view == "labels") }}
      {% if current_user and current_user.id == tracker.owner_id %}
      {{ tab(url_for("settings.details_GET",
          owner=tracker.owner.canonical_name,
          name=tracker.name), "settings", view == "settings") }}
      {% endif %}

      {% if view == "tickets" %}
      <li class="flex-grow-1 d-none d-sm-block"></li>
      <li class="nav-item d-none d-sm-block">
        {% if current_user %}
        <form method="POST" action="{{url_for("tracker." +
            ("disable_notifications" if is_subscribed else "enable_notifications"),
            owner=tracker.owner.canonical_name,
            name=tracker.name)}}">
          {{csrf_token()}}
          <button class="nav-link active" type="submit">
            {{icon("envelope-o")}}
            {% if is_subscribed %}
            Disable notifications
            {% else %}
            Enable notifications
            {% endif %}
            {{icon("caret-right")}}
          </button>
        </form>
        {% else %}
        <a class="nav-link active" href="{{ tracker_subscribe }}">
          {{icon("envelope-o")}}
          Subscribe
          {{icon("caret-right")}}
        </a>
        {% endif %}
      </li>
      {% endif %}
    </ul>
  </div>
</div>
{% endblock %}

{% block subnav %}
{% endblock %}

{% block content %}
{% endblock %}
{% endblock %}
