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

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

  <%= f.simple_fields_for :recovery_diary_record, @avaliation_recovery_diary_record.recovery_diary_record.localized do |recovery_diary_record| %>

    <%= recovery_diary_record.hidden_field :id %>

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

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

        <div class="col col-sm-4">
          <% if current_user.current_role_is_admin_or_employee? %>
          <%= recovery_diary_record.association :discipline,
              as: :select2_discipline,
              user: current_user,
              record: f.object,
              classroom_id: @avaliation_recovery_diary_record.recovery_diary_record.classroom_id %>
          <% else %>
            <%= recovery_diary_record.association :discipline,
              as: :select2, elements: @disciplines,
              user: current_user,
              record: f.object,
              classroom_id: @avaliation_recovery_diary_record.recovery_diary_record.classroom_id %>
          <% end %>
        </div>
      </div>

      <div class="row">
        <div class="col col-sm-4">
          <%= f.association :avaliation, as: :select2, elements: [], readonly: f.object.persisted? %>
        </div>

        <div class="col col-sm-4">
          <%= recovery_diary_record.input :recorded_at, as: :date %>
        </div>
      </div>
    </fieldset>

    <fieldset>
      <legend><%= t('.students') %></legend>

      <% if recovery_diary_record.object.errors.added? :students, :at_least_one_assigned_student %>
        <div class="alert alert-danger fade in">
          <i class="fa-fw fa fa-times"></i>
          <%= recovery_diary_record.object.errors[:students].first %>
        </div>
      <% end %>

      <table class="table table-striped table-bordered table-condensed records">
        <colgroup>
          <col style="width: 65px;" />
          <col />
          <col />
          <col style="width: 200px;" />
        </colgroup>
        <thead>
          <tr>
            <th>Sequencial</th>
            <th><%= RecoveryDiaryRecordStudent.human_attribute_name :student %></th>
            <th width="20%"><%= t('.note') %></th>
            <th width="20%"><%= t('.avaliation_recovery') %></th>
          </tr>
        </thead>

        <tbody id="recovery-diary-record-students" data-scale="<%= @number_of_decimal_places %>">
          <tr>
            <td class="no_item_found" colspan="4" style="<%= recovery_diary_record.object.students.reject(&:marked_for_destruction?).empty? ? 'display: table-cell;' : 'display: none;' %>" ><%= t('.no_item_found') %></td>
          </tr>

          <% sequence = 0 %>
          <%= recovery_diary_record.fields_for :students, @normal_students do |student| %>
            <% sequence += 1 %>
            <%= render 'student_fields', f: student, sequence: sequence %>
          <% end %>

          <% sequence = 0 %>
          <% if @dependence_students && @dependence_students.any? %>
            <%= recovery_diary_record.fields_for :students, @dependence_students do |student| %>
              <% sequence += 1 %>
              <%= render 'student_fields', f: student, sequence: sequence %>
            <% end %>

            <tr>
              <td colspan="4">
                <span class="daily-note-student-legend">
                  <%= t('.dependence_students_legend') %>
                </span>
              </td>
            </tr>
          <% end %>
          <% if @any_inactive_student %>
            <tr>
              <td colspan="4">
                <span class="daily-note-student-legend">
                  <%= t('.inactive_students_legend') %>
                </span>
              </td>
            </tr>
          <% end %>
          <% if @any_student_exempted_from_discipline %>
            <tr>
              <td colspan="4">
                <span class="conceptual-exam-student-legend">
                  <%= t('.exempted_students_from_discipline_legend') %>
                </span>
              </td>
            </tr>
          <% end %>
          <tr>
            <td colspan="4">
              <span class="daily-note-student-legend">
                <%= t('.dependence_students_legend') %>
              </span>
            </td>
          </tr>
          <tr>
            <td colspan="4">
              <span class="daily-note-student-legend">
                 <%= t('.inactive_students_legend') %>
              </span>
            </td>
          </tr>
          <tr>
            <td colspan="4">
              <span class="daily-note-student-legend">
                 <%= t('.exempted_students_from_discipline_legend') %>
              </span>
            </td>
          </tr>
        </tbody>
      </table>
    </fieldset>
  <% end %>

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

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

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