<%= form_with(url: district_school_analyze_index_path,
                    method: :get,
                    data: {
                    turbo_frame: "results",
                    turbo_action: "advance",
                    controller: "form",
                    action: "input->form#submit"
                    }) do |f| %>
                    <%  params.reject{|key,_| key.start_with?("academic_year")}.each do |key, value|  %>
  <input type="hidden" id="year" name="<%= key  %>" value="<%= value %>">
<% end %>

<h3 class="sub-header-4 mt-5">School Years</h3>
<% available_academic_years.each_with_index do | year, index | %>
  <div class="d-flex justify-content-start align-items-center mt-1" data-controller="analyze">
    <input type="checkbox"
    class="form-check-input"
    id="<%= year.range %>"
    name="academic_year-<%= index  %>"
    value="<%= year.range %>"
    <%= selected_academic_years.include?(year)  ? "checked" : "" %>
    <% empty_dataset = empty_dataset?(measures: measures, school: school, academic_year: year) %>
    <% empty_survey_dataset = empty_survey_dataset?(measures: measures, school: school, academic_year: year)  %>
    <% empty_parent_dataset = empty_parent_dataset?(measures: measures, school: school, academic_year: year)  %>
    <% if graph.slug == 'all-data' %>
      <%= empty_dataset ? "disabled" : "" %>
    <% elsif graph.slug.starts_with?('parents-by') %>
      <%= empty_parent_dataset ? "disabled" : "" %>
    <% elsif graph.slug.starts_with?('students-and-teachers-and-parents') %>
      <%= empty_parent_dataset && empty_survey_dataset ? "disabled" : "" %>
    <% else %>
      <%= empty_survey_dataset ? "disabled" : "" %>
    <% end %>
    >
    <label class="px-3" for="<%= year.range %>"><%= year.range %></label><br>
    <div class="bg-color-blue px-3" style="width:20px;height:20px;background-color:<%= colors[index] %>;"></div>
    <% if graph.slug == 'all-data' && empty_dataset %>
      <i class="fa-solid fa-circle-exclamation px-3"
        data-bs-toggle="popover" data-bs-placement="right"
        data-bs-content="No admin data OR teacher and student survey response rates below <%= ResponseRateCalculator::TEACHER_RATE_THRESHOLD %>% OR no parent responses">
      </i>
    <% elsif graph.slug == 'students-and-teachers-and-parents' &&  (empty_survey_dataset && empty_parent_dataset )%>
      <i class="fa-solid fa-circle-exclamation px-3"
        data-bs-toggle="popover" data-bs-placement="right"
        data-bs-content="Teacher and student survey response rates below <%= ResponseRateCalculator::TEACHER_RATE_THRESHOLD %>% OR no parent responses">
      </i>
    <% elsif graph.slug != 'students-and-teachers-and-parents' && graph.slug.starts_with?('student') && empty_survey_dataset %>
      <i class="fa-solid fa-circle-exclamation px-3"
        data-bs-toggle="popover" data-bs-placement="right"
        data-bs-content="Teacher and student survey response rates below <%= ResponseRateCalculator::TEACHER_RATE_THRESHOLD %>%">
      </i>
      <% elsif graph.slug.starts_with?('parent') && empty_parent_dataset %>
      <i class="fa-solid fa-circle-exclamation px-3"
        data-bs-toggle="popover" data-bs-placement="right"
        data-bs-content="Insufficient parent survey responses">
      </i>
    <% end %>
  </div>
<% end %>
<% end %>
