[% PROCESS _header.tt %]
[% PROCESS _sounds.tt %]
[% PROCESS _blocks.tt %]

[% WRAPPER _status_totals_header.tt %]
  <div class="card overflow-hidden">
    <div class="actionbox less-padding">
      [% IF hostgroup == 'all' %]
        <div><a href='status.cgi?hostgroup=all&amp;style=detail'>View Service Status Detail For All Host Groups</a></div>
        <div><a href='status.cgi?hostgroup=all&amp;style=hostdetail'>View Host Status Detail For All Host Groups</a></div>
        <div><a href='status.cgi?hostgroup=all&amp;style=summary'>View Status Summary For All Host Groups</a></div>
        <div><a href='status.cgi?hostgroup=all&amp;style=grid'>View Status Grid For All Host Groups</a></div>
      [% ELSIF hostgroup != '' %]
        <div><a href="status.cgi?hostgroup=all&amp;style=overview">View Status Overview For All Host Groups</a></div>
        <div><a href="status.cgi?hostgroup=[% hostgroup | uri %]&amp;style=detail">View Service Status Detail For This Host Group</a></div>
        <div><a href="status.cgi?hostgroup=[% hostgroup | uri %]&amp;style=hostdetail">View Host Status Detail For This Host Group</a></div>
        <div><a href="status.cgi?hostgroup=[% hostgroup | uri %]&amp;style=summary">View Status Summary For This Host Group</a></div>
        <div><a href="status.cgi?hostgroup=[% hostgroup | uri %]&amp;style=grid">View Status Grid For This Host Group</a></div>
      [% ELSIF servicegroup == 'all' %]
        <div><a href="status.cgi?servicegroup=all&amp;style=detail">View Service Status Detail For All Service Groups</a></div>
        <div><a href="status.cgi?servicegroup=all&amp;style=summary">View Status Summary For All Service Groups</a></div>
        <div><a href="status.cgi?servicegroup=all&amp;style=grid">View Service Status Grid For All Service Groups</a></div>
      [% ELSIF servicegroup != '' %]
        <div><a href="status.cgi?servicegroup=[% servicegroup | uri %]&amp;style=detail">View Service Status Detail For This Service Group</a></div>
        <div><a href="status.cgi?servicegroup=[% servicegroup | uri %]&amp;style=summary">View Status Summary For This Service Group</a></div>
        <div><a href="status.cgi?servicegroup=[% servicegroup | uri %]&amp;style=grid">View Service Status Grid For This Service Group</a></div>
        <div><a href="status.cgi?servicegroup=all&amp;style=overview">View Status Overview For All Service Groups</a></div>
      [% ELSE %]
        <div><a href="status.cgi?hostgroup=all&amp;style=detail">View Service Status Detail For All Host Groups</a></div>
        <div><a href="status.cgi?hostgroup=all&amp;style=hostdetail">View Host Status Detail For All Host Groups</a></div>
        <div><a href="status.cgi?hostgroup=all&amp;style=summary">View Status Summary For All Host Groups</a></div>
        <div><a href="status.cgi?hostgroup=all&amp;style=grid">View Status Grid For All Host Groups</a></div>
      [% END %]
    </div>
  </div>
[% END %]

<h1 class="mt-2">
  [% IF hostgroup == 'all' %]Service Overview For All Host Groups
  [% ELSIF hostgroup != '' %]Service Overview For Host Group '[% hostgroup | html %]'
  [% ELSIF servicegroup == 'all' %]Service Overview For All Service Groups
  [% ELSIF servicegroup != '' %]Service Overview For Service Group '[% servicegroup | html %]'
  [% ELSE %]Service Overview
  [% END %]
</h1>

<div class="my-2 flex gap-1">
  [% PROCESS _add_bookmark.tt %]
  [% PROCESS _show_link.tt %]
  [% IF hostgroup != '' && hostgroup != 'all' %]
    <a class="button round small" href="extinfo.cgi?type=5&amp;hostgroup=[% hostgroup | uri %]" title="send hostgroup commands"><i class="uil uil-icons"></i></a>
  [% ELSIF servicegroup != '' && servicegroup != 'all' %]
    <a class="button round small" href="extinfo.cgi?type=8&amp;servicegroup=[% servicegroup | uri %]" title="send servicegroup commands"><i class="uil uil-icons"></i></a>
  [% END %]
</div>

