% layout 'default';
% title 'New Remark';
<h2><%= title %></h2>
<form method="post">
  <div class="author field">
    <%= label_for author => 'Author' %>
    <%= text_field author => session->{'author'}, (
        maxlength => 63,
        minlength => 1
    ) %>
    <% if (my $error = validation->error('author')) { =%>
    <p class="field-with-error">Invalid author: 1 to 63 characters please.</p>
    <% } =%>
  </div>
  <div class="text field">
    <%= label_for body => 'Text' %>
    <%= text_area body => (
        maxlength => 4000,
        minlength => 2,
        required  => 'true',
        rows      => 6,
        autofocus => 'autofocus'
    ) %>
    <% if (my $error = validation->error('body')) { =%>
    <p class="field-with-error">Invalid text: Up to 4,000 characters only.</p>
    <% } =%>
  </div>
  <%= submit_button 'Post', class => 'post button' %>
</form>
<div class="threads">
  <h3>Thread</h3>
  <article class="thread">
    <nav class="id">
      <%= link_to "#$thread->{'id'}",
        single_thread => {thread_id => $thread->{'id'}} %>
    </nav>
    <h3 class="title"><%= $thread->{'title'} %></h3>
    <h4 class="date"><%= $thread->{'date'} %></h4>
    <h5 class="author"><%= $thread->{'author'} %></h5>
    <div class="body">
      <%== markdown $thread->{'body'} =%>
    </div>
  </article>
</div>
<% if (my $last_remark_id = $last_remark->{'id'}) { =%>
<div class="remarks">
  <h3>Last Remark</h3>
  <article class="remark">
    <nav class="id">
      <%= link_to "#$last_remark_id",
          single_remark => {remark_id => $last_remark_id} %>
    </nav>
    <h4 class="date"><%= $last_remark->{'date'} %></h4>
    <h5 class="author"><%= $last_remark->{'author'} %></h5>
    <div class="body">
      <%== markdown $last_remark->{'body'} =%>
    </div>
  </article>
</div>
<% } =%>