[% USE HTML %]
[% PROCESS _header.tt %]
[% PROCESS _message.tt %]

[% UNLESS nomap %]
  <script>
  <!--

    function html_entity_decode(str) {
      var ta=document.createElement("textarea");
      ta.innerHTML=str.replace('<',"&lt;").replace('>',"&gt;");
      return ta.value;
    }

    var details = [% json_encode(image_map) %];
    var tmp;
    function showDetail(nr) {
      tmp = details[nr];
      document.getElementById('popup').style.visibility='visible';
      document.getElementById('detail_state').innerHTML         = details[nr].state;
      document.getElementById('detail_start').innerHTML         = details[nr].start_human;
      document.getElementById('detail_end').innerHTML           = details[nr].end_human;
      document.getElementById('detail_duration').innerHTML      = details[nr].duration;
      if(details[nr].plugin_output != details[nr].real_plugin_output) {
        [% IF escape_html_tags %]
          document.getElementById('detail_plugin_output').innerHTML = details[nr].plugin_output + "<br><i>original output was:<\/i><br>" + details[nr].real_plugin_output;
        [% ELSE %]
          document.getElementById('detail_plugin_output').innerHTML = html_entity_decode(details[nr].plugin_output) + "<br><i>original output was:<\/i><br>" + html_entity_decode(details[nr].real_plugin_output);
        [% END %]
      } else {
        [% IF escape_html_tags %]
          document.getElementById('detail_plugin_output').innerHTML = details[nr].plugin_output;
        [% ELSE %]
          document.getElementById('detail_plugin_output').innerHTML = html_entity_decode(details[nr].plugin_output);
        [% END %]
      }
    }

    function hideDetail() {
      document.getElementById('popup').style.visibility='hidden';
    }
  -->
  </script>
  <div id="popup" class="card shadow-float absolute top-2 left-2 min-w-[400px]" style="visibility: hidden;">
    <div class="head">
      <h3 id="detail_state"></h3>
    </div>
    <table class="body cellspacing-x w-fit">
      <tr>
        <th class="align-top">Start</th>
        <td id="detail_start"></td>
      </tr>
      <tr>
        <th class="align-top">End</th>
        <td id="detail_end"></td>
      </tr>
      <tr>
        <th class="align-top">Duration</th>
        <td id="detail_duration"></td>
      </tr>
      <tr>
        <th class="align-top">State Info</th>
        <td id="detail_plugin_output"></td>
      </tr>
    </table>
  </div>
