{% extends "base.html" %}

{% block content %}
<div class="ui text container">
    <form class="ui form" action="" method="post" novalidate>
        {{ form.hidden_tag() }}
        <p>
            {{ form.channelId.label }}<br>
            {{ form.channelId(size=32) }}<br>
            {% for error in form.channelId.errors %}
            <span style="color: red;">[{{ error }}]</span>
            {% endfor %}
        </p>
        <p>{{ form.submit() }}</p>
    </form>

    {% if results %}
    <h3 class="ui dividing header">Users</h3>
            <div class="ui relaxed divided list">

                    {% for res in results.channels %}
                    <div class="item">
                        <div class="image">
                            {% if config.nginxVideoStream %}
                                <img src="{{res.thumbnail}}" alt="Avatar">
                            {% else %}    
                                <img alt="Avatar" src="{{ url_for('img', url=res.thumbnail) }}">
                            {% endif %}
                        </div>
                        <div class="content">
                          <a class = "header" href="{{ url_for('channel', id=res.channelId)}}">{{res.username}}</a>
                          <div class="meta">
                            <span>{{res.description}}</span>
                          </div>
                          <div class="description">
                            <p></p>
                          </div>
                          <div class="extra">
                            <div class="ui label">
                                <i class="user icon"></i> {{res.suscribers}}
                            </div>

                            <div class="ui label">
                                <i class="video icon"></i> {{res.videos}}
                            </div>
                            
                            {% if restricted or current_user.is_authenticated %}
                                <div class="right floated content">
                                {% if not current_user.is_following_yt(res.channelId) %}
                                    <form action="{{ url_for('ytfollow', channelId=res.channelId) }}" method="post">
                                        {{ btform.hidden_tag() }}
                                        {{ btform.submit(value='Follow') }}
                                    </form>
                                {% else %}
                                    <form action="{{ url_for('ytunfollow', channelId=res.channelId) }}" method="post">
                                        {{ btform.hidden_tag() }}
                                        {{ btform.submit(value='Unfollow') }}
                                    </form>
                                {% endif %}
                                </div>  
                            {% endif %}
                          </div>
                        </div>
                    </div>
                    {% endfor %}
                </div>
            {% endif %}


            <div class="ui middle aligned divided list">
                {% if results.videos %}
                <h3 class="ui dividing header">Videos</h3>
                    <div class="ui centered cards">
                        {% for video in results.videos %}
                            {% include '_video_item.html' %}
                        {% endfor %}
                    </div>
                {% endif %}
            </div>
</div>

{% endblock %}