<div class="card w-full min-w-[420px]">
  <div class="mainTableHeader">
    <div>
      <div class="flex flex-nowrap gap-x-1 items-center">
        [% PROCESS _status_column_select.tt colprefix="ovr" columns_name="overview" %]
        [% PROCESS _status_filter.tt %]
      </div>
    </div>
    <div>
      [% PROCESS _pager.tt %]
    </div>
    <div>
      [% PROCESS _pager_per_page.tt %]
    </div>
  </div>

  <div class="mainTable [% IF main_table_full %]fullsize[% END %]">
    <div class="flex">
    [% FOR group_name IN groups_data.keys.sort %]
      [% g     = groups_data.$group_name.group %]
      [% hosts = groups_data.$group_name.hosts %]
      <div class="basis-1/3[% IF !loop.first %] border-l[% END %]">
        [% IF substyle == 'host' %]
        <h3 class="flexrow flex-nowrap">
          <a class="link" href="status.cgi?hostgroup=[% g.name | uri %]&amp;style=detail">[% g.alias | html %] ([% g.name | html %])</a>
          <a class="button round small text-sm display-filter" href="extinfo.cgi?type=5&amp;hostgroup=[% g.name | uri %]" title="send hostgroup commands"><i class="uil uil-icons"></i></a>
        </h3>
        [% ELSIF substyle == 'service' %]
        <h3 class="flexrow flex-nowrap">
          <a href="status.cgi?servicegroup=[% g.name | uri %]&amp;style=detail">[% g.alias | html %] ([% g.name | html %])</a>
          <a class="button round small text-sm display-filter" href="extinfo.cgi?type=8&amp;servicegroup=[% g.name | uri %]" title="send servicegroup commands"><i class="uil uil-icons"></i></a>
        </h3>
        [% END %]
        <div class='border-t border-b'>
          <table class='status statusgroups [% paneprefix %]_table statusTable mainTable striped'>
            <thead>
              <tr onmouseover="initStatusTableColumnSorting('[% paneprefix %]', 'mainTable');">
                [% FOREACH col = table_columns.$paneprefix %]
                  [% center = "" %]
                  [% IF col.field == "state"
                     || col.field == "actions"
                  %]
                    [% center = " text-center" %]
                  [% END %]
                  <th class="status col_[% col.field | html %][% center %]"[% IF ! col.checked %] style="display: none;"[% END %]>
                    <a class="status col_[% col.field | html %]">[% col.title | html %]</a>
                  </th>
                [% END %]
              </tr>
            </thead>
            <tbody>
              [% FOR hostname IN hosts.keys.sort %]
                [% SET h   = hosts.$hostname %]
                [% SET hst = hosts_data.$hostname %]
                [% loop_index = loop.index %]
                <tr>
                [% FOREACH col = table_columns.$paneprefix %]
                  [% NEXT UNLESS col.checked %]
                  [% IF col.field == "name" %]
                    <td class='name'>
                      <div class="flex min-w-max">
                        <div class="flex-1">
                          <a href="status.cgi?host=[% hostname | uri %]&amp;style=detail" title="[% hst.address | html %]">[% _host(hst) | html %]</a>
                        </div>
                        [% SET host_comment_count = hst.comments.size %]
                        [% PROCESS _status_host_attributes hostprefix="" host=hst host_comment_count=host_comment_count with_status=0 %]
                      </div>
                    </td>
                  [% ELSIF col.field == "state" %]
                    [% IF hst.has_been_checked == 0 %]
                    <td class='PENDING text-center'>PENDING</td>
                    [% ELSIF hst.state == 0 %]
                    <td class='UP text-center'>UP</td>
                    [% ELSIF hst.state == 1 %]
                    <td class='DOWN text-center'>DOWN</td>
                    [% ELSIF hst.state == 2 %]
                    <td class='UNREACHABLE text-center'>UNREACHABLE</td>
                    [% END %]
                  [% ELSIF col.field == "services" %]
                    <td class="p-0">
                      [% SET total_hosts = h.ok + h.warning + h.unknown + h.critical + h.pending %]
                      [% IF total_hosts == 0 %]
                      <div class="px-1.5">No matching services</div>
                      [% ELSE %]
                        <div class="flex h-full">
                          [% grouplink = substyle _ 'group' %]
                          [% IF h.ok       %][% SET ok_pct = h.ok / total_hosts * 100 %]<a style="width: [% ok_pct %]%" class="OK pt-0.5 min-w-[15px] px-1" href='[%       uri_with(c, $grouplink => g.name, 'host' => hostname, 'style' => 'detail', 'servicestatustypes' => '2',  'hoststatustypes' => '15', 'serviceprops' => '0', 'hostprops' => '0' ) %]'>[% h.ok %]</a>[% END %]
                          [% IF h.warning  %][% SET w_pct = h.warning / total_hosts * 100 %]<a style="width: [% w_pct %]%" class="WARNING text-cnter pt-0.5 min-w-[15px] px-1" href='[%  uri_with(c, $grouplink => g.name, 'host' => hostname, 'style' => 'detail', 'servicestatustypes' => '4',  'hoststatustypes' => '15', 'serviceprops' => '0', 'hostprops' => '0' ) %]'>[% h.warning %]</a>[% END %]
                          [% IF h.unknown  %][% SET u_pct = h.unknown / total_hosts * 100 %]<a style="width: [% u_pct %]%" class="UNKNOWN text-cnter pt-0.5 min-w-[15px] px-1" href='[%  uri_with(c, $grouplink => g.name, 'host' => hostname, 'style' => 'detail', 'servicestatustypes' => '8',  'hoststatustypes' => '15', 'serviceprops' => '0', 'hostprops' => '0' ) %]'>[% h.unknown %]</a>[% END %]
                          [% IF h.critical %][% SET c_pct = h.critical / total_hosts * 100 %]<a style="width: [% c_pct %]%" class="CRITICAL textcenter pt-0.5 min-w-[15px] px-1" href='[% uri_with(c, $grouplink => g.name, 'host' => hostname, 'style' => 'detail', 'servicestatustypes' => '16', 'hoststatustypes' => '15', 'serviceprops' => '0', 'hostprops' => '0' ) %]'>[% h.critical %]</a>[% END %]
                          [% IF h.pending  %][% SET p_pct = h.pending / total_hosts * 100 %]<a style="width: [% p_pct %]%" class="PENDING text-cnter pt-0.5 min-w-[15px] px-1" href='[%  uri_with(c, $grouplink => g.name, 'host' => hostname, 'style' => 'detail', 'servicestatustypes' => '1',  'hoststatustypes' => '15', 'serviceprops' => '0', 'hostprops' => '0' ) %]'>[% h.pending %]</a>[% END %]
                        </div>
                      [% END %]
                    </td>
                  [% ELSIF col.field == "actions" %]
                    <td class='actions'>
                      <div class="flex gap-x-1 justify-center">
                        <a href="extinfo.cgi?type=1&amp;host=[% hst.name | uri %]"><i class="fa-solid fa-magnifying-glass-arrow-right" title='View Extended Information For This Host'></i></a>
                        <a href="status.cgi?host=[% hst.name | uri %]"><i class="fa-solid fa-bars" title='View Service Details For This Host'></i></a>
                      </div>
                    </td>
                  [% ELSIF col.field == "address" %]
                    <td class='address text-left' nowrap>[% hst.address | html %]</td>
                  [% ELSIF col.field == "alias" %]
                    <td class='alias text-left' nowrap>[% hst.alias | html %]</td>
                  [% ELSIF col.field == "peer_name" %]
                    <td class='peer_name text-left' nowrap>[% peer_name(h) | html %]</td>
                  [% ELSIF col.field.match('^cust_') %]
                    [% val = "";
                      field = col.field.replace('^cust_', '');
                      cust_vars = get_custom_vars(c, h, '', 1);
                      IF cust_vars.exists(field); val = cust_vars.$field;
                      ELSIF cust_vars.exists('HOST' _ field); field = 'HOST' _ field; val = cust_vars.$field;
                      END;
                    %]
                    <td class="[% col.field | html %]">[% val %]</td>
                  [% ELSE %]
                    <td></td>
                  [% END %]
                [% END %]
                </tr>
              [% END %]
            </tbody>
          </table>
        </div>
      </div>
      [%# every x group is in a new table row #%]
      [% columns_prev = columns - 1 %]
      [% IF loop.index % columns == columns_prev and ! loop.last %]
        </div>
        <div class="flex border-t">
      [% END %]
    [% END %]
    </div>
  </div>

  <div class="mainTableFooter">
    [% PROCESS _pager_total_items.tt %]
  </div>

</div>

<script>
<!--
  if(!window.default_columns) { default_columns = {}; }
  default_columns["[% paneprefix %]"] = "[% default_overview_columns %]";
-->
</script>

[% PROCESS _footer.tt %]
