<% ucid = channel.ucid %>
<% author = HTML.escape(channel.author) %>

<% content_for "header" do %>
<title><%= author %> - Invidious</title>
<% end %>

<% if channel.banner %>
    <div class="h-box">
        <img style="width:100%" src="/ggpht<%= URI.parse(channel.banner.not_nil!.gsub("=w1060-", "=w1280-")).request_target %>">
    </div>

    <div class="h-box">
        <hr>
    </div>
<% end %>

<div class="pure-g h-box">
    <div class="pure-u-2-3">
        <div class="channel-profile">
            <img src="/ggpht<%= URI.parse(channel.author_thumbnail).request_target %>">
            <span><%= author %></span>
        </div>
    </div>
    <div class="pure-u-1-3" style="text-align:right">
        <h3 style="text-align:right">
            <a href="/feed/channel/<%= ucid %>"><i class="icon ion-logo-rss"></i></a>
        </h3>
    </div>
</div>

<div class="h-box">
    <div id="descriptionWrapper">
        <p><span style="white-space:pre-wrap"><%= XML.parse_html(channel.description_html).xpath_node(%q(.//pre)).try &.content if !channel.description_html.empty? %></span></p>
    </div>
</div>

<div class="h-box">
    <% sub_count_text = number_to_short_text(channel.sub_count) %>
    <%= rendered "components/subscribe_widget" %>
</div>

<div class="pure-g h-box">
    <div class="pure-g pure-u-1-3">
        <div class="pure-u-1 pure-md-1-3">
            <a href="https://www.youtube.com/channel/<%= ucid %>/playlists"><%= translate(locale, "View channel on YouTube") %></a>
        </div>

        <div class="pure-u-1 pure-md-1-3">
            <% if env.get("preferences").as(Preferences).automatic_instance_redirect%>
                <a href="/redirect?referer=<%= env.get?("current_page") %>"><%= translate(locale, "Switch Invidious Instance") %></a>
            <% else %>
                <a href="https://redirect.invidious.io<%= env.request.resource %>"><%= translate(locale, "Switch Invidious Instance") %></a>
            <% end %>
        </div>

        <div class="pure-u-1 pure-md-1-3">
            <a href="/channel/<%= ucid %>"><%= translate(locale, "Videos") %></a>
        </div>
        <div class="pure-u-1 pure-md-1-3">
            <% if !channel.auto_generated %>
                <b><%= translate(locale, "Playlists") %></b>
            <% end %>
        </div>
        <div class="pure-u-1 pure-md-1-3">
            <% if channel.tabs.includes? "community" %>
                <a href="/channel/<%= ucid %>/community"><%= translate(locale, "Community") %></a>
            <% end %>
        </div>
    </div>
    <div class="pure-u-1-3"></div>
    <div class="pure-u-1-3">
        <div class="pure-g" style="text-align:right">
            <% {"last", "oldest", "newest"}.each do |sort| %>
                <div class="pure-u-1 pure-md-1-3">
                    <% if sort_by == sort %>
                        <b><%= translate(locale, sort) %></b>
                    <% else %>
                        <a href="/channel/<%= ucid %>/playlists?sort_by=<%= sort %>">
                            <%= translate(locale, sort) %>
                        </a>
                    <% end %>
                </div>
            <% end %>
        </div>
    </div>
</div>

<div class="h-box">
    <hr>
</div>

<div class="pure-g">
<% items.each do |item| %>
    <%= rendered "components/item" %>
<% end %>
</div>

<div class="pure-g h-box">
    <div class="pure-u-1 pure-u-md-4-5"></div>
    <div class="pure-u-1 pure-u-lg-1-5" style="text-align:right">
        <% if continuation %>
            <a href="/channel/<%= ucid %>/playlists?continuation=<%= continuation %><% if sort_by != "last" %>&sort_by=<%= URI.encode_www_form(sort_by) %><% end %>">
                <%= translate(locale, "Next page") %>
            </a>
        <% end %>
    </div>
</div>
