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

            {% if messages %}
                <br>
                {% 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 %}
            {% 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 able to import/export playlists from YouTube and UnTube :)</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>

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

            </div>




            <div class="accordion" id="accordionExample">
                <div class="accordion-item bg-dark text-white">
                    <h2 class="accordion-header" id="headingTwo">
                      <button style="background-color: #cdc6e2" class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
                        Statistics
                      </button>
                    </h2>
                    <div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordionExample">
                      <div class="accordion-body d-flex justify-content-evenly">
                          <div class="card" style="width: 18rem;">
                              <div class="card-body text-black-50">
                                <h5 class="card-title">25 total playlists</h5>
                                  <ul>
                                <h5 class="card-title">24 owned</h5>
                                      <ul>
                                          <h5 class="card-title">4 private</h5>
                                        <h5 class="card-title">24 public</h5>

                                      </ul>
                                 <h5 class="card-title">36 Imported</h5>
                                      <ul>
                                          <h5 class="card-title">24 mixes</h5>
                                        <h5 class="card-title">12 others</h5>

                                      </ul>
                                  </ul>
                              </div>
                        </div>
                          <div class="card" style="width: 18rem;">
                              <div class="card-body">
                                <h5 class="card-title">Card title</h5>
                                <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
                                <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                                <a href="#" class="card-link">Card link</a>
                                <a href="#" class="card-link">Another link</a>
                              </div>
                        </div>
                                                    <div class="card" style="width: 18rem;">
                              <div class="card-body">
                                <h5 class="card-title">Card title</h5>
                                <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
                                <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                                <a href="#" class="card-link">Card link</a>
                                <a href="#" class="card-link">Another link</a>
                              </div>
                        </div>
                          <div class="card" style="width: 18rem;">
                              <div class="card-body">
                                <h5 class="card-title">Card title</h5>
                                <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
                                <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                                <a href="#" class="card-link">Card link</a>
                                <a href="#" class="card-link">Another link</a>
                              </div>
                        </div>

                      </div>
                    </div>
                  </div>
            </div>
            {% if watching %}
                <br>
                <div class="border border-5 rounded-3 border-primary p-3">
            <h3>Continue Watching</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-info text-white">15/23 viewed</span>

                            <span class="badge bg-dark text-white">3hr. 4min. left</span>

                        </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>
                    {% 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>
                {% endif %}

            <br>
            <h3>Most viewed playlists <a href="{% url 'all_playlists' 'all' %}" class="btn btn-sm btn-info">View All</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 %}
            <h5>You have no playlists ;-;</h5>
            {% endif %}


        <br>
            <h3>Recently Accessed</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 %}
            <h5>You have no playlists ;-;</h5>
            {% endif %}

        <br>
            <h3>Recently Added</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 %}
            <h5>You have no playlists ;-;</h5>
            {% endif %}
        <br>


        {% endif %}


{% endblock %}