<h1>Featured Links</h1>
<p class="is-lead">Featured links allow you as a moderator to draw attention to issues or posts of importance to the community. Use them sparingly and only when needed, because they tend to get ignored if used too often.</p>

<div class="grid has-margin-bottom-4">
    <% if current_user.is_global_moderator %>
    <div class="grid--cell">
        <div class="button-list is-gutterless">
            <%= link_to "current community", query_url(global: '0', filter: params[:filter] || 'active'),
                        class: "button is-muted is-outlined #{(params[:global] == '0' || params[:global].nil?) ? 'is-active' : ''}" %>
            <%= link_to "global", query_url(global: '1', filter: params[:filter] || 'active'),
                        class: "button is-muted is-outlined #{(params[:global] == '1') ? 'is-active' : ''}" %>
            <%= link_to "everywhere", query_url(global: '2', filter: params[:filter] || 'active'),
                        class: "button is-muted is-outlined #{(params[:global] == '2') ? 'is-active' : ''}" %>
        </div>
    </div>
    <% end %>
    <div class="grid--cell">
        <div class="button-list is-gutterless">
            <%= link_to "active", query_url(global: params[:global] || '0', filter: 'active'),
                        class: "button is-muted is-outlined #{(params[:filter] == 'active' || params[:filter].nil?) ? 'is-active' : ''}" %>
            <%= link_to "inactive", query_url(global: params[:global] || '0', filter: 'inactive'),
                        class: "button is-muted is-outlined #{(params[:filter] == 'inactive') ? 'is-active' : ''}" %>
            <%= link_to "all", query_url(global: params[:global] || '0', filter: 'all'),
                        class: "button is-muted is-outlined #{(params[:filter] == 'all') ? 'is-active' : ''}" %>
        </div>
    </div>
    <div class="grid--cell is-flexible">
    </div>
    <div class="grid--cell">
        <div class="button-list is-gutterless">
            <a href="<%= new_pinned_link_path %>" class="button is-filled"><i class="fa fa-plus"></i> New</a>
        </div>
    </div>
</div>

<table class="table is-with-hover">
    <tr>
        <th>type</th>
        <th>shown label</th>
        <th>links to</th>
        <th>begins</th>
        <th>ends</th>
        <th>active?</th>
        <% if current_user.is_global_moderator %>
            <th>community</th>
        <% end %>
        <th>actions</th>
    </tr>
    <% @links.each do |pl| %>
        <% pl_link = pl.post.nil? ? pl.link : ('Post #' + pl.post.id.to_s) %>
        <% pl_label = pl.post.nil? ? pl.label : (pl.post.parent.nil? ? pl.post.title : pl.post.parent.title) %>
        <tr>
            <td>
                <% if pl.shown_before.nil? %>
                    <% if pl.post.nil? %>
                        link
                    <% else %>
                        post
                    <% end%>
                <% else %>
                    event
                <% end%>
            </td>
            <td>
                <%= pl_label %>
            </td>
            <td>
                <%= pl_link %>
            </td>
            <td>
                <%= pl.shown_after ? pl.shown_after : raw('&mdash;') %>
            </td>
            <td>
                <%= pl.shown_before ? pl.shown_before : raw('&mdash;') %>
            </td>
            <td>
                <%= pl.active ? raw('<strong>yes</strong>') : 'no' %>
            </td>
            <% if current_user.is_global_moderator %>
                <td><%= pl.community.nil? ? 'global' : pl.community.name %></td>
            <% end %>
            <td>
                <a href="<%= edit_pinned_link_path(pl.id) %>" class="button is-outlined">edit</a>
            </td>
        </tr>
    <% end %>
</table>