[%# EDIT #%]
[% IF block == 'edit' %]
  [%
    required_fields = [
        { 'language'                => [ 'Language',          'language',     'en',          '', 1 ] },
        { 'report_theme'            => [ 'Theme',             'report_theme'                       ] },
        { 'timeperiod'              => [ 'Timeperiod',        'rptimeperiod', 'last24hours', '', 1 ] },
        { 'reverse'                 => [ 'Reverse Logs',      'option',       0             ] },
        { 'pattern'                 => [ 'Pattern',           'pattern',      ''            ] },
        { 'exclude_pattern'         => [ 'Exclude Pattern',   'pattern',      ''            ] },
        { 'event_types'             => [ 'Event Type Filter', 'logclasses',   ''            ] },
    ];
  %]
[% END %]

[%# MAIL LAYOUT #%]
[% PROCESS 'reports/comp/mail.tt' %]

[%# PREPARE REPORT #%]
[% IF block == 'prepare' %]
  [% get_events() %]
[% END %]

[%# REPORT LAYOUT #%]
[% IF block == 'render' %]
  [% PROCESS _blocks.tt %]
  [% PROCESS _common_css_fonts.tt %]

  [%# report settings #%]
  [% file = 'reports/locale/' _ param.language _ '.tt'; PROCESS $file %]
  [%
    title        = loc('Event Report')
    subtitle     = r.name
    totals       = count_event_totals(logs)
    coverdetails = [ loc('Report Timeperiod:'), get_report_timeperiod(start, end, reportDateFormat) ]
  %]

  [% WRAPPER 'reports/comp/report.tt' %]

    [% WRAPPER 'reports/comp/page_cover.tt' %][% END %]
    [% PROCESS 'reports/comp/backend_error_page.tt' %]

    [% WRAPPER 'reports/comp/page_standard.tt' pagetitle = loc('Legend') %]
      <table class="legendtable">
        <tr>
          <th></th><th>[% loc('Host Alert') %]</th><th class="totals">[% loc('Totals') %]</th>
        </tr>
        <tr>
          <td class="img"><i class="fa-solid fa-check round small green"></i></td><td>[% loc('Up') %]</td>
          <td class="totals">[% totals.host.up %]</td>
        </tr>
        <tr>
          <td class="img"><i class="fa-solid fa-exclamation round small red"></i></td><td>[% loc('Down') %]</td>
          <td class="totals">[% totals.host.down %]</td>
        </tr>
        <tr>
          <td class="img"><i class="fa-solid fa-exclamation round small red"></i></td><td>[% loc('Unreachable') %]</td>
          <td class="totals">[% totals.host.unreachable %]</td>
        </tr>
      </table>

      <table class="legendtable">
        <tr>
          <th></th><th>[% loc('Service Alert') %]</th><th class="totals">[% loc('Totals') %]</th>
        </tr>
        <tr>
          <td class="img"><i class="fa-solid fa-check round small green"></i></td><td>[% loc('Ok') %]</td>
          <td class="totals">[% totals.service.ok %]</td>
        </tr>
        <tr>
          <td class="img"><i class="fa-solid fa-exclamation round small yellow"></i></td><td>[% loc('Warning') %]</td>
          <td class="totals">[% totals.service.warning %]</td>
        </tr>
        <tr>
          <td class="img"><i class="fa-solid fa-question round small orange"></i></td><td>[% loc('Unknown') %]</td>
          <td class="totals">[% totals.service.unknown %]</td>
        </tr>
        <tr>
          <td class="img"><i class="fa-solid fa-exclamation round small red"></i></td><td>[% loc('Critical') %]</td>
          <td class="totals">[% totals.service.critical %]</td>
        </tr>
      </table>
    [% END %]

    [% IF logs.size == 0 %]
      [% WRAPPER 'reports/comp/page_standard.tt' pagetitle = loc('Events') %]
      [% loc('no events during this timeperiod.') %]
      [% END %]
    [% ELSE %]
      [% counter = 0 %]
      [% WHILE logs.size > 0 %]
        [% logblock = logs.splice(0, 22) %][%# Items per page #%]
        [% WRAPPER 'reports/comp/page_standard.tt' pagetitle = loc('Events') %]
            [% FOREACH l = logblock %]
              [% PROCESS _logs_line %]
              <div class="logdate">
                <span class="w-4"><i class='[% pic %]' title='[% desc %]'></i></span>
                [% format_date(l.time, reportDateTimeFormat) %]
                <span class="logtype">[% IF has_type %][% l.type %][% END %]</span>
              </div>
              [% options = message;
                 IF has_type;
                   options = options.substr(l.type.length + 2);
                 END;
              %]
              <div class="logoptions fittext">[% options.substr(0, 130) %]</div>
            [% END %]
        [% END %]
        [% counter = counter + 1 %]
        [% LAST IF counter >= 100 %][%# max out at page 100 #%]
      [% END %]
    [% END %]

  [% END %][%# report wrapper #%]
[% END %][%# render block #%]
