{% extends "base_list.html" %}
{% load form_tags %}
{% load mathfilters %}
{% load naturalduration %}
{% load static %}

{% block title %}{{object.name}}{% endblock %}

{% block head_extra %}
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
    <style>
        dl { border:none; }
        dt {
            background: #333;
            color: #fff;
        }
        dd {
            float:left;
            margin: 2px;
            padding: 4px;
            min-height: 1em;
            border: none;
        }
        #map {
            height: 400px;
            border-radius: 4px;
        }
    </style>
{% endblock %}

{% block lists %}

<div class="row">

<div class="alert alert-info">
    Shared via link
</div>

<h1 class="d-flex align-items-center gap-2">
{% if object.media_type == "Video" %}🎬{% elif object.media_type == "Track" %}🎵{% elif object.media_type == "PodcastEpisode" %}🎙️{% elif object.media_type == "SportEvent" %}⚽{% elif object.media_type == "Book" %}📚{% elif object.media_type == "Paper" %}📄{% elif object.media_type == "VideoGame" %}🎮{% elif object.media_type == "BoardGame" %}🎲{% elif object.media_type == "GeoLocation" %}📍{% elif object.media_type == "Trail" %}🥾{% elif object.media_type == "Beer" %}🍺{% elif object.media_type == "Puzzle" %}🧩{% elif object.media_type == "Food" %}🍔{% elif object.media_type == "Task" %}✅{% elif object.media_type == "WebPage" %}🌐{% elif object.media_type == "LifeEvent" %}🎉{% elif object.media_type == "Mood" %}😊{% elif object.media_type == "BrickSet" %}🧱{% elif object.media_type == "Channel" %}📺{% elif object.media_type == "AgentSession" %}🤖{% elif object.media_type == "Workout" %}🏋️{% endif %}
{% if object.media_obj.get_absolute_url %}
    <a href="{{ object.media_obj.get_absolute_url }}">{% endif %}
        {{ object.media_obj.title }}
        {% if object.media_obj.get_absolute_url %}</a>
        {% endif %}
</h1>
<h2>{{ object.media_obj.subtitle }}</h2>
<p>
{% if object.media_type == "SportEvent" %}
{% for team in object.media_obj.teams.all %}
<img src="{{team.logo.url}}" width=150 />
{% endfor %}
{% endif %}
{% if object.media_type == "Task" and object.public_logdata.title %}
    </p>
<h2>{{ object.public_logdata.title }}</h2>
{% endif %}
{% if object.media_type == "AgentSession" and object.public_logdata.title %}
    </p>
<h2>{{ object.public_logdata.title }}</h2>
{% endif %}
<h3 class="text-muted">{{ object.local_timestamp }}</h3>
{% if object.media_type == "Track" %}
<p class="text-muted small">Source: {{ object.source }}{% if object.public_log.mopidy_source %} ({{ object.public_log.mopidy_source|capfirst }}){% endif %}</p>
{% endif %}
{% if object.media_type == "Task" and object.public_log.weight %}
<div class="mb-3">
  <dl class="row" style="max-width: 400px;">
    <dt class="col-sm-5">Weight</dt>
    <dd class="col-sm-7">{{ object.public_log.weight }} {% if object.public_log.unit_type == "imperial" %}lbs{% else %}kg{% endif %}</dd>
    {% if object.public_log.body_fat %}
    <dt class="col-sm-5">Body Fat</dt>
    <dd class="col-sm-7">{{ object.public_log.body_fat }}%</dd>
    {% endif %}
    {% if object.public_log.bmi %}
    <dt class="col-sm-5">BMI</dt>
    <dd class="col-sm-7">{{ object.public_log.bmi }}</dd>
    {% endif %}
    {% if object.public_log.muscle %}
    <dt class="col-sm-5">Muscle</dt>
    <dd class="col-sm-7">{{ object.public_log.muscle }} {% if object.public_log.unit_type == "imperial" %}lbs{% else %}kg{% endif %}</dd>
    {% endif %}
    {% if object.public_log.bone %}
    <dt class="col-sm-5">Bone</dt>
    <dd class="col-sm-7">{{ object.public_log.bone }} {% if object.public_log.unit_type == "imperial" %}lbs{% else %}kg{% endif %}</dd>
    {% endif %}
    {% if object.public_log.water %}
    <dt class="col-sm-5">Water</dt>
    <dd class="col-sm-7">{{ object.public_log.water }}%</dd>
    {% endif %}
    {% if object.public_log.visceral_fat %}
    <dt class="col-sm-5">Visceral Fat</dt>
    <dd class="col-sm-7">{{ object.public_log.visceral_fat }}</dd>
    {% endif %}
    {% if object.public_log.waist %}
    <dt class="col-sm-5">Waist</dt>
    <dd class="col-sm-7">{{ object.public_log.waist }} {% if object.public_log.unit_type == "imperial" %}in{% else %}cm{% endif %}</dd>
    {% endif %}
    {% if object.public_log.lbm %}
    <dt class="col-sm-5">Lean Mass</dt>
    <dd class="col-sm-7">{{ object.public_log.lbm }} {% if object.public_log.unit_type == "imperial" %}lbs{% else %}kg{% endif %}</dd>
    {% endif %}
    {% if object.public_log.calories %}
    <dt class="col-sm-5">Calories</dt>
    <dd class="col-sm-7">{{ object.public_log.calories }}</dd>
    {% endif %}
    {% if object.public_log.comment %}
    <dt class="col-sm-5">Comment</dt>
    <dd class="col-sm-7">{{ object.public_log.comment }}</dd>
    {% endif %}
  </dl>
