= form_for(@user) do |f|
  = render('shared/form_errors', object: @user)
  .mb-3
    = f.label(:consumer_id, class: 'form-label')
    = f.collection_select(:consumer_id, Consumer.all.sort_by(&:name), :id, :name, {}, class: 'form-control')
  .mb-3
    = f.label(:email, class: 'form-label')
    = f.email_field(:email, class: 'form-control', required: true)
  .mb-3
    = f.label(:name, class: 'form-label')
    = f.text_field(:name, class: 'form-control', required: true)
  .form-check
    label.form-check-label
      = f.check_box(:platform_admin, class: 'form-check-input')
      = f.label(:platform_admin, t('activerecord.attributes.internal_user.platform_admin'), class: 'form-label')

  h2.mt-4 = t('internal_users.form.study_groups')
  ul.list-unstyled.card-group
    li.card
      .card-header role="tab" id="heading"
        a.file-heading data-bs-toggle="collapse" href="#study-group-collapse"
          div.clearfix role="button"
            span = t('internal_users.form.click_to_collapse')
      .card-collapse.collapse id="study-group-collapse" role="tabpanel"
        .table-responsive
          table.table.overflow-hidden#study-groups-table
            thead
              tr
                th = t('activerecord.attributes.study_group.selection')
                th = t('activerecord.attributes.study_group.name')
                th = t('activerecord.attributes.study_group_membership.role')
              = collection_check_boxes :user, :study_group_ids, @study_group_memberships, :study_group_id, :id, {namespace: :internal_user} do |b|
                tr
                  td = b.check_box class: 'form-check-input', name: "internal_user[study_group_ids][]"
                  td = b.object.study_group.name
                  td = select "study_group_membership_roles[#{b.object.study_group.id}]", :role, StudyGroupMembership::ROLES.map { |role| [t("activerecord.attributes.study_group_membership.role_type.#{role}"), role] }, {selected: b.object.persisted? ? b.object.role : nil, include_blank: true}, class: 'form-control form-control-sm'

  .actions = render('shared/submit_button', f: f, object: @user)
