<% content_for :head do %>
  <%= render 'posts/markdown_script' %>
<% end %>

<h1>Warn or suspend <%= link_to @user.username, user_path(@user.id) %></h1>

<div class="notice is-warning">
    <p>Use the warning tool only against users who have violated the site rules. Prefer other measurements, such as friendly asking the user to stop certain behaviors in a comment.</p>
</div>

<%= form_for @warning, url: create_mod_warning_path(@user.id), method: :post do |f| %>
<div class="widget">
    <div class="widget--header h-bg-tertiary-050">
        1. Choose a template
    </div>
    <div class="widget--body">
        <div class="h-p-4">
            <p class="is-lead">Choose a template, which explains, why you are contacting the user. If none is applicable, choose to send a custom message.</p>
            <label class="form-element" for="template">Template</label>
            <select id="template" class="form-element js--warning-template-selection">
                <option value="">Send custom message</option>
                <% @templates.each do |t| %>
                    <option value="<%= t.body_as_b64 %>"><%= t.name %></option>
                <% end %>
            </select>
        </div>
    </div>
    <div class="widget--header h-bg-tertiary-050 has-border-top-width-1 has-border-top-style-solid has-border-color-tertiary-100">
        2. Review the message
    </div>
    <div class="widget--body">
        <div class="h-p-4">
            <p class="is-lead">Review the generated message and add details. Do not add salutations or informations about possible suspensions, as they are generated automatically.</p>
            
            <div class="js--warning-template-target">
                <%= render 'shared/body_field', f: f, field_name: :body, field_label: 'Body' %>
                <div class="post-preview"></div>
            </div>
        </div>
    </div>
    <div class="widget--header h-bg-tertiary-050 has-border-top-width-1 has-border-top-style-solid has-border-color-tertiary-100">
        3. Choose optional suspension
    </div>
    <div class="widget--body">
        <div class="h-p-4">
            <p class="is-lead">Decide, whether or not to suspend the user, and if, for how long. Choose an optional message shown publicly on the user profile.</p>

            <% if @prior_warning_count == 0 %>
              <p><strong>Info:</strong> This user has <a href="<%= mod_warning_log_path(@user.id) %>"><strong>no prior warnings</strong></a>. The system recommends issuing only a warning, unless the user is destructive and needs to be stopped immediately.</p>
            <% elsif @prior_warning_count >= 5 %>
              <p><strong>Info:</strong> This user has <a href="<%= mod_warning_log_path(@user.id) %>"><strong><%= @prior_warning_count %> prior warnings</strong></a>. The system recommends suspending them for 365 days (the maximum).</p>
            <% else %>
              <% lengths = { 1 => 3, 2 => 7, 3 => 30, 4 => 180 } %>
              <p><strong>Info:</strong> This user has <a href="<%= mod_warning_log_path(@user.id) %>"><strong><%= @prior_warning_count %> prior warnings</strong></a>. The system recommends suspending them for <%= lengths[@prior_warning_count] %> days.</p>
            <% end %>

            <div class="h-p-2">
                <%= f.label :is_suspension, 'Suspend this user account?', class: 'form-element' %>
                <label class="form-element"><%= f.radio_button :is_suspension, true %> Yes</label>
                <label class="form-element"><%= f.radio_button :is_suspension, false %> No</label>
            </div>

            <div class="h-p-2">
                <%= f.label :suspension_duration, 'If suspending, for how long?', class: 'form-element' %>
                <div class="form-caption">Enter the number of days. At least 1, at most 365.</div>
                <%= f.number_field :suspension_duration, in: 1..365, class: 'form-element' %>
            </div>

            <div class="h-p-2">
                <%= f.label :suspension_public_notice, 'If suspending, what public notice, if any, do you want to show?', class: 'form-element' %>
                <%= f.select :suspension_public_notice, options_for_select([['for rule violations', 'for rule violations'], ['to cool down', 'to cool down']]), { include_blank: true }, class: 'form-element' %>
            </div>
        </div>
    </div>
    <div class="widget--footer">
        <%= f.submit 'Warn (or suspend) user', class: 'button is-danger is-filled' %>
    </div>
</div>
<% end %>