
{% extends 'base.html' %}
{% block content %}

            {% if messages %}
                {% for message in messages %}
                  <div class="alert alert-success alert-dismissible fade show" role="alert">
                      {{ message }}
                      <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                  </div>
                {% endfor %}
            {% else %}
                <br>
            {% endif %}
        {% if user.profile.playlists.all.count == 0 %}
            <div class="alert alert-success" role="alert">
              <h4 class="alert-heading">It's empty in here</h4>
              <p>
                  There's no playlists in your UnTube right now. You can change that by heading over to <a href="{% url 'manage_playlists' %}" class="btn btn-sm btn-primary">Manage</a> to import some public playlists into your UnTube.
                  {% if not user.profile.imported_yt_playlists %}
                      Or you could always head over to your <a href="{% url 'profile' %}" class="btn btn-sm btn-primary">Profile</a> to import all of your public/private YouTube playlists.
                  {% else %}
                      Keep in mind that your own YouTube playlists will automatically be imported into UnTube.
                  {% endif %}
              </p>
            </div>
        {% endif %}
        {% if import_successful %}
            <br>
                <br>
                <div class="d-flex justify-content-center pt-3 pb-2 mb-3">
                    <h1>Welcome to UnTube, {{ user.username|capfirst }}</h1>
                </div>
                  <div class="d-flex justify-content-center pt-3 pb-2 mb-3">
                            <h2>{{ user.profile.playlists.all.count }} playlists from YouTube have been successfully imported.</h2>
                  </div>

                  <div class="d-flex justify-content-center pt-3 pb-2 mb-3">
                        <h3>You'll now be notified on the Dashboard whenever there's any new un-exported playlists on YouTube :)</h3>
                  </div>


                <div class="d-flex justify-content-center pt-3 pb-2 mb-3">
                    <a href="{% url 'home' %}" class="btn btn-lg btn-success">Go to Dashboard</a>
                </div>

            {% else %}

            <!--
            <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">

                <h1 class="h2">Dashboard</h1>

                <span><small>Logged in as <b>{{ user.username }}</b></small></span>

            </div>
            -->

            {% if user.profile.imported_yt_playlists %}
            <div hx-get="{% url 'user_playlists_updates' 'check-for-updates' %}" hx-trigger="load" hx-swap="outerHTML">

            </div>
            {% endif %}



            {% if watching %}
                <div class="border border-5 rounded-3 border-primary p-3">
                    <h3><span style="border-bottom: 3px #ffffff dashed;">Continue Watching</span><i class="fas fa-fire-alt ms-2" style="color: #d24646"></i></h3>
           <div class="row row-cols-1 row-cols-md-4 g-4 text-dark mt-0">
                {% for playlist in watching|slice:"0:3" %}
                <div class="col">
                    <div class="card">
                        <a style="background-color: #7e89c2;" href="{% url 'playlist' playlist.playlist_id %}" class="list-group-item list-group-item-action" aria-current="true">
                            <div class="card-body">
                        <h5 class="card-title">
                           {{ playlist.name }}
                            {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
                            {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
                        </h5>
                        <p class="card-text">
                            <span class="badge bg-{% if playlist.watch_time_left == "0secs." %}success{% else %}info{% endif %} text-white">{{ playlist.num_videos_watched }}/{{ playlist.video_count }} viewed</span>

                            {% if playlist.watch_time_left != "0secs." %}<span class="badge bg-dark text-white">{{ playlist.watch_time_left }} left</span>{% endif %}

                        </p>
                            {% if playlist.tags.all %}
                        <small>
                        <i class="fas fa-tags fa-sm" style="color: yellow"></i>
                            {% for tag in playlist.tags.all %}
                                <span class="badge rounded-pill bg-primary mb-lg-1">
                                    {{ tag.name }}
                                </span>
                            {% endfor %}
                        </small>
                            {% endif %}
                        </div>
                        </a>
                    </div>
                </div>
                    {% if forloop.counter == 3 %}
                        {% if watching.count|add:"-3" != 0 %}
                        <div class="col">
                            <div class="card">
                                <a style="background-color: #7e89c2;" href="{% url 'all_playlists' 'watching' %}" class="list-group-item list-group-item-action" aria-current="true">
                                    <div class="card-body">

                                        <p class="card-text">
                                            <h3>+ {{ watching.count|add:"-3" }} more</h3>
                                        </p>
                                     </div>
                                </a>
                            </div>
                        </div>
                        {% endif %}
                    {% endif %}
                {% endfor %}
            </div>
            </div>
                <br>
                {% endif %}

            <h3><span style="border-bottom: 3px #ffffff dashed;">Most viewed playlists</span> <a href="{% url 'all_playlists' 'all' %}" class="pt-1"><i class="fas fa-binoculars"></i> </a></h3>
            {% if user_playlists %}
            <div class="row row-cols-1 row-cols-md-3 g-4 text-dark mt-0">
                {% for playlist in user_playlists|slice:"0:3" %}
                <div class="col">
                    <div class="card">
                        <a style="background-color: #35795b;" href="{% url 'playlist' playlist.playlist_id %}" class="list-group-item list-group-item-action" aria-current="true">
                            <div class="card-body">
                        <h5 class="card-title">
                           #{{ forloop.counter }} <br><br>{{ playlist.name }}
                            {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
                            {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
                        </h5>
                        <p class="card-text">
                            {% if playlist.description %}
                                {{ playlist.description|truncatewords:"15" }}
                            {% else %}
                                No description
                            {% endif %}
                        </p>
                        <small>
                            <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
                            <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
                            <span class="badge bg-secondary rounded-pill">{{ playlist.num_of_accesses }} clicks </span>

                        </small>
                        </div>
                        </a>
                    </div>
                </div>
                {% endfor %}

            </div>

            {% else %}
                <br>
            <h5>Nothing to see here... yet.</h5>
            {% endif %}


        <br>
            <h3><span style="border-bottom: 3px #ffffff dashed;">Recently Accessed</span> <i class="fas fa-redo fa-sm" style="color: #3c3fd2"></i></h3>

            {% if recently_accessed_playlists %}
            <div class="row row-cols-1 row-cols-md-3 g-4 text-dark mt-0">
                {% for playlist in recently_accessed_playlists %}
                <div class="col">
                    <div class="card">
                        <a style="background-color: #357779;" href="{% url 'playlist' playlist.playlist_id %}" class="list-group-item list-group-item-action" aria-current="true">
                            <div class="card-body">
                        <h5 class="card-title">
                           {{ playlist.name }}
                            {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
                            {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
                        </h5>
                        <p class="card-text">
                            {% if playlist.description %}
                                {{ playlist.description|truncatewords:"15" }}
                            {% else %}
                                No description
                            {% endif %}
                        </p>
                        <small>
                            <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
                            <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
                            <span class="badge bg-secondary rounded-pill">{{ playlist.num_of_accesses }} clicks </span>

                        </small>
                        </div>
                        </a>
                    </div>
                </div>
                {% endfor %}
            </div>
            {% else %}
            <br>
            <h5>Nothing to see here... yet.</h5>
            {% endif %}

        <br>
            <h3><span style="border-bottom: 3px #ffffff dashed;">Recently Added</span> <i class="fas fa-plus-square" style="color:#972727;"></i></h3>
            {% if recently_added_playlists %}
            <div class="row row-cols-1 row-cols-md-3 g-4 text-dark mt-0">
                {% for playlist in recently_added_playlists %}
                <div class="col">
                    <div class="card">
                        <a style="background-color: #958a44;" href="{% url 'playlist' playlist.playlist_id %}" class="list-group-item list-group-item-action" aria-current="true">
                            <div class="card-body">
                        <h5 class="card-title">
                           {{ playlist.name }}
                            {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
                            {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
                        </h5>
                        <p class="card-text">
                            {% if playlist.description %}
                                {{ playlist.description|truncatewords:"15" }}
                            {% else %}
                                No description
                            {% endif %}
                        </p>
                        <small>
                            <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
                            <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
                            <span class="badge bg-secondary rounded-pill">{{ playlist.num_of_accesses }} clicks </span>

                        </small>
                        </div>
                        </a>
                    </div>
                </div>
                {% endfor %}
            </div>
             {% else %}
            <br>
            <h5>You have no playlists ;-;</h5>
            {% endif %}
        <br>


        {% endif %}


{% endblock %}