<!--!
Ticket Box (ticket fields along with description).

Arguments:
 - ticket: the ticket to be shown
 - fields: ticket field metadata
 - description_change: metadata about changes in the description
 - can_append: True if the user is allowed to append to tickets
 - preview_mode: if True, show the "draft" background
 - reporter_link=None: rendered link for the reporter field
 - owner_link=None: rendered link for the owner field
-->
<div xmlns="http://www.w3.org/1999/xhtml"
     xmlns:py="http://genshi.edgewall.org/"
     xmlns:xi="http://www.w3.org/2001/XInclude"
     xmlns:i18n="http://genshi.edgewall.org/i18n"
     id="ticket" class="${preview_mode and 'ticketdraft' or None}">
  <div class="date">
    <p i18n:msg="created" py:if="ticket.exists">Opened ${dateinfo(ticket.time)} ago</p>
    <p i18n:msg="modified" py:if="ticket.changetime != ticket.time">Last modified ${dateinfo(ticket.changetime)} ago</p>
    <p py:if="not ticket.exists"><i>(ticket not yet created)</i></p>
  </div>
  <!--! use a placeholder if it's a new ticket -->
  <h2 class="summary searchable">$ticket.summary</h2>

  <table class="properties"
         py:with="fields = [f for f in fields if not f.skip and f.name not in ('type', 'owner')]">
    <tr>
      <th id="h_reporter">Reported by:</th>
      <td headers="h_reporter" class="searchable">
        ${defined('reporter_link') and reporter_link or authorinfo(ticket.reporter)}
      </td>
      <th id="h_owner">Owned by:</th>
      <td headers="h_owner">
        ${ticket.owner and (defined('owner_link') and owner_link or authorinfo(ticket.owner)) or ''}
      </td>
    </tr>
    <tr py:for="row in group(fields, 2, lambda f: f.type != 'textarea')"
      py:with="fullrow = len(row) == 1">
      <py:for each="idx, field in enumerate(row)">
        <th py:if="idx == 0 or not fullrow"
            id="${field and 'h_' + field.name or None}">
          <py:if test="field"><i18n:msg params="field">${field.label or field.name}:</i18n:msg></py:if>
        </th>
        <td py:if="idx == 0 or not fullrow"
            headers="${field and 'h_' + field.name or None}"
            class="${field and field.name in ('cc', 'keywords') and 'searchable' or None}"
            colspan="${fullrow and 3 or None}">
          <py:if test="field">
            <py:choose test="">
              <py:when test="'rendered' in field">${field.rendered}</py:when>
              <py:otherwise>${ticket[field.name]}</py:otherwise>
            </py:choose>
          </py:if>
        </td>
      </py:for>
    </tr>
  </table>
  <div class="description">
    <h3 id="comment:description">
      Description
      <span py:if="description_change" class="lastmod" title="$description_change.date">
        <i18n:msg params="author">(last modified by ${authorinfo(description_change.author)})</i18n:msg>
        (<a href="${href.ticket(ticket.id, action='diff', version=description_change.cnum)}">diff</a>)
      </span>
    </h3>

    <!--! Quote the description (only for existing tickets) -->
    <form py:if="ticket.exists and ticket.description and can_append"
          id="addreply" method="get" action="#comment">
      <div class="inlinebuttons">
        <input type="hidden" name="replyto" value="description" />
        <input type="submit" name="reply" value="${_('Reply')}" title="Reply, quoting this description" />
      </div>
    </form>
    <div py:if="ticket.description" class="searchable" xml:space="preserve">
      ${wiki_to_html(context, ticket.description, escape_newlines=preserve_newlines)}
    </div>
    <br py:if="not ticket.description" style="clear: both" />
  </div>
</div>
