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

    <div id="search-results">

        <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 mb-3">
            <h1 class="h2"><span style="border-bottom: 3px #ffffff dashed;">{{ playlist_type_display|title }}</span> <span class="badge bg-primary rounded-pill">{{ playlists.count }}</span></h1>

            {% if playlists %}
            <div class="btn-toolbar mb-2 mb-md-0">
                <!--
                <div class="btn-group me-2">
                    <button type="button" class="btn btn-outline-info">Grid</button>
                    <button type="button" class="btn btn-outline-info">List</button>
                </div>
                -->
                <div class="btn-group">
                  <button type="button" class="btn btn-success dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
                    Sort By
                  </button>
                  <ul class="dropdown-menu">
                    <li class="dropdown-item"><a hx-get="{% url 'order_playlists_by' playlist_type 'playlist-duration-in-seconds' %}" hx-trigger="click" hx-target="#search-results">Duration</a></li>
                    <li class="dropdown-item"><a hx-get="{% url 'order_playlists_by' playlist_type 'video-count' %}" hx-trigger="click" hx-target="#search-results"># Videos</a></li>
                    <li class="dropdown-item"><a hx-get="{% url 'order_playlists_by' playlist_type 'recently-accessed' %}" hx-trigger="click" hx-target="#search-results">Recently Accessed</a></li>
                  </ul>
                </div>

            </div>
            {% endif %}

        </div>

        {% if playlists %}
        <div class="">
            <input   class="form-control border border-secondary" type="text"
       name="search" placeholder="Begin to search playlists..."
       hx-post="{% url 'search_playlists' playlist_type %}"
       hx-trigger="keyup changed delay:500ms"
       hx-target="#search-results"
       hx-indicator=".htmx-indicator">
          <br>
        </div>

        <div class="row row-cols-1 row-cols-md-3 g-4">
                {% for playlist in playlists %}
                <div class="col">
                    <div class="card" style="background-color: #515355;">
                        <a style="background-color: #1A4464;" href="{% url 'playlist' playlist.playlist_id %}" class="list-group-item list-group-item-action text-white-50" aria-current="true">

                            <div class="card-body">

                                <h5 class="card-title text-white">
                                    {{ playlist.name }}

                                </h5>
                                <p class="card-text">
                                    {% if playlist.is_user_owned %}<small><span class="badge bg-light text-black-50">OWNED</span></small>{% else %}<small><span class="badge bg-light text-black-50">IMPORTED</span></small>{% endif %}

                                    {% if playlist.is_private_on_yt %}<small><span class="badge bg-secondary text-white">Private</span></small> {% endif %}
                                    {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-black-50">YT</span></small> {% endif %}

                                </p>
                                {% if playlist.tags.all %}
                                <p class="card-text">
                                    <span class="d-flex justify-content-start flex-wrap">
                                        <small>
                                        <span style="color: #eed868;" class="me-lg-1 mb-lg-1">
                                            <i class="fas fa-tags"></i>
                                        </span>
                                        </small>
                                        {% for tag in playlist.tags.all %}
                                            <span class="badge rounded-pill bg-info mb-lg-1 me-lg-1 text-black-50">
                                                {{ tag.name }}
                                            </span>
                                        {% endfor %}
                                    </span>
                                </p>
                                {% endif %}
                                <small>
                                    <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
                                    <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
                                </small>
                            </div>
                        </a>
                    </div>
                </div>
                {% endfor %}


        </div>
        {% else %}
              <div class="card bg-dark text-white mb-3">
            <div class="card-body">
                <div class="d-flex justify-content-center h3">
                    Nothing here!
                </div>
                <div class="d-flex justify-content-center h5">
                    {% if playlist_type == "watching" %}
                        You can mark a playlist as watching by heading over to the playlist and marking it from the dropdown.
                    {% elif playlist_type == "all" %}
                        There's no playlists in your UnTube right now.
                    {% elif playlist_type == "imported" %}
                        To import public playlists into your UnTube collection you can head over to <a href="{% url 'manage_playlists' %}" class="btn btn-sm btn-primary ms-2">Manage</a>
                    {% elif playlist_type == "plan-to-watch" %}
                        You can mark a playlist as plan to watch by heading over to the playlist and marking it from the dropdown.
                    {% elif playlist_type == "favorites" %}
                        You can mark a playlist as favorite by heading over to the playlist page and pressing the star icon.
                    {% elif playlist_type == "user-owned" %}
                        {% if user.profile.imported_yt_playlists %}
                            Looks like you have no playlists on YouTube.
                        {% else %}
                            You can always head over to your <a href="{% url 'profile' %}" class="btn btn-sm btn-primary p-2">Profile</a> to import all of your public/private YouTube playlists.
                        {% endif %}
                    {% else %}
                        {{ playlist_type }}
                    {% endif %}
                </div>
            </div>
            </div>

        {% endif %}
        <br>

    </div>



{% endblock %}