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

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

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

      <div class="col col-sm-4">
        <% if @admin_or_teacher %>
          <%= f.input :classroom_id, as: :select2_classroom, user: current_user, record: f.object %>
        <% else %>
          <%= f.input :classroom_id, as: :select2, elements: @classrooms, user: current_user, record: f.object %>
        <% end %>
      </div>

      <div class="col col-sm-4">
        <% if @admin_or_teacher %>
          <%= f.input :discipline_id, as: :select2_discipline, user: current_user, record: f.object,
                classroom_id: @transfer_note.classroom_id %>
        <% else %>
          <%= f.input :discipline_id, as: :select2, elements: @disciplines, user: current_user, record: f.object,
                classroom_id: @transfer_note.classroom_id %>
        <% end %>
      </div>
    </div>

    <div class="row">
      <div class="col col-sm-4">
        <%= f.input :step_id, as: :select2_step, classroom: current_user_classroom,
              readonly: @transfer_note.persisted?, required: true %>
      </div>

      <div class="col col-sm-4">
        <%= f.input :recorded_at, as: :date, readonly: f.object.persisted? %>
      </div>

      <div class="col col-sm-4">
        <%= f.input :student_id, as: :select2, elements: students, readonly: f.object.persisted? %>
      </div>
    </div>
  </fieldset>
  <fieldset>
    <legend>Notas do aluno na turma anterior</legend>
    <table class="table table-bordered table-striped table-condensed table-hover">
      <thead>
        <tr>
          <th>Avaliação</th>
          <th style="width: 20%;">Nota</th>
          <th style="width: 20%;">Recuperação</th>
        </tr>
      </thead>

      <tbody id="old-notes-rows"></tbody>

      <tfoot>
        <tr>
          <td class="no_old_notes_found" colspan="3"><%= t('.no_old_notes_found') %></td>
        </tr>
        <tr>
          <td colspan="3">
            <button type="button" class="btn btn-sm btn-primary pull-right" id="transfer_note_copy_notes">
              <i class="fa fa-files-o"></i> Copiar notas
            </button>
          </td>
        </tr>
      </tfoot>
    </table>
  </fieldset>
  <fieldset>
    <% if f.object.errors[:daily_note_students].any? %>
      <div class="alert alert-danger fade in">
        <i class="fa-fw fa fa-times"></i>
        <%= f.object.errors[:daily_note_students].first %>
      </div>
    <% end %>

    <legend>Notas de aluno na turma atual</legend>
    <table class="table table-bordered table-striped table-condensed table-hover">
      <thead>
        <tr>
          <th>Avaliação</th>
          <th style="width: 30%;">Nota</th>
        </tr>
      </thead>

      <tbody id="current-notes-rows">
        <%= f.simple_fields_for :daily_note_students, @students_ordered do |daily_note_student| %>
          <%= render 'current_notes_rows', f: daily_note_student %>
        <% end %>
      </tbody>

      <tfoot class="no_current_notes_found" style="<%= f.object.daily_note_students.present? ? 'display: none;' : '' %>">
        <td colspan="2"><%= t('.no_current_notes_found') %></td>
      </tfoot>
    </table>
  </fieldset>

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

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

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