{% extends 'base.html.j2' %}

{% block additional-stylesheet %}
    {% load static %}
    <link rel="stylesheet" href="{% static 'ticketing.css' %}">
{% endblock additional-stylesheet %}

{% load markdown %}

{% block article %}

<div id="ticket-content">

    <div id="ticket-data">

        <div id="ticket-description">
            <h3 class="{{ ticket_type }}-ticket">
            <span class="sub-script">opened by</span> {{ ticket.opened_by }} <span class="sub-script">on</span> {{ ticket.created }} 
            {% if ticket.created|date_time_seconds != ticket.modified|date_time_seconds %}
            <span class="sub-script">Updated</span> {{ ticket.modified }}
            {% endif %}
            </h3>
            <div>
                <input style="float: right; position: relative; margin: 0px;" type="button" value="Edit" onclick="window.location='{{ edit_url }}';">
            </div>
            <div id="markdown">{{ ticket.description | markdown | safe }}</div>
        </div>

        <div id="ticket-additional-data">

            <div id="data-block">
                <h3>
                    <div id="text">Related Tickets</div>
                    <div id="icons">
                        <a href="{% url '_ticket_related_add' ticket_type=ticket_type ticket_id=ticket.id %}">{% include 'icons/ticket/add.svg' %}</a>
                    </div>
                </h3>

                {% if ticket.related_tickets %}
                {% for related_ticket in ticket.related_tickets %}
                <div id="linked-tickets" class="{{ related_ticket.type }}-ticket">
                    <div class="icon icon-{{ related_ticket.how_related }}">{% include related_ticket.icon_filename %}</div>
                    <div id="markdown" class="ticket">
                        {% if related_ticket.how_related == 'blocked_by' %}
                        Blocked by
                        {% elif related_ticket.how_related == 'blocks' %}
                        Blocks
                        {% elif related_ticket.how_related == 'related' %}
                        Related to
                        {% endif %}
                        <span style="display: inline-block;">{{ related_ticket.markdown | markdown | safe }}</span>
                    </div>
                </div>
                {% endfor %}
                {% else %}
                <div>Nothing Found</div>
                {% endif %}

            </div>


            <div id="data-block" class="linked-item">
                <h3>
                    <div id="text">Linked Items</div>
                    <div id="icons">
                        <a href="{% url '_ticket_linked_item_add' ticket_type=ticket_type ticket_id=ticket.id %}">{% include 'icons/ticket/add.svg' %}</a>
                    </div>
                </h3>
                {% if ticket.linked_items %}
                {% for linked_item in ticket.linked_items %}
                <div id="item">{{ linked_item | markdown | safe }}</div>
                {% endfor %}
                {% else %}
                <div style="text-align:center;%">Nothing found</div>
                {% endif%}
            </div>

        </div>

        {% include 'core/ticket/comment.html.j2' %}

    </div>


    <div id="ticket-meta">
    <h3 class="{{ ticket_type }}-ticket">
        {{ ticket_type }} <span style="font-size: smaller;">#{{ ticket.id }} 
        {% if ticket.external_ref %}
        <span style="display: inline-block;" title="External system {{ ticket.get_external_system_display }}">(#{{ ticket.external_ref }})</span>
        {% endif %}</span>
    </h3>

        <fieldset>
            <label>Assigned</label>
            <span class="text">
            {% if ticket.assigned_users %}
                {% for user in ticket.assigned_users.all %}
                    {{ user }} 
                {% endfor%}
            {% endif %}
            {% if ticket.assigned_teams %}
                {% for team in ticket.assigned_teams.all %}
                    {{ team }} 
                {% endfor%}
            {% endif %}
            </span>
        </fieldset>
        <fieldset>
            <label>Status</label>
            <span>{% include 'core/ticket/badge_ticket_status.html.j2' with ticket_status_text=ticket.get_status_display ticket_status=ticket.get_status_display|ticket_status %}</span>
        </fieldset>
        <fieldset>
            <label>Labels</label>
            <span class="text">val</span>
        </fieldset>
        {% if ticket.category %}
        <fieldset>
            <label>Category</label>
            <span class="text">
                <a href="{% url 'Settings:_ticket_category_view' pk=ticket.category.id %}">
                {{ ticket.category }}
                </a>
            </span>
        </fieldset>
        {% endif %}
        {% if ticket.project %}
        <fieldset>
            <label>Project</label>
            <span class="text">
                <a href="{% url 'Project Management:_project_view' pk=ticket.project_id %}">{{ ticket.project }}</a>
            </span>
        </fieldset>
        {% endif %}
        {% if ticket.milestone %}
        <fieldset>
            <label>Milestone</label>
            <span class="text">
                <a href="{% url 'Project Management:_project_milestone_view' project_id=ticket.project_id pk=ticket.milestone.id %}">{{ ticket.milestone }}</a>
            </span>
        </fieldset>
        {% endif %}
        <fieldset>
            <label>Priority</label>
            <span class="text">U{{ ticket.get_urgency_display }} / I{{ ticket.get_impact_display }} / P{{ ticket.get_priority_display }}</span>
        </fieldset>
        <fieldset>
            <label>Duration</label>
            <span class="text">{{ ticket.duration_ticket|to_duration }}</span>
        </fieldset>
        <fieldset>
            <label>Milestone</label>
            <span class="text">val</span>
        </fieldset>
        <fieldset>
            <label>Roadmap(s)</label>
            <span class="text">val</span>
        </fieldset>

    </div>


</div>
{% endblock %}