<div class="grid--cell is-4-lg is-12">
  <%= yield(:sidebar) %>

  <% notice_text = SiteSetting['SidebarNoticeText'] %>
  <% if notice_text.present? %>
    <% cache SiteSetting.find_by(name: 'SidebarNoticeText') do %>
      <div class="widget has-margin-4 is-yellow">
        <div class="widget--body">
          <%= raw(sanitize(render_markdown(notice_text), scrubber: scrubber)) %>
        </div>
      </div>
    <% end %>
  <% end %>

  <% if Rails.env.development? || @hot_questions.to_a.size > 0 || @pinned_links.to_a.size > 0 %>
    <div class="widget has-margin-4 is-tertiary">
    <% if Rails.env.development? || @pinned_links.to_a.size > 0 %>
      <div class="widget--header">Featured</div>
      <% @pinned_links.each do |pl| %>
        <div class="widget--body">
          <% pl_link = pl.post.nil? ? pl.link : generic_share_link(pl.post) %>
          <% pl_label = pl.post.nil? ? pl.label : (pl.post.parent.nil? ? pl.post.title : pl.post.parent.title) %>
          <%= link_to pl_link, class: 'h-fw-bold' do %>
            <%= pl_label %>
          <% end %>
        <% unless pl.shown_before.nil? %>
          <div>
            &mdash;
            <% if !pl.shown_after.nil? %>
              <% if pl.shown_after < DateTime.now %>
                ends in  <%= time_ago_in_words(pl.shown_before) %>
              <% else %>
                starts in <%= time_ago_in_words(pl.shown_after) %>
              <% end %>
            <% else %>
              in <%= time_ago_in_words(pl.shown_before) %>
            <% end %>
          </div>
          <% end %>
        </div>
      <% end %>
    <% end %>
    <% if Rails.env.development? || @hot_questions.to_a.size > 0 %>
      <div class="widget--header">Hot Posts</div>
      <% @hot_questions.each do |hq| %>
        <div class="widget--body">
          <% unless hq.category.nil? %>
            <%= hq.category.name %>
            &mdash;
          <% end %>
          <%= link_to question_path(hq) do %>
            <%= hq.title %>
          <% end %>
        </div>
      <% end %>
    <% end %>
    </div>
  <% end %>

  <% if moderator? || admin? %>
    <div class="widget has-margin-4">
      <h4 class="widget--header has-margin-0">Moderator Tools</h4>
      <div class="widget--body">
        <ul>
          <% if moderator? %>
            <li><%= link_to 'Moderator Tools', moderator_path %></li>
          <% end %>
          <% if admin? %>
            <li><%= link_to 'Admin Tools', admin_path %></li>
          <% end %>
        </ul>
      </div>
    </div>
  <% end %>

  <% if user_signed_in? %>
    <div class="widget has-margin-4">
      <div class="widget--header">
        <%= link_to 'edit', subscriptions_path, class: 'widget--header-link' %>
        Subscribe to Questions
      </div>
      <div class="widget--body">
        <p>You can subscribe to
          <%= link_to 'all new questions', new_subscription_path(type: 'all', return_to: request.path) %>
          (from all categories) or to
          <%= link_to 'interesting questions', new_subscription_path(type: 'interesting', return_to: request.path) %>.</p>
      </div>
    </div>
  <% end %>

  <div class="widget has-margin-4">
    <div class="widget--header">
      <img src="/assets/codidact.png" alt="Codidact logo" class="codidact-logo" />
    </div>
    <div class="widget--body">
<% chat = SiteSetting['ChatLink'] %>
      <p>
        This site is part of the <a href="https://codidact.com">Codidact network</a>.
        We have other sites too &mdash; take a look!
      </p>
      <% if chat.present? %>
      <p>
        You can also <%= link_to 'join us in chat', chat %>!
      </p>
      <% end %>
      <p>
        Want to advertise this site? <%= link_to 'Use our templates!', ads_path %>
      </p>
    </div>
  </div>