[% subtitle="Business Process Overview" %]
[% IF filter; subtitle="Business Processes matching: '" _ filter _ "'"; END %]
[% WRAPPER _bp_frame.tt subtitle=subtitle %]
[% USE date %]

<div class="card w-full min-w-[420px] mt-5">
  <div class="head justify-between">
    <div class="flexrow gap-1 flex-nowrap w-52">
      [% PROCESS _json_export.tt %]
      [% PROCESS _excel_export.tt columns=excel_columns with_custom_vars=0 prefix="" %]
    </div>
    [% IF has_remote_bps %]
      <div class="flexrow flex-nowrap gap-0">
        <span class="tabs min-w-[140px] w-52 px-2 text-center font-medium text-base[% IF type == 'local'  %] active[% END %]"><a class="block" href="[% uri_with(c, 'type' => 'local')  %]">Local</a></span>
        <span class="tabs min-w-[140px] w-52 px-2 text-center font-medium text-base[% IF type == 'remote' %] active[% END %]"><a class="block" href="[% uri_with(c, 'type' => 'remote') %]">Remote</a></span>
        <span class="tabs min-w-[140px] w-52 px-2 text-center font-medium text-base[% IF type == 'all'    %] active[% END %]"><a class="block" href="[% uri_with(c, 'type' => 'all')    %]">All</a></span>
      </div>
    [% END %]
    <div class="w-52">
      <a href="bp.cgi?action=new" class="button [% IF allowed_for_edit %]green[% ELSE %]not-clickable disabled[% END %]"[% IF !allowed_for_edit %] onclick="return false;" title="c"[% END %]>create new business process</a>
    </div>
  </div>
  <div class="mainTableHeader">
    <div>
      <form action="bp.cgi" method="GET">
        <input type="hidden" name="type" value="[% type | html %]">
        <input type="text" id="filter" placeholder="filter" class="deletable autosubmit autofocus" name="filter" value="[% filter | html%]" onkeydown="this.click()" onclick="ajax_search.init(this, 'bp', { url: 'bp.cgi?format=search&amp;type=[% type | html %]', autosubmit:true })">
      </form>
    </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 rowhover striped' id="statusTable">
      <thead>
        <tr>
          <th class="w-0"></th>
          <th class="w-[400px] border-l-0">Name</th>
          <th class="w-[100px] text-center">Actions</th>
          [% IF type != "local" %]
          <th class="w-[100px] text-center">Site</th>
          [% END %]
          <th class="w-[100px] text-center">Status</th>
          <th class="w-[130px] text-center">Last Check</th>
          <th class="w-[130px] text-center">Duration</th>
          <th>Status Information</th>
        </tr>
      </thead>
      <tbody>
        [% FOREACH bp IN data %]
          [% statusClass = 'UNKNOWN' %]
          [% statusText  = 'UNKNOWN' %]
          [% IF bp.draft %][% statusClass = 'PENDING' %][% statusText  = 'DRAFT' %]
          [% ELSIF bp.status == 0 %][% statusClass = 'OK'       %][% statusText  = 'OK'      %]
          [% ELSIF bp.status == 1 %][% statusClass = 'WARNING'  %][% statusText  = 'WARNING' %]
          [% ELSIF bp.status == 2 %][% statusClass = 'CRITICAL' %][% statusText = 'CRITICAL' %]
          [% ELSIF bp.status == 3 %][% statusClass = 'UNKNOWN'  %][% statusText  = 'UNKNOWN' %]
          [% ELSIF bp.status == 4 %][% statusClass = 'PENDING'  %][% statusText  = 'PENDING' %]
          [% END %]
          <tr>
            <td>
              [% IF allowed_for_edit %]
                <a href="bp.cgi?action=details&amp;bp=[% bp.fullid %]&amp;edit=1"><i class="fa-solid fa-pencil text-sm" title='Change Business Process'></i></a>
              [% ELSE %]
                <a href="#" class="not-clickable disabled" onclick="return false;"><i class="fa-solid fa-pencil text-sm" title='business processes are configured to be readonly'></i></a>
              [% END %]
            </td>
            <td class="mightOverflow border-l-0">
              [% IF bp.draft %]
                <a href="bp.cgi?action=details&amp;bp=[% bp.fullid %]&amp;edit=1"><b>[% bp.name | html %]</b> <span class="textHINT pl-2">(DRAFT)</span></a>
              [% ELSE %]
                <a href="bp.cgi?action=details&amp;bp=[% bp.fullid %]"><b>[% bp.name | html %]</b></a>
              [% END %]
            </td>
            <td class="text-right">
              <div class="flex gap-x-1 justify-center">
                [% IF !bp.draft %]
                  <a href="bp.cgi?action=details&amp;bp=[% bp.fullid %]&amp;testmode=1"><i class="fa-solid fa-clipboard-question" title="Business Impact Analysis"></i></a>
                  <a href="status.cgi?host=[% bp.name | uri %]"><i class="fa-solid fa-bars" title="Show Service Details"></i></a>
                  <a href="bp.cgi?action=details&amp;bp=[% bp.fullid %]"><i class="fa-solid fa-sitemap" title='Show Business Process'></i></a>
                [% END %]
              </div>
            </td>
            [% IF type != "local" %]
            <td class="text-center">[% bp.site %]</td>
            [% END %]
            <td class="[% statusClass %] text-center">[% statusText %]</td>
            <td class="text-center">[% IF bp.draft %][% ELSE %][% IF bp.last_check %][% date_format(c, bp.last_check) %][% ELSE %]never[% END %][% END %]</td>
            <td class="text-center">[% IF bp.draft %][% ELSE %][% IF bp.last_state_change %][% duration(date.now - bp.last_state_change, 6) %][% END %][% END %]</td>
            [% output = bp.status_text.split("\n") %]
            <td class="truncate max-w-sm"[% IF output.size > 1 %]
              onclick="overcard({ 'body': this.abbr, 'caption': '[% escape_js(bp.name) | html %]', 'width': 600 })" abbr="[% escape_html(nl2br(bp.status_text)) %]"
              [% END %]>
              [% IF bp.draft %]
              [% ELSE %]
                [% IF output.size > 1 %]
                <span class="has_long_plugin_output clickable">
                [% END %]
                [% IF output.size > 0 %]
                [% output.0 %]
                [% END %]
                [% IF output.size > 1 %]
                </span>
                [% END %]
              [% END %]
            </td>
          </tr>
        [% END %]
      </tbody>
    </table>


  </div>

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

[% END %]
