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

[% SET peer_key = service.peer_key %]

<div class="flexrow justify-between">
  <div class="order-3 min-[1700px]:order-1">
    <div class="hidden lg:block">
      [% PROCESS _infobox.tt %]
    </div>
    [% IF matching_backends.size > 1 %]
      <div class="card mt-5 min-w-[350px] p-3">
        <form action="extinfo.cgi" method="GET">
          <input type="hidden" name="type" value="2">
          <input type="hidden" name="host" value="[% service.host_name | html %]">
          <input type="hidden" name="service" value="[% service.description | html %]">
          <div class="flexrow gap-1 items-center">
            <span>This service is ambiguous:</span>
            <select name="backend">
              [% FOREACH b IN matching_backends %]
                <option value="[% b | html %]"[% IF b == backend %] selected[% END %]>[% peer_name(b) %]</option>
              [% END %]
            </select>
            <button>go</button>
          </div>
        </form>
      </div>
    [% END %]
    <div class="min-[1700px]:hidden block mt-5">
      [% PROCESS _service_command_box.tt %]
    </div>
    <div class="card mt-5 min-w-[350px] overflow-hidden">
      <div class="actionbox less-padding">
        <div><a href="extinfo.cgi?type=1&amp;host=[% service.host_name | uri %]">View Information For This Host</a></div>
        <div><a href="status.cgi?host=[% service.host_name | uri %]">View Status Detail For This Host</a></div>
        <div class="flex flex-nowrap gap-x-1"><a href="history.cgi?host=[% service.host_name | uri %]&amp;service=[% service.description | uri %]&amp;nosystem=1&amp;backend=[% peer_key %]">View Alert History For This Service</a> (<a href="showlog.cgi?host=[% service.host_name | uri %]&amp;service=[% service.description | uri %][% add_request_backend %]">Logs</a> / <a href="avail.cgi?outages=1&host=[% service.host_name | uri %]&amp;service=[% service.description | uri %][% add_request_backend %]">Outages</a>)</div>
        [% IF show_impacts_link %]<div><a href="shinken_status.cgi?style=bothtypes&amp;s0_type=impact&amp;s0_op=%3D&amp;s0_value=[% service.host_name | uri %]/[% service.description | uri %]&amp;title=Impacts of [% service.host_name | uri %]/[% service.description | uri %]">View Impacts For This Problem</a></div>[% END %]
        [% IF show_rootproblems_link %]<div><a href="shinken_status.cgi?style=bothtypes&amp;s0_type=rootproblem&amp;s0_op=%3D&amp;s0_value=[% service.host_name | uri %]/[% service.description | uri %]&amp;title=Root problem of [% service.host_name | uri %]/[% service.description | uri %]">View Root Problem For This Impact</a></div>[% END %]
        [% IF use_feature_trends %]<div><a href="trends.cgi?host=[% service.host_name | uri %]&amp;service=[% service.description | uri %][% add_request_backend %]">View Trends For This Service</a></div>[% END %]
        <div><a href="avail.cgi?host=[% service.host_name | uri %]&amp;service=[% service.description | uri %]&amp;show_log_entries[% add_request_backend %]">View Availability Report For This Service</a></div>
        <div><a href="notifications.cgi?host=[% service.host_name | uri %]&amp;service=[% service.description | uri %][% add_request_backend %]">View Notifications For This Service</a></div>
        [% IF c.check_user_roles('authorized_for_configuration_information') %]
          <div class="flex flex-nowrap gap-x-1">
            <a href="config.cgi?type=services&amp;jump2=[% service.host_name | uri %]&amp;jump3=[% service.description | uri %]">
              View Configuration For This Service
            </a>
            [% IF use_feature_configtool && c.check_user_roles('admin') && backends_with_obj_config.$peer_key %]
              <a href="conf.cgi?edit&amp;host=[% service.host_name | uri %]&amp;service=[% service.description | uri %][% add_request_backend %]"> (Edit This Service)</a>
            [% END %]
          </div>
        [% END %]
        <div class="flex flex-nowrap gap-x-1"><a href="status.cgi?s0_op=%3D&amp;s0_type=service&amp;s0_value=[% service.description | uri %]">View All '[% IF service.description.length > 7; service.description.substr(0, 7) | html %]...[% ELSE; service.description | html; END %]' Services</a> (<a href="status.cgi?s0_op=%3D&amp;s0_type=service&amp;s0_value=[% service.description | uri %]&amp;style=perfmap">As Performance Map</a>)</div>
      </div>
    </div>

    [% PROCESS _customvar_box.tt %]
  </div>

  <div class="flexcol flex-grow order-1 min-[1700px]:order-2">
    <div class="card w-full">
      <div class="head justify-between">
        <h3>Service <span class="js-copy-to-clipboard">[% _service(service) | html %]</span> on <span class="js-copy-to-clipboard">[% _shost(service) | html %]</span></h3>
        <div class="flex gap-x-3 items-center">
          [% cust_vars = get_custom_vars(c, service); IF cust_vars.exists('THRUK_ACTION_MENU') %]
            <div>
              [% menu = get_action_menu(c, cust_vars.THRUK_ACTION_MENU) %]
              [% IF menu.defined('err') && menu.err %]
                <i class="fa-solid fa-exclamation round small yellow" title="[% menu.err | html %]"></i>
              [% ELSE %]
                <script>
                [% IF menu.defined('icons') %]action_images = [% json_encode(menu.icons) %];[% END %]
                [% IF menu.type == "js" %]
                  [% IF !action_menus_inserted.defined(menu.data) %]
                  [% menu.data %]
                  [% action_menus_inserted.item(menu.data) = 1 %]
                  [% END %]
                  print_action_menu([% menu.function %], [% json_encode({"backend" => peer_key, "host" => service.host_name, "service" => service.description }) %]);
                [% ELSE %]
                  print_action_menu([% menu.data %], [% json_encode({"backend" => peer_key, "host" => service.host_name, "service" => service.description }) %]);
                [% END %]
                </script>
              [% END %]
            </div>
          [% END %]
          [% IF enable_shinken_features %]
            [% prio = service.criticity %]
            <div class="flex items-center gap-1 mr-3">
              <span class="font-bold">Priority [% prio %]/5</span>
              <img class="inline-block" src="[% url_prefix %]plugins/[% shinken_features_path %]/images/criticity_[% prio %].png" alt="Priority [% prio %]/5" title="[% priorities.$prio | html %]">
            </div>
          [% END %]
          [% IF service.action_url_expanded %]
            [% action_url = proxifiy_url(c, service, get_action_url(c, 2, 1, service.action_url_expanded, service)) %]
            <div>
              <a href='[% l = set_target_link(action_url, c.config.action_url_target); l.0 %]' target='[% l.1 %]'>
                <i class="fa-solid fa-chart-line clickable text-xl" title='Show Performance Chart'></i>
              </a>
            </div>
          [% END %]
          [% IF service.notes_url_expanded %]
            <div>
              <a href='[% l = set_target_link(service.notes_url_expanded, c.config.notes_url_target); l.0 %]' target='[% l.1 %]'>
                <i class="fa-solid fa-clipboard clickable" title='View Extra Service Notes'></i>
              </a>
            </div>
          [% END %]
          [% has_bp = has_business_process(service, 'host_') %]
          [% IF has_bp %]
            <div>
              <a href="bp.cgi?action=details&bp=[% has_bp %]">
                <i class="fa-solid fa-sitemap clickable text-xl" title='Show Business Process'></i>
              </a>
            </div>
          [% END %]
        </div>
      </div>
      <div>
        [% PROCESS _extinfo_host_service_details.tt obj=service %]
      </div>
    </div>

    [% IF pnp_url %]
      <div>[% PROCESS _pnp_graph.tt hst=service.host_name svc=service.description %]</div>
    [% ELSIF histou_url %]
      <div>[% PROCESS _histou_graph.tt hst=service.host_name svc=service.description %]</div>
    [% ELSE %]
      [% graph_url = get_graph_url(c, service, 1)%]
      [% IF graph_url %]
        <div>[% PROCESS _third_graph.tt hst=service.host_name svc=service.description %]</div>
      [% END %]
    [% END %]
  </div>

  <div class="hidden min-[1700px]:block order-2 min-[1700px]:order-3">
    [% PROCESS _service_command_box.tt %]
  </div>
