{% extends "home/base.html" %}
{% block content %}
{% load static %}
{% load humanize %}
<div class="boxed-content">
    <div class="channel-banner">
        <a href="{% url 'channel_id' channel_info.channel_id %}"><img src="{{ channel_info.channel_banner_url }}" alt="channel_banner"></a>
    </div>
    <div class="info-box-item child-page-nav">
        <a href="{% url 'channel_id' channel_info.channel_id %}"><h3>Videos</h3></a>
        {% if has_streams %}
            <a href="{% url 'channel_id_live' channel_info.channel_id %}"><h3>Streams</h3></a>
        {% endif %}
        {% if has_shorts %}
            <a href="{% url 'channel_id_shorts' channel_info.channel_id %}"><h3>Shorts</h3></a>
        {% endif %}
        {% if has_playlists %}
            <a href="{% url 'channel_id_playlist' channel_info.channel_id %}"><h3>Playlists</h3></a>
        {% endif %}
        <a href="{% url 'channel_id_about' channel_info.channel_id %}"><h3>About</h3></a>
        {% if has_pending %}
            <a href="{% url 'downloads' %}?channel={{ channel_info.channel_id }}"><h3>Downloads</h3></a>
        {% endif %}
    </div>
    <div id="notifications" data="channel reindex"></div>
    <div class="info-box info-box-3">
        <div class="info-box-item">
            <div class="round-img">
                <a href="{% url 'channel_id' channel_info.channel_id %}">
                    <img src="{{ channel_info.channel_thumb_url }}" alt="channel-thumb">
                </a>
            </div>
            <div>
                <h3><a href="{% url 'channel_id' channel_info.channel_id %}">{{ channel_info.channel_name }}</a></h3>
                {% if channel_info.channel_subs >= 1000000 %}
                    <p>Subscribers: {{ channel_info.channel_subs|intword }}</p>
                {% else %}
                    <p>Subscribers: {{ channel_info.channel_subs|intcomma }}</p>
                {% endif %}
            </div>
        </div>
        <div class="info-box-item">
            <div>
                <p>Last refreshed: {{ channel_info.channel_last_refresh }}</p>
                {% if channel_info.channel_active %}
                    <p>Youtube: <a href="https://www.youtube.com/channel/{{ channel_info.channel_id }}" target="_blank">Active</a></p>
                {% else %}
                    <p>Youtube: Deactivated</p>
                {% endif %}
            </div>
        </div>
        <div class="info-box-item">
            <div>
                {% if channel_info.channel_views >= 1000000 %}
                    <p>Channel views: {{ channel_info.channel_views|intword }}</p>
                {% elif channel_info.channel_views > 0 %}
                    <p>Channel views: {{ channel_info.channel_views|intcomma }}</p>
                {% endif %}
                <div class="button-box">
                    <button onclick="deleteConfirm()" id="delete-item">Delete Channel</button>
                    <div class="delete-confirm" id="delete-button">
                        <span>Delete {{ channel_info.channel_name }} including all videos? </span><button class="danger-button" onclick="deleteChannel(this)" data-id="{{ channel_info.channel_id }}">Delete</button> <button onclick="cancelDelete()">Cancel</button>
                    </div>
                </div>
                {% if reindex %}
                    <p>Reindex scheduled</p>
                {% else %}
                    <div id="reindex-button" class="button-box">
                        <button data-id="{{ channel_info.channel_id }}" data-type="channel" onclick="reindex(this)" title="Reindex Channel {{ channel_info.channel_name }}">Reindex</button>
                        <button data-id="{{ channel_info.channel_id }}" data-type="channel" data-extract-videos="true" onclick="reindex(this)" title="Reindex Videos of {{ channel_info.channel_name }}">Reindex Videos</button>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>
    {% if channel_info.channel_description %}
        <div class="description-box">
            <p id="text-expand" class="description-text">
                {{ channel_info.channel_description|linebreaksbr|urlizetrunc:50 }}
            </p>
            <button onclick="textExpand()" id="text-expand-button">Show more</button>
        </div>
    {% endif %}
    {% if channel_info.channel_tags %}
        <div class="description-box">
            <div class="video-tag-box">
                {% for tag in channel_info.channel_tags %}
                    <span class="video-tag">{{ tag }}</span>
                {% endfor %}
            </div>
        </div>
    {% endif %}
    <div id="overwrite-form" class="info-box">
        <div class="info-box-item">
            <h2>Customize {{ channel_info.channel_name }}</h2>
            <form class="overwrite-form" action="/channel/{{ channel_info.channel_id }}/about/" method="POST">
                {% csrf_token %}
                <div class="overwrite-form-item">
                    <p>Download format: <span class="settings-current">
                        {% if channel_info.channel_overwrites.download_format %}
                            {{ channel_info.channel_overwrites.download_format }}
                        {% else %}
                            False
                        {% endif %}</span></p>
                    {{ channel_overwrite_form.download_format }}<br>
                </div>
                <div class="overwrite-form-item">
                    <p>Auto delete watched videos after x days: <span class="settings-current">
                        {% if channel_info.channel_overwrites.autodelete_days %}
                            {{ channel_info.channel_overwrites.autodelete_days }}
                        {% else %}
                            False
                        {% endif %}</span></p>
                    {{ channel_overwrite_form.autodelete_days }}<br>
                </div>
                <div class="overwrite-form-item">
                    <p>Index playlists: <span class="settings-current">
                        {% if channel_info.channel_overwrites.index_playlists %}
                            {{ channel_info.channel_overwrites.index_playlists }}
                        {% else %}
                            False
                        {% endif %}</span></p>
                    {{ channel_overwrite_form.index_playlists }}<br>
                </div>
                <div class="overwrite-form-item">
                    <p>Enable <a href="https://sponsor.ajay.app/" target="_blank">SponsorBlock</a>: <span class="settings-current">
                        {% if channel_info.channel_overwrites.integrate_sponsorblock %}
                            {{ channel_info.channel_overwrites.integrate_sponsorblock }}
                        {% elif channel_info.channel_overwrites.integrate_sponsorblock == False %}
                            Disabled
                        {% else %}
                            False
                        {% endif %}</span></p>
                    {{ channel_overwrite_form.integrate_sponsorblock }}<br>
                </div>
                <button type="submit">Save Channel Overwrites</button>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript" src="{% static 'progress.js' %}"></script>
{% endblock content %}