{% extends "home/base.html" %}
{% block content %}
{% load static %}
<div class="boxed-content {% if view_style == "grid" %}boxed-{{ grid_items }}{% endif %}">
    {% if continue_vids %}
        <div class="title-bar">
            <h1>Continue Watching</h1>
        </div>
        <div class="video-list {{ view_style }} {% if view_style == "grid" %}grid-{{ grid_items }}{% endif %}">
            {% for video in continue_vids %}
                <div class="video-item {{ view_style }}">
                    <a href="#player" data-id="{{ video.youtube_id }}" onclick="createPlayer(this)">
                        <div class="video-thumb-wrap {{ view_style }}">
                            <div class="video-thumb">
                                <img src="{{ video.vid_thumb_url }}" alt="video-thumb">
                                {% if video.player.progress %}
                                    <div class="video-progress-bar" id="progress-{{ video.youtube_id }}" style="width: {{video.player.progress}}%;"></div>
                                {% else %}
                                    <div class="video-progress-bar" id="progress-{{ video.youtube_id }}" style="width: 0%;"></div>
                                {% endif %}
                            </div>
                            <div class="video-play">
                                <img src="{% static 'img/icon-play.svg' %}" alt="play-icon">
                            </div>
                        </div>
                    </a>
                    <div class="video-desc {{ view_style }}">
                        <div class="video-desc-player" id="video-info-{{ video.youtube_id }}">
                            {% if video.player.watched %}
                                <img src="{% static 'img/icon-seen.svg' %}" alt="seen-icon" data-id="{{ video.youtube_id }}" data-status="watched" onclick="updateVideoWatchStatus(this)" class="watch-button" title="Mark as unwatched">
                            {% else %}
                                <img src="{% static 'img/icon-unseen.svg' %}" alt="unseen-icon" data-id="{{ video.youtube_id }}" data-status="unwatched" onclick="updateVideoWatchStatus(this)" class="watch-button" title="Mark as watched">
                            {% endif %}
                            <span>{{ video.published }} | {{ video.player.duration_str }}</span>
                        </div>
                        <div>
                            <a href="{% url 'channel_id' video.channel.channel_id %}"><h3>{{ video.channel.channel_name }}</h3></a>
                            <a class="video-more" href="{% url 'video' video.youtube_id %}"><h2>{{ video.title }}</h2></a>
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
    {% endif %}
    <div class="title-bar">
        <h1>Recent Videos</h1>
    </div>
    <div class="view-controls three">
        <div class="toggle">
            <span>Hide watched:</span>
            <div class="toggleBox">
                <input id="hide_watched" onclick="toggleCheckbox(this)" type="checkbox" {% if hide_watched %}checked{% endif %}>
                {% if not hide_watched %}
                    <label for="" class="ofbtn">Off</label>
                {% else %}
                    <label for="" class="onbtn">On</label>
                {% endif %}
            </div>
        </div>
        <div class="sort">
            <div id="hidden-form">
                <span>Sort by:</span>
                <select name="sort" id="sort" onchange="sortChange(this.value)">
                    <option value="published" {% if sort_by == "published" %}selected{% endif %}>date published</option>
                    <option value="downloaded" {% if sort_by == "downloaded" %}selected{% endif %}>date downloaded</option>
                    <option value="views" {% if sort_by == "views" %}selected{% endif %}>views</option>
                    <option value="likes" {% if sort_by == "likes" %}selected{% endif %}>likes</option>
                </select>
                <select name="sord-order" id="sort-order" onchange="sortChange(this.value)">
                    <option value="asc" {% if sort_order == "asc" %}selected{% endif %}>asc</option>
                    <option value="desc" {% if sort_order == "desc" %}selected{% endif %}>desc</option>
                </select>
            </div>
        </div>
        <div class="view-icons">
            <img src="{% static 'img/icon-sort.svg' %}" alt="sort-icon" onclick="showForm()" id="animate-icon">
            {% if view_style == "grid" %}
                <div class="grid-count">
                    {% if grid_items < 7 %}
                        <img src="{% static 'img/icon-add.svg' %}" onclick="changeGridItems(this)" data-value="{{ grid_items|add:"1"}}" alt="grid plus row">
                    {% endif %}
                    {% if grid_items > 3 %}
                        <img src="{% static 'img/icon-substract.svg' %}" onclick="changeGridItems(this)" data-value="{{ grid_items|add:"-1"}}" alt="grid minus row">
                    {% endif %}
                </div>
            {% endif %}
            <img src="{% static 'img/icon-gridview.svg' %}" onclick="changeView(this)" data-origin="home" data-value="grid" alt="grid view">
            <img src="{% static 'img/icon-listview.svg' %}" onclick="changeView(this)" data-origin="home" data-value="list" alt="list view">
        </div>
    </div>
</div>
<div id="player" class="player-wrapper"></div>
<div class="boxed-content {% if view_style == "grid" %}boxed-{{ grid_items }}{% endif %}">
    <div class="video-list {{ view_style }} {% if view_style == "grid" %}grid-{{ grid_items }}{% endif %}">
        {% if results %}
            {% for video in results %}
                <div class="video-item {{ view_style }}">
                    <a href="#player" data-id="{{ video.youtube_id }}" onclick="createPlayer(this)">
                        <div class="video-thumb-wrap {{ view_style }}">
                            <div class="video-thumb">
                                <img src="{{ video.vid_thumb_url }}" alt="video-thumb">
                                {% if video.player.progress %}
                                    <div class="video-progress-bar" id="progress-{{ video.youtube_id }}" style="width: {{video.player.progress}}%;"></div>
                                {% else %}
                                    <div class="video-progress-bar" id="progress-{{ video.youtube_id }}" style="width: 0%;"></div>
                                {% endif %}
                            </div>
                            <div class="video-play">
                                <img src="{% static 'img/icon-play.svg' %}" alt="play-icon">
                            </div>
                        </div>
                    </a>
                    <div class="video-desc {{ view_style }}">
                        <div class="video-desc-player" id="video-info-{{ video.youtube_id }}">
                            {% if video.player.watched %}
                                <img src="{% static 'img/icon-seen.svg' %}" alt="seen-icon" data-id="{{ video.youtube_id }}" data-status="watched" onclick="updateVideoWatchStatus(this)" class="watch-button" title="Mark as unwatched">
                            {% else %}
                                <img src="{% static 'img/icon-unseen.svg' %}" alt="unseen-icon" data-id="{{ video.youtube_id }}" data-status="unwatched" onclick="updateVideoWatchStatus(this)" class="watch-button" title="Mark as watched">
                            {% endif %}
                            <span>{{ video.published }} | {{ video.player.duration_str }}</span>
                        </div>
                        <div>
                            <a href="{% url 'channel_id' video.channel.channel_id %}"><h3>{{ video.channel.channel_name }}</h3></a>
                            <a class="video-more" href="{% url 'video' video.youtube_id %}"><h2>{{ video.title }}</h2></a>
                        </div>
                    </div>
                </div>
            {% endfor %}
        {% else %}
            <h2>No videos found...</h2>
            <p>If you've already added a channel or playlist, try going to the <a href="{% url 'downloads' %}">downloads page</a> to start the scan and download tasks.</p>
        {% endif %}
    </div>
</div>
{% endblock content %}