<h1>Categories</h1>

<% @categories.each do |cat| %>
  <% next unless (current_user&.trust_level || 0) >= (cat.min_view_trust_level || -1) %>
  <div class="widget">
    <div class="widget--body">
      <h3><%= cat.name %></h3>
      <% if cat.short_wiki.present? %>
        <%= raw(sanitize(render_markdown(cat.short_wiki), scrubber: scrubber)) %>
      <% end %>
      <% post_count = cat.posts.undeleted.count %>
      <span class="has-color-tertiary-500" title="<%= post_count %>">
        <%= short_number_to_human post_count, precision: 1, significant: false %>
        <%= 'post'.pluralize(post_count) %>
      </span>
    </div>
    <div class="widget--footer">
      <%= link_to category_path(cat), class: 'button is-filled' do %>
        See posts &raquo;
      <% end %>
      <% if current_user&.is_admin %>
        <%= link_to 'Edit', edit_category_path(cat), class: 'button is-outlined' %>
      <% end %>
    </div>
  </div>
<% end %>

<% if current_user&.is_admin %>
  <%= link_to new_category_path, class: 'button is-outlined' do %>
    Add new category &raquo;
  <% end %>
<% end %>