<% content_for :js do %>
  <%= javascript_include_tag 'list-contents' %>
  <%= javascript_include_tag 'summernote' %>
  <%= javascript_include_tag 'views/discipline_lesson_plans/form' %>
  <%= javascript_include_tag 'views/layouts/copy-objectives' %>
<% end %>

<%= hidden_field_tag :action_name, action_name %>

<%= simple_form_for @discipline_lesson_plan,
    url: discipline_lesson_plan_form_url(@discipline_lesson_plan, action_name),
    method: lesson_plan_form_method(action_name),
    html: { class: 'smart-form', id: 'discipline_lesson_plan' } do |f| %>
  <%= f.error_notification %>

  <%= f.simple_fields_for :lesson_plan, @discipline_lesson_plan.lesson_plan.localized do |lesson_plan| %>
    <%= lesson_plan.hidden_field :id %>

    <%= render partial: 'lesson_plans/base_errors', locals: { f: lesson_plan } %>

    <fieldset>
    <% if action_name != 'show' %>
      <%= render 'teaching_plans/diciplines_modal', f: lesson_plan %>
      <% if @allows_copy_experience_fields_in_lesson_plans %>
        <%= render 'teaching_plans/experience_fields_modal', f: lesson_plan %>
      <% end %>
    <% end %>
      <div class="row">
        <%= render partial: 'lesson_plans/unity_field', locals: { f: lesson_plan } %>

        <%= render partial: 'lesson_plans/classroom_field', locals: { f: lesson_plan } %>

        <div class="col col-sm-4">
          <% if current_user.current_role_is_admin_or_employee? %>
            <%= f.association :discipline, as: :select2_discipline, user: current_user,
              classroom_id: @discipline_lesson_plan.lesson_plan.classroom_id %>
          <% else %>
            <%= f.association :discipline, as: :select2, elements: @disciplines,
               user: current_user, record: f.object, readonly: ['show', 'edit'].include?(action_name) %>
          <% end %>
        </div>
      </div>

      <div class="row">
        <%= render partial: 'lesson_plans/lesson_plan_date_fields', locals: { f: lesson_plan } %>

        <div class="col col-sm-4">
          <%= f.input :thematic_unit, readonly: action_name == 'show' %>
        </div>
      </div>
    </fieldset>
    <%= render partial: 'lesson_plans/fields', locals: { f: lesson_plan, model: @discipline_lesson_plan, modal_id: '#disciplines-modal' } %>

    <%= render partial: 'lesson_plans/opinion_field', locals: { f: lesson_plan } %>

    <%= render partial: 'lesson_plans/hidden_fields', locals: { f: lesson_plan } %>

    <% if lesson_plan.object.persisted? %>
      <div style="position: absolute; margin-top: 11px; <%= action_name == 'show' ? 'right: 340px;' : 'right: 340px;' %>">
        <%= lesson_plan.input :validated, as: :boolean, label: false, inline_label: true, disabled: current_user.teacher? %>
      </div>
    <% end %>
  <% end %>

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

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

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