{% load static %}
{% load humanize %}
<!doctype html>
<html class="no-js" lang="">
    <head>
        <title>{% block page_title %}Scrobble all the things{% endblock %} @ Vrobbler</title>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="shortcut icon" type="image/png" href="{% static 'images/favicon.ico' %}"/>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
        <link href="{% static 'css/bootstrap.min.css'  %}" rel="stylesheet">
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
        <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.10/clipboard.min.js"></script>
        <style type="text/css">
        dl {
            display: flex;
            flex-flow: column wrap;
            border: 1px solid #777;
        }
        dt {
            padding: 2px 4px;
            background: #000;
            color: #fff;
        }
        dd {
            margin: 0;
            padding: 4px;
            min-height: 3em;
            border-right: 1px solid #777;
        }
        .latest-scrobble {
            width: 50%;
        }

        .progress-bar {
            width: 100%;
            background-color: #e0e0e0;
            padding: 3px;
            border-radius: 3px;
            box-shadow: inset 0 1px 3px rgba(0, 0, 0, .2);
        }

        .progress-bar-fill {
            display: block;
            height: 22px;
            background-color: #659cef;
            border-radius: 3px;
            transition: width 500ms ease-in-out;
        }
        .bd-placeholder-img {
            font-size: 1.125rem;
            text-anchor: middle;
            -webkit-user-select: none;
            -moz-user-select: none;
            user-select: none;
        }

        @media (min-width: 768px) {
            .bd-placeholder-img-lg {
            font-size: 3.5rem;
            }
        }
        body {
        font-size: .875rem;
        }

        .feather {
        width: 16px;
        height: 16px;
        vertical-align: text-bottom;
        }

        /*
        * Sidebar
        */

        .sidebar {
        position: fixed;
        top: 0;
        /* rtl:raw:
        right: 0;
        */
        bottom: 0;
        /* rtl:remove */
        left: 0;
        z-index: 100; /* Behind the navbar */
        padding: 48px 0 0; /* Height of navbar */
        box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
        }

        @media (max-width: 767.98px) {
        .sidebar {
            top: 5rem;
        }
        }

        .sidebar-sticky {
        position: relative;
        top: 0;
        height: calc(100vh - 48px);
        padding-top: .5rem;
        overflow-x: hidden;
        overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
        }

        .sidebar .nav-link {
        font-weight: 500;
        color: #333;
        }

        .sidebar .nav-link .feather {
        margin-right: 4px;
        color: #727272;
        }

        .sidebar .nav-link.active {
        color: #2470dc;
        }

        .sidebar .nav-link:hover .feather,
        .sidebar .nav-link.active .feather {
        color: inherit;
        }

        .sidebar-heading {
        font-size: .75rem;
        text-transform: uppercase;
        }

        /*
        * Navbar
        */

        .navbar-brand {
        padding-top: .75rem;
        padding-bottom: .75rem;
        font-size: 1rem;
        background-color: rgba(0, 0, 0, .25);
        box-shadow: inset -1px 0 0 rgba(0, 0, 0, .25);
        }

        .navbar .navbar-toggler {
        top: .25rem;
        right: 1rem;
        }

        .navbar .form-control {
        padding: .75rem 1rem;
        border-width: 0;
        border-radius: 0;
        }

        .form-control-dark {
        color: #fff;
        background-color: rgba(255, 255, 255, .1);
        border-color: rgba(255, 255, 255, .1);
        }

        .form-control-dark:focus {
        border-color: transparent;
        box-shadow: 0 0 0 3px rgba(255, 255, 255, .25);
        }
        #scrobble-form { width: 100% }
        </style>
        {% block head_extra %}{% endblock %}

        <link rel="apple-touch-icon" href="{% static 'images/apple-touch-icon.png' %}">
    </head>
    <body>
        <header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
            <a class="navbar-brand col-md-3 col-lg-2 me-0 px-3" href="#">Vrobbler</a>
            <button class="navbar-toggler position-absolute d-md-none collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#sidebarMenu" aria-controls="sidebarMenu" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>

            {% if user.is_authenticated %}
            <form id="scrobble-form" action="{% url 'scrobbles:imdb-manual-scrobble' %}" method="post">
                {% csrf_token %}
                {{ imdb_form }}
            </form>
            {% endif %}
            <div class="navbar-nav">
                <div class="nav-item text-nowrap">
                    {% if user.is_authenticated %}
                    <a class="nav-link px-3" href="{% url "account_logout" %}">Sign out</a>
                    {% else %}
                    <a class="nav-link px-3" href="{% url "account_login" %}">Sign in</a>
                {% endif %}
                </div>
            </div>
        </header>

        <div class="container-fluid">
            <div class="row">
                <nav id="sidebarMenu" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
                    <div class="position-sticky pt-3">
                        {% if messages %}
                        <ul style="padding-right:10px;">
                        {% for message in messages %}
                        <li {% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
                        {% endfor %}
                        </ul>
                        {% endif %}
                        <ul class="nav flex-column">
                            <li class="nav-item">
                                <a class="nav-link active" aria-current="page" href="/">
                                <span data-feather="music"></span>
                                Dashboard
                                </a>
                            </li>
                            {% if user.is_authenticated %}
                            <li class="nav-item">
                                <a class="nav-link" aria-current="page" href="/charts/">
                                <span data-feather="bar-chart"></span>
                                Charts
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" aria-current="page" href="/tracks/">
                                <span data-feather="music"></span>
                                Tracks
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="/artists/">
                                <span data-feather="user"></span>
                                Artists
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="/albums/">
                                <span data-feather="music"></span>
                                Albums
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="/movies/">
                                <span data-feather="film"></span>
                                Movies
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="/series/">
                                <span data-feather="tv"></span>
                                TV Shows
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="/admin/">
                                <span data-feather="key"></span>
                                Admin
                                </a>
                            </li>
                            {% endif %}
                        </ul>
                        {% block extra_nav %}
                        {% endblock %}
                        <hr/>

                        {% if now_playing_list and user.is_authenticated %}
                        <ul style="padding-right:10px;">
                            <b>Now playing</b>
                            {% for scrobble in now_playing_list %}
                            <div>
                                {% if scrobble.media_obj.album.cover_image %}
                                <td><img src="{{scrobble.track.album.cover_image.url}}" width=120 height=120 style="border:1px solid black; " /></td><br/>
                                {% endif %}
                                <a href="{{scrobble.media_obj.get_absolute_url}}">{{scrobble.media_obj.title}}</a><br/>
                                {% if scrobble.media_obj.subtitle %}
                                <em><a href="{{scrobble.media_obj.subtitle.get_absolute_url}}">{{scrobble.media_obj.subtitle}}</a></em><br/>
                                {% endif %}
                                <small>{{scrobble.timestamp|naturaltime}}<br/> from {{scrobble.source}}</small>
                                <div class="progress-bar" style="margin-right:5px;">
                                    <span class="progress-bar-fill" style="width: {{scrobble.percent_played}}%;"></span>
                                </div>
                                <a href="{% url "scrobbles:cancel" scrobble.uuid %}">Cancel</a>
                                <a href="{% url "scrobbles:finish" scrobble.uuid %}">Finish</a>
                                <hr />
                            </div>
                            {% endfor %}
                        </ul>
                        <hr/>
                        {% endif %}

                        {% if active_imports %}
                        {% for import in active_imports %}
                        <ul style="padding-right:10px;">
                            <li>Import in progress ({{import.processing_started|naturaltime}})</li>
                        </ul>
                        {% endfor %}
                        {% endif %}

                    </div>
                </nav>

                {% block content %}
                {% endblock %}
            </div>
        </div>

        <script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js" integrity="sha384-uO3SXW5IuS1ZpFPKugNNWqTZRRglnUJK6UAZ/gxOX80nxEkN9NcGZTftn6RzhGWE" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js" integrity="sha384-zNy6FEbO50N+Cg5wap8IKA4M/ZnLJgzc6w2NqACZaK0u0FXfOWRRJOnQtpZun8ha" crossorigin="anonymous"></script>
        <script><!-- comment ------------------------------------------------->
            /* globals Chart:false, feather:false */
            (function () {
            'use strict'

            feather.replace({ 'aria-hidden': 'true' })

            // Graphs
            var ctx = document.getElementById('myChart')
            // eslint-disable-next-line no-unused-vars
            var myChart = new Chart(ctx, {
                type: 'line',
                data: {
                  labels: [
                      {% for day in weekly_data.keys %}
                      "{{day}}"{% if not forloop.last %},{% endif %}
                      {% endfor %}
                  ],
                  datasets: [{
                      data: [
                      {% for count in weekly_data.values %}
                      {{count}}{% if not forloop.last %},{% endif %}
                      {% endfor %}
                      ],
                      lineTension: 0,
                      backgroundColor: 'transparent',
                      borderColor: '#007bf0',
                      borderWidth: 4,
                      pointBackgroundColor: '#007bff'
                  }]
                },
                options: {
                  scales: {
                      yAxes: [{
                      ticks: {
                          beginAtZero: false
                      }
                      }]
                  },
                  legend: {
                      display: false
                  }
                }
            })
            })()

        </script>
        {% block extra_js %}
        {% endblock %}
    </body>
</html>
