<% content_for :js do %>
  <%= javascript_include_tag 'views/custom_rounding_tables/form' %>
<% end %>

<%= simple_form_for @custom_rounding_table, html: { class: 'smart-form custom_rounding_tables' } do |f| %>
  <%= f.error_notification %>

  <fieldset>
    <div class='row'>
      <div class='col col-sm-6'>
        <%= f.input :name, input_html: { maxlength: 255 } %>
      </div>
      <div class='col col-sm-2'>
          <%= f.input :year, input_html: { maxlength: 4 } %>
      </div>
    </div>

    <div class='row'>
      <div class='col col-sm-6'>
        <%= f.association :unities, as: :select2, elements: @unities, multiple: true,
          input_html: { value: f.object.unity_ids.join(','), data: { without_json_parser: true } } %>
      </div>
      <div class='col col-sm-6'>
        <%= f.association :courses, as: :select2, elements: @courses, multiple: true,
          input_html: { value: f.object.course_ids.join(','), data: { without_json_parser: true } } %>
      </div>
    </div>

    <div class='row'>
      <div class='col col-sm-6'>
        <%= f.association :grades, as: :select2, elements: @filtered_grades, multiple: true,
          input_html: { value: f.object.grade_ids.join(','), data: { without_json_parser: true } } %>
      </div>
      <div class='col col-sm-6'>
        <%= f.input :rounded_avaliations, as: :select2, elements: @rounded_avaliations, multiple: true,
          input_html: { value: f.object.rounded_avaliations.join(','), data: { without_json_parser: true } } %>
      </div>
    </div>
  </fieldset>

  <fieldset id="custom_rounding_table_values">
    <% if f.object.errors.messages[:invalid_actions].present? %>
      <div class="alert alert-danger">
        <%= f.object.errors[:invalid_actions].first %>
      </div>
    <% end %>
    <legend><%= CustomRoundingTableValue.model_name.human %></legend>

    <table class="table table-striped table-bordered table-condensed records">
      <thead>
        <tr>
          <th style="width: 20%;"><%= CustomRoundingTableValue.human_attribute_name :label %></th>
          <th style="width: 60%;"><%= CustomRoundingTableValue.human_attribute_name :action %></th>
          <th style="width: 20%;"><%= CustomRoundingTableValue.human_attribute_name :exact_decimal_place %></th>
        </tr>
      </thead>

      <tbody id="units-conversion-items">
        <%= f.simple_fields_for :custom_rounding_table_values, @custom_rounding_table_values do |item| %>
          <%= render 'custom_rounding_table_values_fields', f: item %>
        <% end %>
      </tbody>
    </table>
  </fieldset>

  <footer>
    <%= link_to 'Voltar', custom_rounding_tables_path, class: 'btn btn-default' %>

    <% if @custom_rounding_table.persisted? %>
      <%= link_to 'Histórico', history_custom_rounding_table_path(@custom_rounding_table), class: 'btn btn-info' %>
    <% end %>

    <%= f.button :submit, 'Salvar', class: 'btn btn-primary' %>
  </footer>
<% end %>
