<% content_for :js do %>
  <%= javascript_include_tag 'views/avaliations/form' %>
<% end %>
<%= simple_form_for @avaliation, html: { class: "smart-form" } do |f| %>
  <%= f.error_notification %>

  <% if @avaliation.errors.any? %>
    <div class="alert alert-danger fade in">
      <i class="fa-fw fa fa-times"></i>
      <% @avaliation.errors.full_messages.each do |message| %>
        <%= message %><br/>
      <% end %>
    </div>
  <% end %>

  <fieldset>
      <div class="row">
        <div class="col col-sm-4">
          <%= f.association :test_setting, as: :select2, elements: @test_settings, hide_empty_element: true,
              input_html: {
                data: { hide_empty_element: true }, value: @test_settings.first.id
              }
          %>
        </div>
      </div>

    <div class="row">
      <div class="col col-sm-4">
        <%= f.input :unity, as: :select2_unity, user: current_user %>
      </div>

      <div class="col col-sm-4">
        <% if current_user.current_role_is_admin_or_employee? %>
          <%= f.association :classroom, as: :select2_classroom, user: current_user, record: f.object %>
        <% else %>
          <%= f.association :classroom, as: :select2, elements: @classrooms,
                            user: current_user, record: f.object, readonly: action_name.eql?('edit') %>
        <% end %>
      </div>

      <div class="col col-sm-4">
        <% if current_user.current_role_is_admin_or_employee? %>
          <%= f.association :discipline, as: :select2_discipline, user: current_user, record: f.object,
                            classroom_id: @avaliation.classroom_id %>
        <% else %>
          <%= f.association :discipline, as: :select2, elements: @disciplines, user: current_user, record: f.object,
                             classroom_id: @avaliation.classroom_id, readonly: action_name.eql?('edit')%>
        <% end %>
      </div>
    </div>

    <div class="row">
      <div class="col col-sm-4">
        <%= f.input :test_date, as: :date, input_html: { value: f.object.localized.test_date } %>
      </div>

      <div class="col col-sm-4">
        <%= f.input :description, required: true %>
      </div>

      <div class="col col-sm-4">
        <%= f.association :test_setting_test, as: :select2, elements: [] %>
      </div>

      <div class="col col-sm-4">
        <%= f.input :weight, required: true, label_html: show_avaliation_weight,
            input_html: show_avaliation_weight.merge({
               data: { inputmask: "'digits': #{@avaliation.test_setting&.number_of_decimal_places || 0}" }
            })
        %>
      </div>
    </div>

    <div class="row">
      <div class="col col-sm-4">
        <%= f.association :grades, as: :select2, elements: @grades, multiple: true, required: true,
                          input_html: {
                            value: f.object.grade_ids.join(',').presence || @grades.map{ |g| g.id }.sort.join(','),
                            data: { without_json_parser: true }
                          }%>
      </div>
    </div>

    <div class="row">
      <div class="col col-sm-12">
        <%= f.input :observations %>
      </div>
    </div>
  </fieldset>

  <footer>
    <%= link_to(t('views.form.back'), avaliations_path, class: 'btn btn-default') %>

    <%= link_to(t('views.form.history'), history_avaliation_path(@avaliation), class: 'btn btn-info') if @avaliation.persisted? %>

    <%= f.submit(t('views.form.save'), class: 'btn btn-primary', data: { disable_with: 'Salvando...'}) %>
    <%= f.submit(t('.save_and_edit_daily_notes'), class: 'btn btn-primary', data: { disable_with: 'Salvando...'}) %>
  </footer>
<% end %>
