<% content_for :title, t('.global_settings') %>

<section class="viewblock">
  <header class="viewblock-header">
    <div class="viewblock-header_right">
      <div class="button-padding">
        <%= link_to t('.check_configuration'), {action: :config_check}, {class: "btn"} %>
        <% if webserver_supports_restart? %>
          <%= link_to t('.restart_webserver'), {action: :initiate_restart}, {method: :post, class: "btn"}%>
        <% end %>
      </div>
    </div>
    <div class="default-padding">
      <h1>
        <%= t('.edit_settings') %>
      </h1>
    </div>

  </header>

  <div class="viewblock-cont">

    <div class="subnav clearfix">
      <%= generate_tabs @concerto_configs %>

    </div>

    <%= form_tag concerto_config_path, method: :put do %>

      <fieldset class="global-prefs">

        <div class="tab-content">
          <% last_category = "" %>
          <% @concerto_configs.each_with_index do |c, i| %>
            <% if c.category != last_category %>
              <%= "</div>".html_safe if i > 0 %>
              <div class="tab-pane <%= 'active' if i == 0 %>" id="tab<%= c.id %>">
                <% last_category = c.category %>
            <% end %>

            <div class="clearfix">
              <% if c.value_type == "string" %>
                <% input_size = "input-large" %>
                <%= label_tooltip "concerto_config", c.key.to_sym, t("activerecord.attributes.concerto_config.#{c.key.to_sym}"), tip: c.description %>
                <div class="input">
                  <%= text_field_tag "concerto_config[#{c.key}]", ConcertoConfig[c.key.to_sym], class: input_size, placeholder: c.value_default %>
                </div>
              <% elsif c.value_type == "select" %>
                <% input_size = "input-large" %>
                <%= label_tooltip "concerto_config", c.key.to_sym, t("activerecord.attributes.concerto_config.#{c.key.to_sym}"), tip: c.description %>
                <div class="input">
                  <% options = "" %>
                  <% options = options_for_select(eval(c.select_values).map,c.value) unless c.select_values.blank? %>
                  <%= select_tag "concerto_config[#{c.key}]", options, class: input_size %>
                </div>
              <% elsif c.value_type == "integer" %>
                <% input_size = "input-small" %>
                <%= label_tooltip "concerto_config", c.key.to_sym, t("activerecord.attributes.concerto_config.#{c.key.to_sym}"), tip: c.description %>
                <div class="input">
                  <%= number_field_tag "concerto_config[#{c.key}]", ConcertoConfig[c.key.to_sym], class: input_size, placeholder: c.value_default %>
                </div>
              <% elsif c.value_type == "timezone" %>
                <%= label_tooltip "concerto_config", c.key.to_sym, t("activerecord.attributes.concerto_config.#{c.key.to_sym}"), tip: c.description %>
                <div class="input">
                  <%= select_tag "concerto_config[#{c.key}]", time_zone_options_for_select(ConcertoConfig[:system_time_zone], ActiveSupport::TimeZone.us_zones) %>
                </div>
              <% elsif c.value_type == "boolean" %>
                <div class="input checkbox">
                  <%= tag 'input', type: 'hidden', name: "concerto_config[#{c.key}]", value: '0' %>
                  <%= check_box 'concerto_config', c.key, {checked: ConcertoConfig[c.key.to_sym]}, true, false %>
                  <%= label_tooltip "concerto_config", c.key.to_sym, t("activerecord.attributes.concerto_config.#{c.key.to_sym}"), tip: c.description %>
                </div>
              <% elsif c.value_type == "time" %>
                <%= label_tooltip "concerto_config", c.key.to_sym, t("activerecord.attributes.concerto_config.#{c.key.to_sym}"), tip: c.description %>
                <div class="input">
                  <%= text_field_tag "concerto_config[#{c.key}]", ConcertoConfig[c.key.to_sym], class: "input-small timefield" %>
                </div>
              <% elsif c.value_type == "text" %>
                <%= label_tooltip "concerto_config", c.key.to_sym, t("activerecord.attributes.concerto_config.#{c.key.to_sym}"), tip: c.description %>
                <div class="input">
                  <%= text_area_tag "concerto_config[#{c.key}]", ConcertoConfig[c.key.to_sym], class: 'fillWidth', placeholder: c.value_default %>
                </div>
              <% end %>
            </div>
          <% end %>
          <%= "</div>".html_safe if @concerto_configs.count > 0 %>
          </div>
      </fieldset>

      <div class="submit_bar actions">
        <%= submit_tag t('.save_settings'), class: "btn btn-primary" %>
      </div>
    <% end %>

  </div>
</section>
