- @pagetitle = 'Request Role Addition'

.row
  .col
    .card
      - if @package
        = render partial: 'webui/package/tabs', locals: { project: @project, package: @package }
      - else
        = render partial: 'webui/project/tabs', locals: { project: @project }
      .card-body
        .row
          .col-12
            %h3= @pagetitle
          .col-12
            %p
              -# FIXME: get rid of the helper project_or_package_link
              Do you want to request a Role Addition to
              = project_or_package_link(project: @project.name, package: @package.try(:name))
              ?
          .col-12.col-md-9.col-lg-6
            - form_path = @package ? project_package_role_additions_path(@project, @package) : project_role_additions_path(@project)
            = form_for(@bs_request, url: form_path) do |f|
              = f.fields_for(:bs_request_actions) do |bs_request_actions|
                = bs_request_actions.hidden_field(:target_project)
                = bs_request_actions.hidden_field(:type)
                .mb-3
                  = bs_request_actions.label(:role, 'Role:', class: 'w-100 mb-2')
                  .form-check.custom-control-inline
                    = bs_request_actions.radio_button(:role, 'maintainer', class: 'form-check-input')
                    = bs_request_actions.label(:role, 'Maintainer', value: 'maintainer', class: 'form-check-label')
                  .form-check.custom-control-inline
                    = bs_request_actions.radio_button(:role, 'bugowner', class: 'form-check-input')
                    = bs_request_actions.label(:role, 'Bugowner', value: 'bugowner', class: 'form-check-label')
                .mb-3
                  = label_tag(:role_type, 'Type:', class: 'w-100 mb-2')
                  .form-check.custom-control-inline
                    = radio_button_tag(:role_type, 'user', true, class: 'form-check-input')
                    = label_tag(:role_type, 'User', for: 'role_type_user', class: 'form-check-label')
                  .form-check.custom-control-inline
                    = radio_button_tag(:role_type, 'group', false, class: 'form-check-input')
                    = label_tag(:role_type, 'Group', for: 'role_type_group', class: 'form-check-label')
                .hideable.user
                  -# Reproduce the naming convention for nested fields since we cannot use the FormBuilder (we replace ][, ] and [ by _)
                  = render partial: 'webui/shared/search_box',
                           locals: { html_id: "#{bs_request_actions.object_name.gsub(/\]\[|\]|\[/, '_')}person_name",
                                     html_name: "#{bs_request_actions.object_name}[person_name]",
                                     label: 'User:', required: true,
                                     data: { source: autocomplete_users_path } }
                .hideable.group.d-none
                  -# Reproduce the naming convention for nested fields since we cannot use the FormBuilder (we replace ][, ] and [ by _)
                  = render partial: 'webui/shared/search_box',
                           locals: { html_id: "#{bs_request_actions.object_name.gsub(/\]\[|\]|\[/, '_')}group_name",
                                     html_name: "#{bs_request_actions.object_name}[group_name]",
                                     label: 'Group:', required: true,
                                     data: { source: autocomplete_groups_path } }
                - if @package
                  .mb-3
                    = bs_request_actions.hidden_field(:target_package)
                    = bs_request_actions.label(:target_project, 'In target project:')
                    = bs_request_actions.text_field(:target_project, disabled: true, class: 'form-control')
              .mb-3
                = f.label(:description, 'Description:')
                = f.text_area(:description, row: 3, class: 'form-control')

              = submit_tag('Request', class: 'btn btn-primary px-4')

- content_for :ready_function do
  requestAddAutocompleteResponsiveUx('[name="role_type"]');
