<% content_for :js do %>
  <%= javascript_include_tag 'list-contents' %>
<% end %>

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

  <%= f.simple_fields_for :content_record, @knowledge_area_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, elements: unities, readonly: true %>
        </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.input :knowledge_area_ids, as: :select2, elements: @knowledge_areas, multiple: true,
                      input_html: { data: { without_json_parser: true } }, readonly: f.object.persisted? %>
        </div>
      </div>

      <div class="row">
        <div class="col col-sm-4">
          <%= content_record.input :record_date, as: :date, readonly: true %>
        </div>
        <div class="col col-sm-4">
          <% if f.object.decorator.show_experience_fields %>
            <%= f.input :experience_fields, readonly: true %>
          <% end %>
        </div>
      </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><%= @knowledge_area_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| %>
            <li class="list-group-item manual" style="display: flex;" id="content_record_<%= content.id %>">
                <%= check_box_tag("knowledge_area_content_record[content_record_attributes][content_ids][]",
                    content.id, content.id.in?(@knowledge_area_content_record.contents.collect(&:id)),
                    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'), knowledge_area_content_records_path, class: 'btn btn-default' %>

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