{% extends "home/base.html" %}
{% block content %}
{% load static %}
<div class="boxed-content">
    <div class="title-bar">
        <h1>Recent Videos</h1>
    </div>
    <div class="info-box info-box-2">
        <div class="sort">
            <p>Sort by <span class="settings-current">{{ sort_by }}</span>
                <select name="sort" id="sort" onchange="sortChange(this.value)">
                    <option value="" disabled selected> -- change sort by -- </option>
                    <option value="published">date published</option>
                    <option value="downloaded">date downloaded</option>
                    <option value="views">views</option>
                    <option value="likes">likes</option>
                </select>
                <select name="sord-order" id="sort-order" onchange="sortChange(this.value)">
                    {% if sort_order == "asc" %}
                        <option value="asc" selected>asc</option>
                    {% else %}
                        <option value="asc">asc</option>
                    {% endif %}
                    {% if sort_order == "desc" %}
                        <option value="desc" selected>desc</option>
                    {% else %}
                        <option value="desc">desc</option>
                    {% endif %}
                </select>
            </p>
        </div>
        <div class="search-form icon-text">
            <div class="search-icon">
                <img src="{% static 'img/icon-search.svg' %}" alt="search-icon" onclick="showSearch()">
            </div>
            <form action="/" method="POST" id="search-box">
                {% csrf_token %}
                {{ search_form }}
            </form>
        </div>
    </div>
    <div class="view-controls">
        <div class="toggle">
            <span>Hide watched videos:</span>
            <div class="toggleBox">
                <input 
                    id="hide_watched" onclick="toggleCheckbox(this)" type="checkbox"
                    {% if hide_watched %}
                        checked
                    {% endif %}
                    >
                <label for="" class="onbtn">On</label>
                <label for="" class="ofbtn">Off</label>
            </div>
        </div>
        <div class="view-icons">
            <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">
    <div class="video-list {{ view_style }}">
        {% if videos %}
            {% for video in videos %}
                <div class="video-item {{ view_style }}">
                    <a href="#player" data-src="/media/{{ video.source.media_url }}" data-thumb="/cache/{{ video.source.vid_thumb_url }}" data-title="{{ video.source.title }}" data-channel="{{ video.source.channel.channel_name }}" data-channel-id="{{ video.source.channel.channel_id }}" data-id="{{ video.source.youtube_id }}" onclick="createPlayer(this)">
                        <div class="video-thumb-wrap {{ view_style }}">
                            <div class="video-thumb">
                                <img src="/cache/{{ video.source.vid_thumb_url }}" alt="video-thumb">
                            </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.source.youtube_id }}">
                            {% if video.source.player.watched %}
                                <img src="{% static 'img/icon-seen.svg' %}" alt="seen-icon" id="{{ video.source.youtube_id }}" onclick="isUnwatched(this.id)" class="seen-icon" title="Mark as unwatched">
                            {% else %}
                                <img src="{% static 'img/icon-unseen.svg' %}" alt="unseen-icon" id="{{ video.source.youtube_id }}" onclick="isWatched(this.id)" class="unseen-icon" title="Mark as watched.">
                            {% endif %}
                            <span>{{ video.source.published }} | {{ video.source.player.duration_str }}</span>
                        </div>
                        <div>
                            <a href="{% url 'channel_id' video.source.channel.channel_id %}"><h3>{{ video.source.channel.channel_name }}</h3></a>
                            <a class="video-more" href="{% url 'video' video.source.youtube_id %}"><h2>{{ video.source.title }}</h2></a>
                        </div>
                    </div>
                </div>
            {% endfor %}
        {% else %}
            <h2>No videos found...</h2>
        {% endif %}
    </div>
</div>
{% endblock content %}