{% extends "home/base.html" %}
{% load static %}
{% block content %}
<div class="boxed-content">
    <div class="title-split">
        <div class="title-bar">
            <h1>Playlists</h1>
        </div>
        <div class="title-split-form">
            <img id="animate-icon" onclick="showForm()" src="{% static 'img/icon-add.svg' %}" alt="add-icon" title="Subscribe to Playlists">
            <div class="show-form">
                <form id="hidden-form" action="/playlist/" method="post">
                    {% csrf_token %}
                    {{ subscribe_form }}
                    <button type="submit">Subscribe</button>
                </form>
            </div>
        </div>
    </div>
    <div id="notifications" data="subscription"></div>
    <div class="view-controls">
        <div class="toggle">
            <span>Show subscribed only:</span>
            <div class="toggleBox">
                <input id="show_subed_only" onclick="toggleCheckbox(this)" type="checkbox" {% if show_subed_only %}checked{% endif %}>
                {% if not show_subed_only %}
                    <label for="" class="ofbtn">Off</label>
                {% else %}
                    <label for="" class="onbtn">On</label>
                {% endif %}
            </div>
        </div>
        <div class="view-icons">
            <img src="{% static 'img/icon-gridview.svg' %}" onclick="changeView(this)" data-origin="playlist" data-value="grid" alt="grid view">
            <img src="{% static 'img/icon-listview.svg' %}" onclick="changeView(this)" data-origin="playlist" data-value="list" alt="list view">
        </div>
    </div>
    <div class="playlist-list {{ view_style }}">
        {% if results %}
            {% for playlist in results %}
            <div class="playlist-item {{ view_style }}">
                <div class="playlist-thumbnail">
                    <a href="{% url 'playlist_id' playlist.source.playlist_id %}">
                        <img src="/cache/playlists/{{ playlist.source.playlist_id }}.jpg" alt="{{ playlist.source.playlist_id }}-thumbnail">
                    </a>
                </div>
                <div class="playlist-desc {{ view_style }}">
                    <a href="{% url 'channel_id' playlist.source.playlist_channel_id %}"><h3>{{ playlist.source.playlist_channel }}</h3></a>
                    <a href="{% url 'playlist_id' playlist.source.playlist_id %}"><h2>{{ playlist.source.playlist_name }}</h2></a>
                    <p>Last refreshed: {{ playlist.source.playlist_last_refresh }}</p>
                    {% if playlist.source.playlist_subscribed %}
                        <button class="unsubscribe" type="button" id="{{ playlist.source.playlist_id }}" onclick="unsubscribe(this.id)" title="Unsubscribe from {{ playlist.source.playlist_name }}">Unsubscribe</button>
                    {% else %}
                        <button type="button" id="{{ playlist.source.playlist_id }}" onclick="subscribe(this.id)" title="Subscribe to {{ playlist.source.playlist_name }}">Subscribe</button>
                    {% endif %}
                </div>
            </div>
            {% endfor %}
        {% else %}
            <h2>No playlists found...</h2>
        {% endif %}
    </div>
</div>
<script type="text/javascript" src="{% static 'progress.js' %}"></script>
{% endblock content %}