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

<div class="widget-body no-padding">
  <%= simple_form_for @descriptive_exam, html: { class: "smart-form" } do |f| %>
    <%= f.error_notification %>

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

        <div class="col col-sm-4">
          <% if current_user.current_role_is_admin_or_employee? %>
            <%= f.input :classroom_id, as: :select2_classroom, user: current_user %>
          <% else %>
            <%= f.input :classroom_id, as: :select2, elements: @classrooms, user: current_user %>
          <% end %>
        </div>
        <% if @opinion_types.present? %>
          <div class="col col-sm-4" data-opinion-type-container>
            <%= f.input :opinion_type,
              as: :select2,
              elements: @opinion_types,
              input_html: { value: (@opinion_types.size == 1 ? @opinion_types.first.id : @opinion_type) } %>
          </div>
        <% end %>
      </div>
      <div class="row">
        <div class="col col-sm-4 hidden" data-descriptive-exam-discipline-container>
          <% if current_user.current_role_is_admin_or_employee? %>
            <%= f.input :discipline_id, as: :select2_discipline, user: current_user,
                  classroom_id: @descriptive_exam.classroom_id %>
          <% else %>
            <%= f.input :discipline_id, as: :select2, elements: @disciplines, user: current_user,
                        classroom_id: @descriptive_exam.classroom_id %>
          <% end %>
        </div>
        <div class="col col-sm-4 hidden" data-descriptive-exam-step-container>
          <%= f.input :step_id, as: :select2_step, classroom: current_user_classroom,
            readonly: @descriptive_exam.persisted?, required: true %>
        </div>
      </div>

    </fieldset>

    <footer>
      <% if current_user.can_change?(:descriptive_exams) %>
        <%= f.submit 'Novo/Editar', class: 'btn btn-success', data: { disable_with: 'Carregando...'} %>
      <% end %>
      <%= link_to 'Visualizar', new_descriptive_exam_path, id: 'view-btn', class: 'btn btn-primary disabled',
                  data: { disable_with: 'Carregando...'} %>
    </footer>
  <% end %>
</div>
