<!--
  This file is compiled into schedule.js via "yarn run build".
  Changing it has no impact. Compile before checking output.
-->

<!-- var base_template -->
<div class="schedule-formhandler"></div>
<div class="schedule-logs"></div>
<!-- end -->

<!-- var name_template -->
<td><%- _.last((obj.value || '').split(/:/)) %></td>
<!-- end -->

<!-- var actions_schedule_template -->
<td>
  <button class="run btn btn-primary btn-xs" title="Run now" data-name="<%- row.name %>">
    <i class="fa fa-play"></i>
  </button>
</td>
<!-- end -->

<!-- var actions_alert_template -->
<td>
  <button class="run btn btn-primary btn-xs" title="Send alert now" data-name="<%- row.name %>">
    <i class="fa fa-envelope"></i>
  </button>
  <button class="run btn btn-success btn-xs ml-1" title="Preview results" data-name="<%- row.name %>" data-mock="true">
    <i class="fa fa-eye"></i>
  </button>
</td>
<!-- end -->

<!-- var notification_template -->
<div class="alert alert-<%- obj.error ? 'danger' : 'success' %> alert-dismissible fade show" role="alert">
  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span>
  </button>
  <div>
    <strong><%- name %></strong>
    <% if (obj.error) { %>
      <%= obj.traceback || '' %>
    <% } else { %>
      <div><%- obj.mock ? 'Previewed successfully.' : 'Ran successfully.' %></div>
    <% } %>
  </div>
  <% _.each(obj.results, function (row) { %>
    <table class="table table-sm bg-white mt-3">
      <tbody>
        <% _.each(['to', 'cc', 'bcc', 'from', 'reply_to', 'on_behalf_of', 'subject'], function (key) { %>
          <% if (key in row) { %>
            <tr>
              <th><%- key %></th>
              <td><%- row[key] %></td>
            </tr>
          <% } %>
        <% }) %>
        <% if (row.body) { %><tr><th>body</th><td><%- row.body %></td></tr><% } %>
        <% if (row.html) { %><tr><th>html</th><td><%= row.html %></td></tr><% } %>
        <% if (row.attachments) { %>
          <tr>
            <th>attachments</th>
            <td><ul>
              <% _.each(row.attachments, function (path) { %>
                <li><%- path %></li>
              <% }) %>
            </ul></td>
          </tr>
        <% } %>
      </tbody>
    </table>
  <% }) %>
</div>
<!-- end -->

<!-- var function_template -->
<td>
  <pre class="mb-0 pre-wrap"><%- value %></pre>
  <% var args = JSON.parse(row.args), kwargs = JSON.parse(row.kwargs) %>
  <% if (_.size(args) + _.size(kwargs)) { %>
  <div><a data-toggle="collapse" href="#kwargs<%- index %>" class="sm1">Expand arguments...</a></div>
  <div class="collapse" id="kwargs<%- index %>">
    <%= _.size(args) ? '<pre>' + JSON.stringify(args, null, 2) + '</pre>' : '' %>
    <%= _.size(kwargs) ? '<pre>' + JSON.stringify(kwargs, null, 2) + '</pre>' : '' %>
  </div>
  <% } %>
</td>
<!-- end -->

<!-- var schedule_template -->
<td>
  <div><%- row.schedule %></div>
  <div class="small"><%- row.next ? moment.utc(row.next).fromNow() : '' %></div>
</td>
<!-- end -->
