<fieldset>
  <div class="row">
    <div class="col col-sm-3">
      <%= f.input :first_name %>
    </div>

    <div class="col col-sm-3">
      <%= f.input :last_name %>
    </div>

    <div class="col col-sm-4">
      <%= f.input :email %>
    </div>

    <% if current_user.admin? %>
      <div class="col col-sm-2">
        <%= f.input :admin, as: :boolean %>
      </div>
    <% end %>
  </div>

  <div class="row">
    <div class="col col-sm-6">
      <%= f.input :login %>
    </div>

    <div class="col col-sm-2">
      <%= f.input :cpf %>
    </div>

    <div class="col col-sm-4">
      <%= f.input :authorize_email_and_sms %>
    </div>
  </div>

  <div class="row">
    <div class="col col-sm-6">
      <%= f.input :student, as: :autocomplete, url: search_autocomplete_students_path %>
    </div>

    <div class="col col-sm-6">
      <%= f.input :teacher_id, as: :select2, elements: @teachers %>
      <% if f.object.teacher_id.blank? %>
        <div class="alert alert-warning" style="margin-top: 2px; margin-bottom: 0; padding: 6px 12px;">
          <i class="fa fa-info-circle"></i>
          Este campo deve ser preenchido caso o usuário seja um professor.
        </div>
      <% end %>
    </div>
  </div>
  <div class="row">
    <div class="col col-sm-3">
      <%= f.input :status, as: :select2, elements: UserStatus.to_select.to_json %>
    </div>

    <div class="col col-sm-3">
      <%= f.input :expiration_date %>
    </div>

    <div class="col col-sm-3">
      <%= f.input :phone, as: :tel, input_html: { autocomplete: "off" } %>
    </div>

    <% if current_user.can_change?("can_change_user_password") %>
      <div class="col col-sm-3">
        <%= f.input :password, hint: "Preencha apenas se desejar alterar a senha", input_html: { autocomplete: "new-password" } %>
      </div>
    <% end %>
  </div>
</fieldset>

<fieldset>
  <legend>Permissões</legend>

  <table class="table table-striped table-bordered table-condensed records">
    <thead>
      <tr>
        <th><%= UserRole.human_attribute_name :role %></th>
        <th><%= UserRole.human_attribute_name :unity %></th>
        <th></th>
      </tr>
    </thead>

    <tbody id="user-roles">
      <%= f.association :user_roles do |p| %>
        <%= render 'user_role_fields', f: p %>
      <% end %>
    </tbody>
    <tfoot class="links">
      <tr>
        <td colspan="3">
          <%= link_to_add_association 'Adicionar permissão', f, :user_roles,
            class: 'btn btn-success btn-sm',
            :"data-association-insertion-method" => "append",
            :"data-association-insertion-node" => "#user-roles" %>
        </td>
      </tr>
    </tfoot>
  </table>
</fieldset>
