<div class="row mb-3">
  <div class="col-12">
    <h2>Email Tools</h2>
    <%= form_with url: verify_email_ownership_internal_user_path(@user), local: true do |f| %>
      Email last verified at: <%= @last_email_verification_date %>
      <%= f.hidden_field(:user_id, value: @user.id) %>
      <%= f.submit "Verify Email Ownership", class: "btn btn-primary float-right" %>
    <% end %>
  </div>
  <div class="col-12">
    <h3>Email <%= @user.name %></h3>
    <%= form_with url: send_email_internal_user_path(@user), local: true do |f| %>
      <%= f.hidden_field(:user_id, value: @user.id) %>
      <h4>Subject:</h4>
      <%= f.text_field :email_subject, class: "form-control my-1" %>
      <h4>Body:</h4>
      <%= f.text_area :email_body, class: "form-control my-1", rows: "10" %>
      <%= f.submit "Send Email", class: "btn btn-primary float-right" %>
    <% end %>
  </div>
</div>

<div class="row mb-3">
  <div class="col-12">
    <h3>Recent Emails</h3>
    <div class="list-group-flush">
      <% @user.email_messages.order("sent_at DESC").limit(50).each do |email| %>
        <a href="/admin/email_messages/<%= email.id %>" class="list-group-item list-group-item-action">
          <%= email.subject %>
          <em> - <%= email.sent_at&.strftime("%b %e '%y") %></em>
        </a>
      <% end %>
    </div>
  </div>
</div>