[% END %]



  <div class="flexrow justify-between gap-x-1">
    <div class="flexcol gap-x-1">
      [% PROCESS _infobox.tt %]
      <div class="card min-w-[350px] overflow-hidden">
        <div class="actionbox less-padding">
          [% IF service %]
            <div><a class="flex" href="trends.cgi?host=[% host | uri %]&amp;t1=[% start %]&amp;t2=[% end %]&amp;includesoftstates=[% includesoftstates | uri %]&amp;assumestateretention=[% assumestateretention | uri %]&amp;assumeinitialstates=[% assumeinitialstates | uri %]&amp;assumestatesduringnotrunning=[% assumestatesduringnotrunning | uri %]&amp;initialassumedservicestate=[% initialassumedservicestate | uri %]&amp;backtrack=[% backtrack | uri %]&amp;rpttimeperiod=[% rpttimeperiod | uri %][% IF nomap %]&amp;nomap=[% nomap | uri %][% END %][% add_request_backend %]">View Trends For This Host</a></div>
            <div><a class="flex" href="avail.cgi?host=[% host | uri %]&amp;service=[% service | uri %]&amp;t1=[% start %]&amp;t2=[% end %]&amp;assumestateretention=[% assumestateretention | uri %]&amp;includesoftstates=[% includesoftstates | uri %]&amp;assumeinitialstates=[% assumeinitialstates | uri %]&amp;assumestatesduringnotrunning=[% assumestatesduringnotrunning | uri %]&amp;initialassumedservicestate=[% initialassumedservicestate | uri %]&amp;backtrack=[% backtrack | uri %]&amp;rpttimeperiod=[% rpttimeperiod | uri %]&amp;show_log_entries[% add_request_backend %]">View Availability Report For This Service</a></div>
            <div><a class="flex" href="history.cgi?host=[% host | uri %]&amp;service=[% service | uri %]&amp;nosystem=1[% add_request_backend %]">View Alert History For This Service</a></div>
            <div><a class="flex" href="notifications.cgi?host=[% host | uri %]&amp;service=[% service | uri %][% add_request_backend %]">View Notifications For This Service</a></div>
          [% ELSE %]
            <div><a class="flex" href="avail.cgi?host=[% host | uri %]&amp;t1=[% start %]&amp;t2=[% end %]&amp;includesoftstates=[% includesoftstates | uri %]&amp;assumestateretention=[% assumestateretention | uri %]&amp;assumeinitialstates=[% assumeinitialstates | uri %]&amp;assumestatesduringnotrunning=[% assumestatesduringnotrunning | uri %]&amp;initialassumedhoststate=[% initialassumedhoststate | uri %]&amp;backtrack=[% backtrack | uri %]&amp;show_log_entries&amp;rpttimeperiod=[% rpttimeperiod | uri %][% add_request_backend %]">View Availability Report For This Host</a></div>
            <div><a class="flex" href="status.cgi?host=[% host | uri %]">View Status Detail For This Host</a></div>
            <div><a class="flex" href="history.cgi?host=[% host | uri %]&amp;nosystem=1[% add_request_backend %]">View Alert History For This Host</a></div>
            <div><a class="flex" href="notifications.cgi?host=[% host | uri %][% add_request_backend %]">View Notifications For This Host</a></div>
          [% END %]
        </div>
      </div>
    </div>

    <div class="card min-w-[400px] min-h-[190px]">
      <div class="head justify-between">
        <h3>
          [% IF service %]
          Service '[% service | html %]' On Host '[% host | html %]'
          [% ELSE %]
          Host '[% host | html %]'
          [% END %]
        </h3>
      </div>
      <div class="body flexcol gap-2 items-center">
        <h3 class="text-center">
          <span class="block">[% format_date(start, datetime_format) %]</span>
          <span class="block">to</span>
          <span class="block">[% format_date(end, datetime_format) %]</span>
        </h3>
        <div>Duration: [% SET dur = end - start %][% duration(dur) %]</div>
      </div>
    </div>

    <div class="flex">
      <div class="card min-w-[400px]">
        <div class="head">
          <h3>Options</h3>
        </div>
        <div class="body flexrow flex-nowrap gap-2">
          <form method="get" action="trends.cgi">
            <input type='hidden' name='host' value="[% host | html %]">
            [% IF service %]<input type='hidden' name='service' value="[% service | html %]">[% END %]
            <input type='hidden' name='assumeinitialstates' value="[% assumeinitialstates | html %]">
            <input type='hidden' name='assumestateretention' value="[% assumestateretention | html %]">
            <input type='hidden' name='assumestatesduringnotrunning' value="[% assumestatesduringnotrunning | html %]">
            <input type='hidden' name='includesoftstates' value="[% includesoftstates | html %]">
            <input type='hidden' name='rpttimeperiod' value="[% rpttimeperiod | html %]">
            [% IF nomap %]<input type='hidden' name='nomap' value="[% nomap | html %]">[% END %]
            <table>
              <tr>
                [% IF service %]
                  <th>First assumed service state</th>
                [% ELSE %]
                  <th>First assumed host state</th>
                [% END %]
                <th>Backtracked archives</th>
              </tr>
              <tr>
                <td>
                  [% IF service %]
                    <input type='hidden' name='initialassumedhoststate' value="[% initialassumedhoststate | html %]">
                    <select name='initialassumedservicestate' class="w-[135px]">
                      <option value="0"[% IF  initialassumedservicestate ==  0 %] selected[% END %]>Unspecified</option>
                      <option value="-1"[% IF initialassumedservicestate == -1 %] selected[% END %]>Current State</option>
                      <option value="6"[% IF  initialassumedservicestate ==  6 %] selected[% END %]>Service Ok</option>
                      <option value="8"[% IF  initialassumedservicestate ==  8 %] selected[% END %]>Service Warning</option>
                      <option value="7"[% IF  initialassumedservicestate ==  7 %] selected[% END %]>Service Unknown</option>
                      <option value="9"[% IF  initialassumedservicestate ==  9 %] selected[% END %]>Service Critical</option>
                    </select>
                  [% ELSE %]
                    <input type='hidden' name='initialassumedservicestate' value="[% initialassumedservicestate | html %]">
                    <select name='initialassumedhoststate' class="w-[135px]">
                      <option value="0"[% IF  initialassumedhoststate ==  0 %] selected[% END %]>Unspecified</option>
                      <option value="-1"[% IF initialassumedhoststate == -1 %] selected[% END %]>Current State</option>
                      <option value="3"[% IF  initialassumedhoststate ==  3 %] selected[% END %]>Host Up</option>
                      <option value="4"[% IF  initialassumedhoststate ==  4 %] selected[% END %]>Host Down</option>
                      <option value="5"[% IF  initialassumedhoststate ==  5 %] selected[% END %]>Host Unreachable</option>
                    </select>
                  [% END %]
                </td>
                <td>
                  <input type='text' name='backtrack' size='2' maxlength='2' value="[% backtrack | html %]">
                </td>
              </tr>
              <tr>
                <th>Report period</th>
                <th>Zoom factor</th>
              </tr>
              <tr>
                <td>
                  [% PROCESS _timeperiods_select_options.tt selected_timeperiod=timeperiod custom=2 name="timeperiod" t1=t1 t2=t2 current=1 show_hint=0 width="w-[135px]" %]
                </td>
                <td class="align-top">
                  <select name='zoom'>
                    <option value="[% zoom | html %]" selected>[% zoom | html %]</option>
                    <option value="+2">+2</option>
                    <option value="+3">+3</option>
                    <option value="+4">+4</option>
                    <option value="-2">-2</option>
                    <option value="-3">-3</option>
                    <option value="-4">-4</option>
                  </select>
                </td>
              </tr>
              <tr>
                <td colspan="2">
                  <input type='submit' value='Update' class="w-40 mx-auto mt-2">
                </td>
              </tr>
            </table>
          </form>
        </div>
      </div>
    </div>
  </div>


