[% USE date %]
[% PROCESS _header.tt %]

[% PROCESS _infobox.tt %]

<h1 class="mt-5">Availability Report</h1>

<div class="card mx-auto min-w-[420px] max-w-[800px] w-full mt-5 overflow-hidden">
  <div class="head p-0">
    <span class="tabs w-44 px-2"><a class="flex" href="avail.cgi">1. Report Type</a></span>
    <i class="fa-solid fa-angle-right text-sm"></i>
    <span class="tabs w-44 px-2">
      [% IF host %]
        <a class="flex" href="avail.cgi?report_type=hosts">2. Select Host</a>
      [% ELSIF hostgroup %]
        <a class="flex" href="avail.cgi?report_type=hostgroups">2. Select Hostgroup</a>
      [% ELSIF service %]
        <a class="flex" href="avail.cgi?report_type=services">2. Select Service</a>
      [% ELSIF servicegroup %]
        <a class="flex" href="avail.cgi?report_type=servicegroups">2. Select Servicegroup</a>
      [% END %]
    </span>
    <i class="fa-solid fa-angle-right text-sm"></i>
    <span class="tabs w-44 active px-2"><a class="flex" href="#">3. Report Options</a></span>
  </div>

  <form method="get" action="avail.cgi" id="avail_form" class="overflow-x-auto">
    <input type='hidden' name='show_log_entries' value=''>
    [% IF host %]<input type='hidden' name='host' value="[% host | html %]">[% END %]
    [% IF hostgroup %]<input type='hidden' name='hostgroup' value="[% hostgroup | html %]">[% END %]
    [% IF service %]<input type='hidden' name='service' value="[% service | html %]">[% END %]
    [% IF servicegroup %]<input type='hidden' name='servicegroup' value="[% servicegroup | html %]">[% END %]
    <div class="body">
      <table class="cellspacing-x">
        <tr>
          <th class="text-right align-top">Report Period</th>
          <td>
            [% t1 = date.now - 86400 %]
            [% t2 = date.now %]
            [% PROCESS _timeperiods_select_options.tt selected_timeperiod="" custom=1 name="timeperiod" t1=t1 t2=t2 current=0 show_hint=0 width="w-56" %]
          </td>
        </tr>
        <tr>
          <th class="text-right align-top">Report time Period</th>
          <td>
            <select name='rpttimeperiod' class="w-56">
              <option value="">None</option>
              [% FOREACH t = timeperiods %]
              <option value="[% t.name | html %]">[% t.name | html %]</option>
              [% END %]
            </select>
          </td>
        </tr>
        <tr>
          <th class="text-right align-top">Assume Initial States</th>
          <td>
            <select name='assumeinitialstates'>
              <option value="yes">Yes</option>
              <option value="no">No</option>
            </select>
          </td>
        </tr>
        <tr>
          <th class="text-right align-top">Assume State Retention</th>
          <td>
            <select name='assumestateretention'>
              <option value="yes">Yes</option>
              <option value="no">No</option>
            </select>
          </td>
        </tr>
        <tr>
          <th class="text-right align-top">Assume States During Program Downtime</th>
          <td>
            <select name='assumestatesduringnotrunning'>
              <option value="yes">Yes</option>
              <option value="no">No</option>
            </select>
          </td>
        </tr>
        <tr>
          <th class="text-right align-top">Include Soft States</th>
          <td>
            <select name='includesoftstates'>
              <option value="yes">Yes</option>
              <option value="no" selected>No</option>
            </select>
          </td>
        </tr>
        [% UNLESS service %]
        <tr>
          <th class="text-right align-top">First Assumed Host State</th>
          <td>
            <select name='initialassumedhoststate' class="w-56">
              <option value=0>Unspecified</option>
              <option value=-1>Current State</option>
              <option value=3>Host Up</option>
              <option value=4>Host Down</option>
              <option value=5>Host Unreachable</option>
            </select>
          </td>
        </tr>
        [% END %]
        <tr>
          <th class="text-right align-top">First Assumed Service State</th>
          <td>
            <select name='initialassumedservicestate' class="w-56">
              <option value="0">Unspecified</option>
              <option value="-1">Current State</option>
              <option value="6">Service Ok</option>
              <option value="8">Service Warning</option>
              <option value="7">Service Unknown</option>
              <option value="9">Service Critical</option>
            </select>
          </td>
        </tr>
        <tr>
          <th class="text-right align-top">Output Format</th>
          <td>
            <div class="radiogroup w-56">
              <input type="radio" name="view_mode" value="html" id="view_mode_0" checked><label for="view_mode_0">HTML</label>
              <input type="radio" name="view_mode" value="xls"  id="view_mode_1" ><label for="view_mode_1">XLS</label>
              <input type="radio" name="view_mode" value="csv"  id="view_mode_2" ><label for="view_mode_2">CSV</label>
              <input type="radio" name="view_mode" value="json" id="view_mode_3" ><label for="view_mode_3">JSON</label>
            </div>
          </td>
        </tr>
      </table>
    </div>
    <div class="footer justify-center border-t-0">
      <input class="green" type='submit' value='Create Availability Report'></td>
    </div>
  </form>

  <div class="footer justify-center h-fit flexcol gap-2">
    <h4 class="self-start mt-1">Other options:</h4>
    <div class="w-full">
      <table>
        <tr>
          <th class="w-1/4">Permanent url for this report:</th>
          <td class="w-3/4 max-w-[10rem]">
            <div class="flex">
              <div class="truncate flex-1">
                <a class="link" target="_blank" href="" id="permalink"></a>
              </div>
              <div>
                <button class="iconOnly px-1 copy_button" onclick="copyCode(event, String(document.getElementById('permalink').href)); return false;"><i class="uil uil-copy" title="Copy to clipboard"></i></button>
              </div>
            </div>
          </td>
        </tr>
      </table>
    </div>

    [% IF c.config.exists('use_feature_reports') && c.config.use_feature_reports %]
    <div class="pb-2">
      <input name="email" value="Create E-Mail Report" onclick="window.location='reports2.cgi?action=edit&amp;report=new&amp;template=report_from_url.tt&amp;params.url='+encodeURIComponent(jQuery('#permalink').attr('href')); return false;" type="button">
    </div>
    [% END %]
  </div>
</div>

<script>
  function update_permalink() {
    var link = 'avail.cgi?'+jQuery("#avail_form").find("input[type='hidden'], :input:not(:hidden)").serialize();
    jQuery('#permalink').text(link).attr('href', link);
  }
  jQuery("#avail_form INPUT, #avail_form SELECT").on("change", update_permalink);
  update_permalink();

</script>

[% PROCESS _footer.tt %]
