<% content_for :js do %>
  <%= javascript_include_tag 'views/daily_frequencies/edit_multiple' %>
<% end %>

<div class="widget-body no-padding">
  <table class="table table-bordered table-only-inner-bordered">
    <thead>
      <tr>
        <th><%= DailyFrequency.human_attribute_name :unity %></th>
        <th><%= DailyFrequency.human_attribute_name :classroom %></th>
        <th><%= DailyFrequency.human_attribute_name :discipline %></th>
        <th><%= DailyFrequency.human_attribute_name :frequency_date %></th>
      </tr>
    </thead>
    <tbody style="border-bottom: 1px solid #ccc;">
      <tr>
        <td><%= @daily_frequencies.first.classroom.unity %></td>
        <td><%= @daily_frequencies.first.classroom %></td>
        <td><%= @daily_frequencies.first.discipline || 'Todas' %></td>
        <td><%= l(@daily_frequencies.first.frequency_date) %></td>
      </tr>
    </tbody>
  </table>

  <%= simple_form_for @daily_frequency, url: create_or_update_multiple_daily_frequencies_path, method: :put,
    html: { class: 'smart-form daily_frequency' } do |f| %>

    <div class="frequency-legend">
      <strong>Legenda:</strong>

      <div class="frequency-legend-item">
        <label class="checkbox checkbox-frequency">
          <input type="checkbox" checked disabled>
          <i></i>
          <span class="hide">Presente</span>
        </label>
        Presente
      </div>

      <div class="frequency-legend-item">
        <label class="checkbox checkbox-frequency">
          <input type="checkbox" disabled>
          <i></i>
          <span class="hide">Ausente</span>
        </label>
        Ausente
      </div>

      <div class="frequency-legend-item">
        <label title="" class="checkbox checkbox-frequency justified">
          <input type="checkbox" disabled>
          <i></i>
          <span class="hide">Falta justificada</span>
        </label>
        Falta justificada
      </div>

      <a href="#" class="btn btn-primary frequency-legend-button no-confirm" data-toggle="modal" data-target="#absence-justification-modal">
        Inserir falta justificada por período
      </a>
    </div>

    <table class="table table-bordered table-only-inner-bordered table-striped table-hover">
      <thead>
        <th style="width: 65px;">Sequencial</th>
        <th style="min-width: 200px;"><%= DailyFrequencyStudent.human_attribute_name :student %></th>
        <% if @general_configuration.type_of_teaching == true %>
          <th>Modalidade de ensino</th>
        <%end%>
        <% @daily_frequencies.each do |daily_frequency| %>
            <th>
              <% if daily_frequency.class_number? %>
                <%= daily_frequency.class_number.to_s + 'ª Aula - '%>
              <% end %>
              <%= DailyFrequencyStudent.human_attribute_name(:present) %>
            </th>
        <% end %>
      </thead>
      <tbody>
        <input type="hidden" value="<%= @new_record %>" id="new_record">
        <%= f.hidden_field :unity_id %>
        <%= f.hidden_field :classroom_id %>
        <%= f.hidden_field :frequency_date %>
        <%= f.hidden_field :discipline_id %>
        <%= f.hidden_field :period %>
        <% sequence = 0 %>
          <% @students.each do |student| %>
            <% if student[:sequence] %>
              <%= render 'student_fields', exempted_from_discipline: student[:exempted_from_discipline],
                student: student[:student], sequence: student[:sequence], dependence: student[:dependence],
                active: student[:active], in_active_search: student[:in_active_search],
                absence_justification: student[:absence_justification]
              %>
            <% else %>
              <% sequence += 1 %>
              <%= render 'student_fields', exempted_from_discipline: student[:exempted_from_discipline],
                student: student[:student], sequence: sequence, dependence: student[:dependence],
                active: student[:active], in_active_search: student[:in_active_search],
                absence_justification: student[:absence_justification]
              %>
            <% end %>
          <% end %>
        <% if @dependence_students %>
          <tr>
            <td colspan="<%= 2 + @daily_frequencies.count %>">
              <span class="daily-note-student-legend">
                <%= t('.dependence_students_legend') %>
              </span>
            </td>
          </tr>
      <% end %>
        <% if @any_inactive_student %>
          <tr>
            <td colspan="<%= 2 + @daily_frequencies.count %>">
              <span class="daily-note-student-legend">
                <%= t('.inactive_students_legend') %>
              </span>
            </td>
          </tr>
        <% end %>

        <% if @any_exempted_from_discipline %>
          <tr>
            <td colspan="<%= 2 + @daily_frequencies.count %>">
              <span class="daily-note-student-legend">
                <%= t('.exempted_students_from_discipline_legend') %>
              </span>
            </td>
          </tr>
        <% end %>

        <% if @any_in_active_search %>
          <tr>
            <td colspan="<%= 2 + @daily_frequencies.count %>">
              <span class="daily-note-student-legend">
                <%= t('.in_active_search') %>
              </span>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>

    <footer>
      <div id="flash-messages-bottom">
        <%= bootstrap_flash %>
      </div>

      <div class="pull-left">
        <%= link_to t('.back'), new_daily_frequency_path, class: 'btn btn-default pull-left' %>
        <% daily_frequency_ids = @daily_frequencies.map(&:id).compact %>
        <% if daily_frequency_ids.present? %>
          <%= link_to t('.destroy'), destroy_multiple_daily_frequencies_path(
            daily_frequencies_ids: daily_frequency_ids), method: :delete,
            data: { confirm: t('.confirm') }, class: 'btn new-delete-style pull-left'
          %>
          <%= link_to t('views.form.history'), history_multiple_daily_frequency_path(
            daily_frequencies_ids: daily_frequency_ids), class: 'btn btn-primary pull-left'
          %>
          <div class="btn-group pull-left dropup" style="margin-left: 5px;">
            <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-expanded="true">
              <%= t('.print') %> <span class="caret"></span>
            </button>
            <ul class="dropdown-menu">
              <li>
                <%= link_to(t('.by_month'), attendance_record_report_path(
                  attendance_record_report_form: params_for_print_month(@daily_frequencies)), method: :post,
                  target: '_blank')
                %>
              </li>
              <li>
                <%= link_to(t('.by_step'), attendance_record_report_path(
                  attendance_record_report_form: params_for_print_step(@daily_frequencies)), method: :post,
                  target: '_blank')
                %>
              </li>
            </ul>
          </div>
        <% end %>
      </div>
      <div class="pull-right">
        <%= f.submit t('.save'), class: 'btn new-save-style', data: { disable_with: 'Salvando...' } %>
      </div>
      <div class="pull-right" style="margin-right: 10px;">
        <%= f.input :receive_email_confirmation, as: :boolean, label: false, inline_label: true %>
      </div>
    </footer>
  <% end %>

  <%= render 'absence_justification' %>

</div>
