{% extends "base.html" %}

{% block content %}
<main class="page-shell">
  <div class="container">
    <div class="row g-4">
      <div class="col-lg-7">
        <article class="detail-panel">
          {% if entry.photo %}
          <img class="detail-photo" src="{{ entry.photo.url }}" alt="Uploaded property photo for entry {{ entry.pk }}">
          {% endif %}
          <div class="detail-body">
            <span class="badge listing-badge">{{ entry.get_listing_type_display }}</span>
            <h1>{{ entry.address|default:"Location-only property" }}</h1>
            <p class="text-muted">Added {{ entry.created_at|date:"M j, Y H:i" }} · {{ entry.get_source_display }}</p>
            <dl class="detail-grid">
              <div><dt>Phone</dt><dd>{{ entry.phone|default:"Missing" }}</dd></div>
              <div><dt>Email</dt><dd>{{ entry.email|default:"Missing" }}</dd></div>
              <div><dt>GPS</dt><dd>{% if entry.has_location %}{{ entry.latitude }}, {{ entry.longitude }}{% else %}Missing{% endif %}</dd></div>
              <div><dt>Photo GPS</dt><dd>{{ entry.has_gps_data|yesno:"Detected,Not detected" }}</dd></div>
            </dl>
            {% if entry.extracted_text %}
            <div class="analysis-box"><h2>Text spotted in photo</h2><p>{{ entry.extracted_text }}</p></div>
            {% endif %}
            {% if entry.idealista_url %}
            <a class="btn btn-ghost" href="{{ entry.idealista_url }}" target="_blank" rel="noopener">Open best-effort Idealista search</a>
            {% endif %}
          </div>
        </article>
      </div>
      <div class="col-lg-5">
        <aside class="side-stack">
          <section class="form-card compact-card">
            <h2>Suggest missing details</h2>
            <form method="post" action="{% url 'suggest_property_update' entry.pk %}">
              {% csrf_token %}
              {% for field in suggestion_form.visible_fields %}
              <div class="mb-3"><label class="form-label" for="{{ field.id_for_label }}">{{ field.label }}</label>{{ field }}</div>
              {% endfor %}
              <button class="btn btn-nest w-100" type="submit">Save suggestion</button>
            </form>
          </section>
          <section class="form-card compact-card danger-soft">
            <h2>Flag for removal</h2>
            <p class="text-muted">Repeated flags hide an entry until a future admin review flow is added.</p>
            <form method="post" action="{% url 'flag_property' entry.pk %}">
              {% csrf_token %}
              {% for field in flag_form.visible_fields %}
              <div class="mb-3"><label class="form-label" for="{{ field.id_for_label }}">{{ field.label }}</label>{{ field }}</div>
              {% endfor %}
              <button class="btn btn-outline-danger w-100 rounded-pill" type="submit">Flag entry</button>
            </form>
          </section>
          <section class="activity-card">
            <h2>Community activity</h2>
            <p>{{ entry.suggestions.count }} suggestions · {{ entry.flag_count }} flags</p>
            <a href="{% url 'property_list' %}">Back to public list →</a>
          </section>
        </aside>
      </div>
    </div>
  </div>
</main>
{% endblock %}
