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

[% UNLESS minimal %]
  [% WRAPPER _status_totals_header.tt %][% END %]

  <h1 class="mt-5">
    [% IF custom_title != '' %][% custom_title %]
    [% ELSIF hostgroup != '' %]Mine Map For Host Group '[% hostgroup %]'
    [% ELSIF servicegroup %]Mine Map For Service Group '[% servicegroup %]'
    [% ELSIF host == 'all' %]Mine Map For All Host
    [% ELSIF host != '' %]Mine Map For Host '[% host | uri %]'
    [% ELSE %]
    Mine Map
    [% END %]
  </h1>

  <div class="flex place-items-end gap-1 my-2">
    [% PROCESS _add_bookmark.tt %]
    [% PROCESS _show_link.tt %]
  </div>
[% END %]

<div class="card w-full min-w-[420px]">
  <div class="mainTableHeader">
    <div>[% PROCESS _status_filter.tt %]</div>
    <div>[% PROCESS _pager.tt %]</div>
    <div>[% PROCESS _pager_per_page.tt %]</div>
  </div>

  <div class="mainTable [% IF main_table_full %]fullsize[% END %]">
    <table class='mainTable sticky-2d striped w-fit' id="statusTable">
      <thead>
        <tr>
          <th class="vert"></th>
          [% FOREACH svc = services.keys.sort %]
          <th class='vert w-7' title="[% svc | html %]">
            <div class="vertical max-h-[180px] truncate"><a href='[% uri_with(c, service => svc, style => 'detail').replace("minemap.cgi", "status.cgi") %]&amp;complex='>[% _service(services.$svc) | html %]</a></div>
          </th>
          [% END %]
        </tr>
      </thead>
      [% FOREACH hstname = hostnames.keys.sort %]
        [% SET hst       = hostnames.$hstname %]
        [% SET hostclass = ''  %]
        [% SET loopclass = hostclass %]
        [% IF hst.host_state == 1 %]
          [% hostclass = 'DOWN' %]
        [% ELSIF hst.host_state == 2 %]
          [% hostclass = 'UNREACHABLE' %]
        [% END %]
        <tr>
          [% SET host_comment_count = 0 %]
          [% SET host_comment_count = hst.host_comments.size IF hst.host_comments %]
          <th class='[% hostclass %]'>
            <div class="flex">
              <div class="flex-1 truncate max-w-[180px]">
                <a href="[% uri_with(c, host => hst.host_name, style => 'detail').replace("minemap.cgi", "status.cgi") %]&complex=">[% _shost(hst) | html %]</a>
              </div>
              [% PROCESS _status_host_attributes hostprefix="host_" host=hst host_comment_count=host_comment_count loop_index=loop.index with_status=0 %]
            </div>
          </th>
          [% FOREACH svcname = services.keys.sort %]
            [% svcbg = loopclass %]
            [% IF matrix.exists(hstname) && matrix.$hstname.exists(svcname) %]
                [% s = matrix.$hstname.$svcname %]
                [% size = 10 %]
                [% icon_bg_class = loopclass %]
                [% state         = servicestatetext(s) %]
                [% serviceclass  = state %]
                [% peer_key      = s.peer_key %]
                [% IF s.state == 1 %]
                    [% icon_bg_class = 'bg' _ state %]
                    [% size = 12 %]
                [% ELSIF s.state == 2 || s.state == 3 %]
                    [% size = 14 %]
                    [% icon_bg_class = 'bg' _ state %]
                [% END %]

                <td class='[% svcbg %] clickable text-center p-0' onclick="overcard({ 'body': '<div class=&quot;service_popup_content&quot;><\/div>', 'caption': '[% escape_js(_shost(s)) | html %] - [% escape_js(_service(s)) | html %]','width': 600}); fetch_svc_info_popup(this, '[% escape_js(s.host_name) %]', '[% escape_js(s.description) %]', '[% s.peer_key | uri %]');">
                  [% IF s.acknowledged %]
                    <i class="fa-solid fa-person-digging clickable" title="This service problem has been acknowledged"></i>
                    [% svcbg = icon_bg_class %]
                  [% ELSIF s.scheduled_downtime_depth > 0 %]
                    <i class="fa-solid fa-moon clickable has_downtime" title="This service is currently in a period of scheduled downtime"></i>
                    [% svcbg = icon_bg_class %]
                  [% ELSE %]
                    <div class="[% serviceclass %] p-1 mx-auto" style="width:[% size %]px; height:[% size %]px; line-height:[% size %]px; border: 1px outset black;">&nbsp;</div>
                  [% END %]
                </td>
            [% ELSE %]
            <td class='[% svcbg %] text-center'>-</td>
            [% END %]
          [% END %]
        </tr>
      [% END %]
    </table>
  </div>

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

[% PROCESS _footer.tt %]
