<% settings = Setting.plugin_redmine_ux_toolkit || {} %>
<% modern_ui = ux_toolkit_modern_ui %>
<% setting_groups = modern_ui.const_get(:SETTING_GROUPS) %>
<% setting_labels = modern_ui.const_get(:SETTING_LABELS) %>
<% setting_help = modern_ui.const_get(:SETTING_HELP) %>
<% group_labels = {
  general: :label_ux_toolkit_modern_ui_group_general,
  issue_pages: :label_ux_toolkit_modern_ui_group_issue_pages,
  project_pages: :label_ux_toolkit_modern_ui_group_project_pages,
  system_pages: :label_ux_toolkit_modern_ui_group_system_pages
} %>

<div class="ux-toolkit-settings-section">
  <p>
    <strong><%= l(:label_ux_toolkit_modern_ui) %></strong>
    <em class="info"><%= l(:text_ux_toolkit_modern_ui_help) %></em>
    <em class="info"><%= l(:text_ux_toolkit_modern_ui_responsive_help) %></em>
  </p>

  <p>
    <%= hidden_field_tag 'settings[modern_ui_enabled]', '0', id: nil %>
    <%= check_box_tag 'settings[modern_ui_enabled]',
                      '1',
                      modern_ui.enabled?(settings),
                      id: 'settings_modern_ui_enabled' %>
    <%= label_tag 'settings_modern_ui_enabled',
                  l(:label_ux_toolkit_modern_ui_enabled) %>
  </p>
</div>

<% group_labels.each do |group_key, label_key| %>
  <div class="ux-toolkit-settings-section">
    <p><strong><%= l(label_key) %></strong></p>

    <% setting_groups.fetch(group_key).each do |setting_key| %>
      <p>
        <%= hidden_field_tag "settings[#{setting_key}]", '0', id: nil %>
        <%= check_box_tag "settings[#{setting_key}]",
                          '1',
                          modern_ui.module_enabled?(settings, setting_key),
                          id: "settings_#{setting_key}" %>
        <%= label_tag "settings_#{setting_key}", l(setting_labels.fetch(setting_key)) %>
        <% if setting_help.key?(setting_key) %>
          <em class="info"><%= l(setting_help.fetch(setting_key)) %></em>
        <% end %>
      </p>
    <% end %>

    <% if group_key == :general %>
      <p>
        <%= label_tag 'settings_modern_ui_density',
                      l(:label_ux_toolkit_modern_ui_density) %>
        <%= select_tag 'settings[modern_ui_density]',
                       options_for_select([
                         [l(:label_ux_toolkit_modern_ui_density_comfortable), 'comfortable'],
                         [l(:label_ux_toolkit_modern_ui_density_compact), 'compact']
                       ], settings.fetch('modern_ui_density', 'comfortable').to_s),
                       id: 'settings_modern_ui_density' %>
      </p>

      <p>
        <%= label_tag 'settings_modern_ui_color_preset',
                      l(:label_ux_toolkit_modern_ui_color_preset) %>
        <%= select_tag 'settings[modern_ui_color_preset]',
                       options_for_select([
                         [l(:label_ux_toolkit_modern_ui_color_redmine_modern), 'redmine_modern'],
                         [l(:label_ux_toolkit_modern_ui_color_blue), 'blue'],
                         [l(:label_ux_toolkit_modern_ui_color_neutral), 'neutral'],
                         [l(:label_ux_toolkit_modern_ui_color_dark_header), 'dark_header']
                       ], settings.fetch('modern_ui_color_preset', 'redmine_modern').to_s),
                       id: 'settings_modern_ui_color_preset' %>
      </p>
    <% end %>
  </div>
<% end %>