</div>
{% endif %}
{% if object.media_type == "Beer" or object.media_type == "Wine" or object.media_type == "Coffee" %}
{% if object.public_logdata.format_display or object.public_logdata.size_ml %}
<div class="mb-3">
  <dl class="row" style="max-width: 400px;">
    {% if object.public_logdata.format_display %}
    <dt class="col-sm-5">Format</dt>
    <dd class="col-sm-7">{{ object.public_logdata.format_display }}</dd>
    {% endif %}
    {% if object.public_logdata.size_ml %}
    <dt class="col-sm-5">Size</dt>
    <dd class="col-sm-7">
        {{ object.public_logdata.size_oz }} oz
    </dd>
    {% endif %}
    {% if object.public_logdata.roast_level_display %}
    <dt class="col-sm-5">Roast</dt>
    <dd class="col-sm-7">{{ object.public_logdata.roast_level_display }}</dd>
    {% endif %}
    {% if object.public_logdata.brewing_method_display %}
    <dt class="col-sm-5">Method</dt>
    <dd class="col-sm-7">{{ object.public_logdata.brewing_method_display }}</dd>
    {% endif %}
  </dl>
</div>
{% endif %}
{% endif %}
{% if object.media_type == "Task" and object.public_logdata.description %}
<p>{{ object.public_logdata.description }}</p>
{% endif %}

{% if object.media_type == "Trail" and object.gpx_file %}
<div class="mb-3">
    <div id="map"></div>
</div>
{% endif %}

{% if object.screenshot %}
<div class="mb-3">
    <img src="{{ object.screenshot_large.url }}" class="img-fluid rounded" style="max-height: 600px;" alt="Screenshot" />
</div>
{% endif %}

<p>
    Tags: 
    {% if object.tags.all %}
    {% for tag in object.tags.all %}
        <span class="badge bg-secondary">{{ tag.name }}</span>
    {% endfor %}
    {% else %}
    untagged
    {% endif %}
</p>

{% with notes_html=object.public_logdata.notes_as_html %}
{% if notes_html %}
<div class="mb-3">
  <h4>Notes</h4>
  <span class="badge fs-8
      {% if sentiment.compound >= 0.5 %}bg-success
      {% elif sentiment.compound >= 0.05 %}bg-info text-dark
      {% elif sentiment.compound > -0.05 %}bg-secondary
      {% elif sentiment.compound > -0.5 %}bg-warning text-dark
      {% else %}bg-danger
      {% endif %}">
      {% if sentiment.compound >= 0.5 %}Positive
      {% elif sentiment.compound >= 0.05 %}Slightly positive
      {% elif sentiment.compound > -0.05 %}Neutral
      {% elif sentiment.compound > -0.5 %}Slightly negative
      {% else %}Negative
      {% endif %}
  </span>
  <div class="notes-list">
    {{ notes_html|safe }}
  </div>
</div>
{% endif %}
{% endwith %}

{% with sentiment=object.public_log.sentiment %}
{% if sentiment %}
<div class="mb-3">
</div>
{% endif %}
{% endwith %}

{% if object.public_logdata.avg_seconds_per_page %}
<p>Rate: {{object.public_logdata.avg_seconds_per_page}}s per page</p>
{% endif %}

{% if object.media_type == "BoardGame" and object.public_logdata.as_html %}
<div class="mb-3">
  <h5>Game Details</h5>
  {{ object.public_logdata.as_html|safe }}
</div>
{% endif %}

{% if object.media_type == "Workout" and object.public_logdata.workouts %}
<div class="mb-3">
  <h5>Workout Details</h5>
  {{ object.public_logdata|workout_html:"metric"|safe }}
</div>
{% endif %}

{% if object.media_type == "AgentSession" %}
<div class="mb-3">
  {% if object.public_logdata.as_html %}
    {{ object.public_logdata|agent_session_html|safe }}
  {% else %}
    <p class="text-muted">No conversation yet.</p>
  {% endif %}
</div>
{% endif %}

</div>

{% endblock %}

{% block extra_js %}
{{ block.super }}
{% if object.media_type == "Trail" and object.gpx_file %}
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script src="https://cdn.jsdelivr.net/npm/leaflet-gpx@2.2.0/gpx.min.js"></script>
<script>
var map = L.map('map');
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
    maxZoom: 19,
    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
    referrerPolicy: 'origin'
}).addTo(map);
var gpx = new L.GPX("{{ object.gpx_file.url|escapejs }}", {
    async: true,
    polyline_options: { color: '#e74c3c' }
});
gpx.on('loaded', function(e) {
    map.fitBounds(e.target.getBounds());
});
gpx.addTo(map);
</script>
{% endif %}
{% endblock %}