[% UNLESS nomap %]
  <map name='trendsmap' id="trendsmap">

    [% SET x = 0 %]
    [% FOR a = image_map %]
      <area shape='rect' coords='[% a.x1 %],[% a.y1 %],[% a.x2 %],[% a.y2 %]' href="trends.cgi?t1=[% a.t1 %]&amp;t2=[% a.t2 %]&amp;host=[% host | uri %][% IF service %]&amp;service=[% service | uri %][% END %]&amp;assumeinitialstates=[% assumeinitialstates | uri %]&amp;initialassumedhoststate=[% initialassumedhoststate | uri %]&amp;initialassumedservicestate=[% initialassumedservicestate | uri %]&amp;assumestateretention=[% assumestateretention | uri %]&amp;assumestatesduringnotrunning=[% assumestatesduringnotrunning | uri %]&amp;includesoftstates=[% includesoftstates | uri %]&amp;backtrack=[% backtrack | uri %]&amp;zoom=[% zoom | uri %]&amp;rpttimeperiod=[% rpttimeperiod | uri %]" onmouseover="showDetail([% x %])" onmouseout='hideDetail()'>
    [% SET x = x+1 %]
    [% END %]
  </map>
[% END %]

<div class="mt-5 w-fit mx-auto min-w-[420px]">
  <img
    src="trends.cgi?createimage&amp;host=[% host | uri %][% IF service %]&amp;service=[% service | uri %][% END %]&amp;t1=[% start %]&amp;t2=[% end %]&amp;assumeinitialstates=[% assumeinitialstates | uri %]&amp;assumestatesduringnotrunning=[% assumestatesduringnotrunning | uri %]&amp;initialassumedhoststate=[% initialassumedhoststate | uri %]&amp;initialassumedservicestate=[% initialassumedservicestate | uri %]&amp;assumestateretention=[% assumestateretention | uri %]&amp;includesoftstates=[% includesoftstates | uri %]&amp;backtrack=[% backtrack | uri %]&amp;zoom=[% zoom | uri %]&amp;rpttimeperiod=[% rpttimeperiod | uri %][% IF ! c.config.no_external_job_forks %]&amp;job_id=[% job_id | uri %][% END %]"
    usemap='#trendsmap'
    width="[% image_width %]"
    height="[% image_height %]"
    alt="trends"
    id="trendsimage"
  >
</div>

[% PROCESS _footer.tt %]
