<tr class="nested-fields">
  <td>
    <%= sequence %>
  </td>
  <td>
    <% name_class = frequency_student_name_class(dependence, active, exempted_from_discipline, in_active_search) %>
    <% student_name = frequency_student_name(student, dependence, active, exempted_from_discipline, in_active_search) %>
    <span class="<%= name_class %>"><%= student_name %></span>
  </td>

  <% @daily_frequencies.each_with_index do |daily_frequency, index| %>
    <% class_number = daily_frequency.class_number || 0 %>
    <% daily_frequency_path = "daily_frequency[daily_frequencies]" %>
    <% daily_frequency_student_path = "#{daily_frequency_path}[#{class_number}][students_attributes]" %>

    <input type="hidden" name="<%= daily_frequency_path %>[<%= class_number %>][class_number]"
      value="<%= class_number %>">

    <% unique_id = "#{class_number.to_s.rjust(10, '0')}#{student.id.to_s.rjust(10, '0')}" %>
    <%= simple_fields_for "#{daily_frequency_student_path}[#{unique_id}]",
      daily_frequency_student = daily_frequency.build_or_find_by_student(student.id) do |f| %>

      <% if @general_configuration.type_of_teaching == true && index == 0 %>
          <td>
            <%= f.input :type_of_teaching, as: :select2, elements: TypesOfTeaching.to_select_specific_values(false, @general_configuration.types_of_teaching).to_json,
                label: false, required: false,
                input_html: { value: f.object.type_of_teaching, data: { without_json_parser: true, id: :type_of_teaching } }  %>
          </td>
      <% end %>
      <td>
        <div>
          <% absence_justifications = absence_justification[@daily_frequency.frequency_date] || {} %>
          <% absence_justification_student_id = absence_justifications[0] || absence_justifications[class_number] %>
          <% ignore_student = !active || exempted_from_discipline || in_active_search.present? %>
          <%= f.hidden_field :id, value: daily_frequency_student.id, disabled: ignore_student %>
          <%= f.hidden_field :daily_frequency_id, value: daily_frequency.id, disabled: ignore_student %>
          <%= f.hidden_field :student_id, value: student.id, disabled: ignore_student %>
          <%= f.hidden_field :dependence, value: dependence, disabled: ignore_student %>
          <%= f.hidden_field :active, value: active, disabled: ignore_student %>
          <%= f.hidden_field :absence_justification_student_id, class: 'hidden-justified', value: absence_justification_student_id, disabled: ignore_student %>

          <% if absence_justification_student_id %>
            <label title="Falta Justificada" class="checkbox checkbox-frequency justified">
              <input type="checkbox" disabled><i></i>
              <span class="hide">Falta Justificada</span>
            </label>
          <% else %>
          <label class="checkbox checkbox-frequency <%= ignore_student ? "state-disabled" : "" %>">
            <%= f.check_box :present, disabled: ignore_student, checked: ignore_student || f.object.present, data: { id: 'checkbox-id' } %>
            <i></i>
            <input type="checkbox" class="hide">
            <span class="hide">Lançar frequência</span>
          </label>
          <% end %>

          <% if @general_configuration.type_of_teaching == true && index != 0 && active && in_active_search.blank? %>
            <span class='hidden'>
              <%= f.input :type_of_teaching, as: :select2, elements: TypesOfTeaching.to_select_specific_values(false, @general_configuration.types_of_teaching).to_json,
                          label: false, required: false,
                          input_html: { value: f.object.type_of_teaching, data: { without_json_parser: true, id: 'type_of_teaching_input' } }  %>
            </span>
          <% end %>
        </div>
      </td>
    <% end %>
  <% end %>
</tr>