</div>

[% IF service.notes_expanded %]
  <div class="card w-full mt-5">
    <div class="head">
      <h3>Notes</h3>
    </div>
    <div class="body">
      [% service.notes_expanded %]
    </div>
  </div>
[% END %]

<div class="card w-full mt-5 overflow-hidden">
  <div class="head justify-between">
    <h3>Service Comments</h3>
    [% IF c.check_cmd_permissions('service', service.description, service.host_name) %]
      <div class="flex gap-1">
        [% UNLESS command_disabled(c, '3') %]
          <div>
            <a class="button js-modal-command-link" href="cmd.cgi?cmd_typ=3&amp;host=[% service.host_name | uri %]&amp;service=[% service.description | uri %]&amp;backend=[% peer_key %]">
              <i class="fa-solid fa-comment mr-1"></i>Add comment
            </a>
          </div>
        [% END %]
        [% IF comments.size > 0 %]
          [% UNLESS command_disabled(c, '21') %]
            <div>
              <a class="button hover-red js-modal-command-link" href="cmd.cgi?cmd_typ=21&amp;host=[% service.host_name | uri %]&amp;service=[% service.description | uri %]&amp;backend=[% peer_key %]">
                <i class="fa-solid fa-trash mr-1"></i>Delete all
              </a>
            </div>
          [% END %]
        [% END %]
      </div>
    [% END %]
  </div>
  <div>
    [% IF comments.size > 0 %]
      [% PROCESS _comments_table.tt comments = comments type='service' names=0 sortprefix='_cmt' %]
    [% ELSE %]
      <div class="flex justify-center textALERT p-2">There are no comments</div>
    [% END %]
  </div>
