
<table class='mainTable striped [% IF names %] hoverable[% END %]' id="recurring_downtimes_table_[% type | html %]">
  <thead>
    <tr>
      <th>Type</th>
      <th>Names</th>
      <th>Schedule</th>
      <th>Type</th>
      <th class="text-center">Duration</th>
      <th>Comment</th>
      <th>Last Edited By</th>
      <th class="text-center">Actions</th>
    </tr>
  </thead>

  <tbody>
    [% FOREACH d = downtimes %]
      <tr id="recurring_[% d.file | html %]" class="js-downtime-row">
        <td class="align-top">[% d.target | ucfirst %]</td>
        <td class="align-top max-w-[500px]">
          <div class="flexrow flex-nowrap gap-x-1 justify-between w-full">
            <div class="overflow-hidden text-ellipsis js-overflown js-for-js-overflow-button">
              [% IF d.target == 'host' %]
                [% FOREACH hst = d.host %]
                    <a class="link" href="extinfo.cgi?type=1&amp;host=[% hst | uri %]">[% hst | html %]</a>[% UNLESS loop.last %], [% END %]
                [% END %]
              [% ELSIF d.target == 'service' %]
                [% FOREACH hst = d.host %]
                    <a class="link" href="extinfo.cgi?type=1&amp;host=[% hst | uri %]">[% hst | html %]</a>[% UNLESS loop.last %], [% END %]
                [% END %]
                <span class="w-1 h-[14px] border-l borderDefault inline-block"></span>

                [% IF d.host.size == 1 %]
                    [% hst = d.host.0 %]
                    [% FOREACH svc = d.service %]
                        <a class="link" href="extinfo.cgi?type=2&amp;host=[% hst | uri %]&amp;service=[% svc | uri %]">[% svc | html %]</a>[% UNLESS loop.last %], [% END %]
                    [% END %]
                [% ELSE %]
                    [% FOREACH svc = d.service %]
                        <a class="link" href='status.cgi?style=detail&amp;dfl_s0_type=host&amp;dfl_s0_op=~&amp;dfl_s0_value=^([% d.host.join('|') %])$&amp;dfl_s0_type=service&amp;dfl_s0_op=%3D&amp;dfl_s0_value=[% svc | uri %]'>[% svc | html %]</a>
                        [% UNLESS loop.last %], [% END %]
                    [% END %]
                [% END %]
              [% ELSIF d.target == 'hostgroup' %]
                [% FOREACH grp = d.hostgroup %]
                    <a class="link" href="status.cgi?hostgroup=[% grp | uri %]&amp;style=hostdetail">[% grp | html %]</a>[% UNLESS loop.last %], [% END %]
                [% END %]
              [% ELSIF d.target == 'servicegroup' %]
                [% FOREACH grp = d.servicegroup %]
                    <a class="link" href="status.cgi?servicegroup=[% grp | uri %]&amp;style=detail">[% grp | html %]</a>[% UNLESS loop.last %], [% END %]
                [% END %]
              [% END %]
            </div>
            <div class="w-5 hidden js-overflow-button">
              <button class="iconOnly" title="expand list" onClick="toggleOverflown(this)"><i class="fa-solid fa-chevron-down"></i></button>
            </div>
          </div>
        </td>
        <td class="align-top">
          [% IF d.schedule.size == 0 %]
            never
          [% ELSE %]
            [% FOREACH cr = d.schedule %]
              <div>[% format_cronentry(c, cr) %]</div>
            [% END %]
          [% END %]
        </td>
        <td class="align-top">[% IF d.fixed %]Fixed[% ELSE %]Flexible ([% duration(d.flex_range * 60) %])[% END %]</td>
        <td class="text-center align-top">[% duration(d.duration * 60) %]</td>
        <td class="align-top">[% IF escape_html_tags %][% escape_html(d.comment) %][% ELSE %][% d.comment %][% END %]</td>
        <td class="align-top">[% d.edited_by | html %] ([% date_format(c, d.last_changed) %])</td class="align-top">
        <td class="align-top">
          <div class="flex gap-x-1 justify-center">
            <a href="extinfo.cgi?type=6&amp;nr=[% d.file | uri %]&amp;recurring=edit">
              <i class="fa-solid fa-pencil small" title='Edit recurring downtime'></i>
            </a>
            <form action="extinfo.cgi" method="POST">
              <input type="hidden" name="nr" value="[% d.file | html %]">
              <input type="hidden" name="type" value="6">
              <input type="hidden" name="CSRFtoken" value="[% get_user_token(c) %]">
              <a href="#" onclick="if(confirm('Do you really want to delete this downtime?')) { return send_form_in_background_and_reload(this, {recurring: 'remove'}) }; return false;"><i class="fa-solid fa-trash text-sm" title='Delete recurring downtime'></i></a>
            </form>
          </div>
        </td>
      </tr>
      [% IF d.exists('error') %]
        <tr>
          <td></td>
          <td colspan=6 class="textALERT text-left">
            <div class="flexrow flex-nowrap gap-x-1">
              [% IF d.exists('fixable') %]
                <div>
                  <form action="extinfo.cgi" method="POST">
                    <input type="hidden" name="nr" value="[% d.file | html %]">
                    <input type="hidden" name="type" value="6">
                    <input type="hidden" name="CSRFtoken" value="[% get_user_token(c) %]">
                    <button title="removes none-existing entries, removes downtime if empty afterwards" onclick="var btn = this; return send_form_in_background(btn, {recurring: 'fix'}, function() { window.setTimeout(function() { fade(jQuery(btn).parents('TR')); }, 1000); }); return false;">
                      <i class="uil uil-band-aid"></i> fix it
                    </button>
                  </form>
                </div>
              [% END %]
              <div>
                [% escape_html(d.error) | nl2br %]
              </div>
            </div>
          </td>
          <td></td>
        </tr>
      [% END %]
    [% END %]
    [% IF downtimes.size == 0 %]
      <tr>
        <td class='text-center textALERT' colspan="9">There are no recurring [% IF type != 'all'; type; END %] downtimes</td>
      </tr>
    [% END %]
  </tbody>
</table>
