{% extends "website/base.html" %}
{% block content %}
<section class="section">
  <div class="card">
    <div class="card-title">
      <div class="icon">🎫</div>
      <div>
        <h1 class="h1" style="margin:0">Ticket {{ ticket.public_id }}</h1>
        <div class="small">Status: <strong>{{ ticket.get_status_display }}</strong> • {{ ticket.full_name }}</div>

        <div class="small" style="margin-top:6px">
          {% if ticket.due_at and not ticket.first_response_at %}
            SLA due: <strong>{{ ticket.due_at|date:"M d, Y H:i" }}</strong>
          {% endif %}
          {% if ticket.assigned_to %}
            • Assigned: <strong>{{ ticket.assigned_to.username }}</strong>
          {% else %}
            • Assigned: <strong>Unassigned</strong>
          {% endif %}
        </div>

      </div>
    </div>
    <div class="sep"></div>

    <div style="display:grid;gap:10px">
      {% for m in ticket.messages.all %}
        <div class="card soft card-tight" style="border-radius:14px">
          <div class="small" style="display:flex;justify-content:space-between;gap:10px;flex-wrap:wrap">
            <strong>{{ m.sender|title }}</strong>
            <span>{{ m.created_at|date:"M d, Y H:i" }}</span>
          </div>
          <div style="margin-top:6px;white-space:pre-wrap">{{ m.message }}</div>
        </div>
      {% endfor %}
    </div>

    <div class="sep"></div>

    <form method="post">
      {% csrf_token %}
      <div class="grid-2">
        <div>
          <label class="label">Change status</label>
          <div style="display:flex;gap:8px;flex-wrap:wrap">
            <button class="btn" name="action" value="open">Open</button>
            <button class="btn" name="action" value="pending">Pending</button>
            <button class="btn" name="action" value="closed">Closed</button>
          </div>
        </div>
        <div>
          <label class="label">Reply to client</label>
          <textarea name="staff_message" placeholder="Type reply..."></textarea>
        </div>
      </div>
      <div style="display:flex;gap:10px;flex-wrap:wrap;margin-top:12px">
        <button class="btn btn-primary" type="submit">Save</button>
        <a class="btn" href="{% url 'website:staff_support_dashboard' %}">Back</a>
      </div>
    </form>
  </div>
</section>
{% endblock %}