</div>

<div class="card w-full mt-5 overflow-hidden">
  <div class="head justify-between">
    <h3>Service Downtimes</h3>
    [% IF c.check_cmd_permissions('service', service.description, service.host_name) %]
      <div class="flex gap-1">
        [% UNLESS command_disabled(c, '56') %]
          <a class="button js-modal-command-link" href="cmd.cgi?cmd_typ=56&amp;host=[% service.host_name | uri %]&amp;service=[% service.description | uri %]&amp;backend=[% peer_key %]">Add downtime</a>
          [% IF use_feature_recurring_downtime %]
            <a class="button" href="extinfo.cgi?type=6&amp;recurring=add&amp;target=service&amp;host=[% service.host_name | uri %]&amp;service=[% service.description | uri %]&amp;backend=[% peer_key %]">Add recurring downtime</a>
          [% END %]
        [% END %]
        [% IF downtimes %]
          [% UNLESS command_disabled(c, '5') %]
            <a class="button hover-red js-modal-command-link" href="cmd.cgi?quick_command=5&amp;confirm=no&amp;host=[% service.host_name | uri %]&amp;service=[% service.description | uri %]&amp;backend=[% peer_key %]&amp;referer=[% as_url_arg(short_uri(c, {referer => 'undef'})) %]">
              <i class="fa-solid fa-trash mr-1"></i>Delete all
            </a>
          [% END %]
        [% END %]
        <a class="button" href="showlog.cgi?host=[% service.host_name | uri %]&amp;service=[% service.description | uri %]&amp;backend=[% peer_key %]&amp;pattern=DOWNTIME&amp;start=[% date.now - 86400 * 7 %]&amp;end=[% date.now %]">
          <i class="fa-solid fa-bars mr-1"></i>List recent downtimes
        </a>
      </div>
    [% END %]
  </div>
  <div>
    [% IF downtimes.size > 0 %]
      [% PROCESS _downtimes_table.tt downtimes = downtimes type='service' names=0 sortprefix='_dtm' %]
    [% END %]
    [% IF recurring_downtimes.size > 0 && use_feature_recurring_downtime %]
      <div class="px-2 py-1 border-b[%IF downtimes.size > 0 %] border-t[% END %]"><h4>Recurring Service Downtimes</h4></div>
      [% PROCESS _downtimes_recurring_table.tt downtimes = recurring_downtimes type='service' names=0 %]
    [% END %]
    [% IF downtimes.size == 0 && recurring_downtimes.size == 0 %]
      <div class="flex justify-center p-2 textALERT">There are no downtimes</div>
    [% END %]
  </div>
</div>

[% IF c.check_show_command_line_permissions("service", service.description, service.host_name) %]
  <div class="card mt-5 w-full">
    <div class="head justify-between">
      <h3>Configuration Information</h3>
      <div class="flex gap-x-1">
        [% IF c.config.exists("has_feature_agents") && c.config.has_feature_agents && cust_vars.exists('AGENT_AUTO_CHECK') %]
          <a class="button" href="agents.cgi?action=edit&hostname=[% service.host_name | uri %]&backend=[% peer_key %]"><i class="fa-solid fa-cube small"></i>Agent Configuration</a>
        [% END %]
        [% IF has_bp %]
          <a class="button" href="bp.cgi?action=details&bp=[% has_bp %]&edit=1"><i class="fa-solid fa-sitemap small"></i>Edit Business Process</a>
        [% END %]
        [% IF use_feature_configtool && c.check_user_roles('authorized_for_system_commands') && backends_with_obj_config.$peer_key %]
          <a class="button" href="conf.cgi?edit&amp;host=[% service.host_name | uri %]&amp;service=[% service.description | uri %]&amp;backend=[% peer_key %]"><i class="fa-solid fa-wrench small"></i>Configure service</a>
        [% ELSE %]
          <a class="button" href="config.cgi?type=services&amp;jump2=[% service.host_name | uri %]&amp;jump3=[% service.description | uri %]"><i class="fa-solid fa-eye small"></i>View Configuration</a>
        [% END %]
      </div>
    </div>
    <div>
      [% PROCESS _extinfo_command_line.tt %]
    </div>
  </div>
[% END %]

[% PROCESS user_ext_service_info.tt %]

[% PROCESS _footer.tt %]
