[% 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=overview'>View Status Overview 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>
    [% ELSIF hostgroup != '' %]
      <div><a href="status.cgi?hostgroup=all&amp;style=grid">View Status Grid 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=overview">View Status Overview 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>
    [% 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=overview'>View Status Overview 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>
    [% 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=overview">View Status Overview 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=all&amp;style=grid">View Service Status Grid 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=overview'>View Status Overview 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>
    [% END %]
  </div>
</div>
[% END %]

<h1 class="mt-2">
  [% IF hostgroup == 'all' %]Service Grid For All Host Groups
  [% ELSIF hostgroup != '' %]Service Grid For Host Group '[% hostgroup | html %]'
  [% ELSIF servicegroup == 'all' %]Service Grid For All Service Groups
  [% ELSIF servicegroup != '' %]Service Grid For Service Group '[% servicegroup | html %]'
  [% ELSE %]Service Grid
  [% 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 %]
        [% IF hostgroup != '' && hostgroup != 'all' %]
          <a class="button round small text-sm display-filter" 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 text-sm display-filter" href="extinfo.cgi?type=8&amp;servicegroup=[% servicegroup | uri %]" title="send servicegroup commands"><i class="uil uil-icons"></i></a>
        [% END %]
      </div>
    </div>
    <div>
      [% PROCESS _pager.tt %]
    </div>
    <div>
      [% PROCESS _pager_per_page.tt %]
    </div>
  </div>

  <div class="mainTable [% IF main_table_full %]fullsize[% END %]" style="max-height: calc(100vh - 210px);">
    [% FOR g IN data %]
      <div>
        <div class="p-2">
          [% IF substyle == 'host' %]
              <h3 class="flexrow flex-nowrap">
                <a href="status.cgi?hostgroup=[% g.name | uri %]&amp;style=detail">[% g.alias | html %] ([% g.name | html %])</a>
                <a class="button round small" href="extinfo.cgi?type=5&amp;hostgroup=[% g.name | uri %]"><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" href="extinfo.cgi?type=8&amp;servicegroup=[% g.name | uri %]"><i class="uil uil-icons"></i></a>
              </h3>
            [% END %]
        </div>
        <div class="border-t">
          <table class="status statusgroups [% paneprefix %]_table statusTable mainTable striped">
            <thead>
              <tr onmouseover="initStatusTableColumnSorting('[% paneprefix %]', 'mainTable');">
                [% FOREACH col = table_columns.$paneprefix %]
                  [% center = "" %]
                  [% IF 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 g.hosts.keys.sort %]
                [% SET hosts_data = g.hosts.$hostname %]
                [% FOR peer_key IN hosts_data.keys.sort %]
                  [% SET h = g.hosts.$hostname.$peer_key; LAST; %]
                [% END %]
                [% hoststate = '' %]
                [% IF h.state == 1 %]
                  [% hoststate = 'DOWN' %]
                [% ELSIF h.state == 2 %]
                  [% hoststate = 'UNREACHABLE' %]
                [% END %]
                [% loop_index = loop.index %]
                <tr class='[% IF loop.last %]border-b[% END %]'>
                [% FOREACH col = table_columns.$paneprefix %]
                  [% NEXT UNLESS col.checked %]
                  [% IF col.field == "name" %]
                    <td class='[% hoststate %] name'>
                      <div class="flex min-w-max">
                        <div class="flex-1">
                          <a href="extinfo.cgi?type=1&amp;host=[% h.name | uri %]">[% _host(h) | html %]</a>
                        </div>
                        [% SET host_comment_count = h.comments.size %]
                        [% PROCESS _status_host_attributes hostprefix="" host=h host_comment_count=host_comment_count with_status=0 %]
                      </div>
                    </td>
                  [% ELSIF col.field == "state" %]
                    <td class="">
                      <div class="flex gap-0.5 flex-row flex-wrap">
                        [% FOR peer_key IN hosts_data.keys.sort %]
                          [% SET hst = g.hosts.$hostname.$peer_key; %]
                          [% FOR servicename IN hst.services.keys.sort %]
                            [% SET s = hst.services.$servicename %]
                            [% IF s.has_been_checked == 0 %]
                              [% SET s_status = 'PENDING' %]
                            [% ELSIF s.state == 0 %]
                              [% SET s_status = 'OK' %]
                            [% ELSIF s.state == 1 %]
                              [% SET s_status = 'WARNING' %]
                            [% ELSIF s.state == 2 %]
                              [% SET s_status = 'CRITICAL' %]
                            [% ELSIF s.state == 3 %]
                              [% SET s_status = 'UNKNOWN' %]
                            [% END %]
                            <a href="extinfo.cgi?type=2&amp;host=[% hst.name | uri %]&amp;service=[% s.description | uri %]&backend=[% peer_key | uri %]" class='[% s_status %] badge'>[% _service(s) | html %]</a>
                          [% END %]
                        [% END %]
                      </div>
                    </td>
                  [% ELSIF col.field == "actions" %]
                    <td>
                      <div class="flex gap-x-1 justify-center">
                        <a href="extinfo.cgi?type=1&amp;host=[% h.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=[% h.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'>[% h.address | html %]</td>
                  [% ELSIF col.field == "alias" %]
                    <td class='alias'>[% h.alias | html %]</td>
                  [% ELSIF col.field == "peer_name" %]
                    <td class='peer_name'>[% 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>
    [% END %]
  </div>

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

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

[% PROCESS _footer.tt %]
