<% overview_items = RedmineUxToolkit::Services::SettingsOverview.items %>
<% operational_entries = RedmineUxToolkit::Services::OperationalStatus.entries %>

<div class="ux-toolkit-settings-overview" data-ux-toolkit-settings-overview>
  <div class="ux-toolkit-settings-overview-search">
    <%= label_tag 'ux_toolkit_settings_search', l(:label_ux_toolkit_search_settings) %>
    <%= tag.input type: 'search',
                  id: 'ux_toolkit_settings_search',
                  placeholder: l(:text_ux_toolkit_search_settings_placeholder),
                  autocomplete: 'off',
                  data: {ux_toolkit_settings_search: '1'} %>
  </div>

  <div class="ux-toolkit-settings-feature-list" data-ux-toolkit-settings-feature-list>
    <% overview_items.each do |item| %>
      <div class="ux-toolkit-settings-feature" data-settings-search-text="<%= h([l(item.label_key), item.keywords].join(' ').downcase) %>">
        <%= link_to l(item.label_key),
                    plugin_settings_path('redmine_ux_toolkit', tab: item.tab),
                    class: 'ux-toolkit-settings-feature-name' %>
        <span class="ux-toolkit-status ux-toolkit-status-<%= item.status %>">
          <%= l("label_ux_toolkit_status_#{item.status}".to_sym) %>
        </span>
      </div>
    <% end %>
  </div>
  <p class="nodata ux-toolkit-settings-search-empty" hidden><%= l(:text_ux_toolkit_no_matching_settings) %></p>
</div>

<div class="ux-toolkit-settings-section ux-toolkit-operational-overview">
  <p><strong><%= l(:label_ux_toolkit_operational_status) %></strong></p>
  <div class="ux-toolkit-operational-grid">
    <% operational_entries.each do |entry| %>
      <div class="ux-toolkit-operational-item">
        <div class="ux-toolkit-operational-heading">
          <%= link_to l(entry.label_key), plugin_settings_path('redmine_ux_toolkit', tab: entry.tab) %>
          <span class="ux-toolkit-status ux-toolkit-status-<%= entry.status %>"><%= l("label_ux_toolkit_status_#{entry.status}".to_sym) %></span>
        </div>
        <% if entry.last_at %><span><%= l(:label_ux_toolkit_operational_last_run) %>: <%= format_time(entry.last_at) %></span><% end %>
        <% if entry.next_at %><span><%= l(:label_ux_toolkit_operational_next_run) %>: <%= entry.next_at.is_a?(Date) && !entry.next_at.is_a?(Time) ? format_date(entry.next_at) : format_time(entry.next_at) %></span><% end %>
        <% if entry.message.present? %><span class="ux-toolkit-operational-message" title="<%= h(entry.message) %>"><%= h(entry.message) %></span><% end %>
      </div>
    <% end %>
  </div>
</div>
