<%= simple_form_for @discipline_content_record, html: { class: 'smart-form' } do |f| %>
  <%= f.error_notification %>

  <%= f.simple_fields_for :content_record, @discipline_content_record.content_record.localized do |content_record| %>
    <%= content_record.hidden_field :id %>

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

        <div class="col col-sm-4">
          <%= content_record.association :classroom, as: :select2_classroom, user: current_user,
                                         record: f.object %>
        </div>

        <div class="col col-sm-4">
          <%= f.association :discipline, as: :select2_discipline, user: current_user, record: f.object,
                            classroom_id: @discipline_content_record.content_record.classroom_id %>
        </div>
      </div>

      <div class="row">
        <div class="col col-sm-4">
          <%= content_record.input :record_date, as: :date, readonly: true %>
        </div>

        <% if @allow_class_number %>
          <div class="col col-sm-4">
            <%= f.input :class_number, as: :select2, multiple: true,
                                     elements: number_of_classes_elements(@number_of_classes),
                                     disabled: true %>
          </div>
        <% end %>
      </div>

      <div class="row">
        <div class="col col-sm-12">
          <%= content_record.input :daily_activities_record, as: :text, readonly: true %>
        </div>
      </div>

    </fieldset>
    <fieldset>
      <legend><%= @discipline_content_record.class.human_attribute_name(:contents) %></legend>
      <% if content_record.object.errors[:contents].any? %>
        <div class="alert alert-danger fade in">
          <i class="fa-fw fa fa-times"></i>
          <%= content_record.object.errors[:contents].first %>
        </div>
      <% end %>
      <div class="well" style="max-height: 300px;overflow-y: auto;">
        <ul class="list-group checked-list-box" id="contents-list">
          <% contents.each do |content| %>
            <% content_id_in_plan = content.id.in?(@discipline_content_record.contents.collect(&:id)) %>
            <% classes = content_id_in_plan ? "list-group-item-info active initialized" : "" %>
            <li class="list-group-item manual <%= classes %>" style="display: flex;" id="content_record_<%= content.id %>">
              <% if content_id_in_plan %>
                <span class="state-icon fa fa-check"></span>
              <% end %>
              <%= check_box_tag("discipline_content_record[content_record_attributes][content_ids][]",
                                content.id, content_id_in_plan,
                                hidden: true, 'data-content_description': content.to_s ) %>
              <span style="margin-left: 5px;display: block;width: calc(100% - 85px);"><%= content %></span>
            </li>
          <% end %>
        </ul>
      </div>
    </fieldset>

  <% end %>

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

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