- if policy(user).update?
  .editing-form.d-none
    = render partial: 'webui/user/edit_account_form',
             locals: { displayed_user: user, role_titles: role_titles, account_edit_link: account_edit_link }

.basic-info
  .d-flex.justify-content-between.flex-row-reverse
    .d-flex.flex-row-reverse.align-items-center.mb-3
      = render ReportsNoticeComponent.new(reportable: user, user: User.session)
      - if policy(Report.new(reportable: user)).create?
        = link_to('#', id: "js-user-#{user.id}", class: 'ps-2',
              data: { 'bs-toggle': 'modal',
                      'bs-target': '#report-modal',
                      'modal-title': "Report #{user.login}",
                      'reportable-type': user.class.name,
                      'reportable-id': user.id }) do
          %i.fas.fa-regular.fa-flag
          %span.nav-item-name Report
      - if User.session
        - if (blocked_user = BlockedUser.find_by(blocker: User.session, blocked: user))
          - if policy(blocked_user).destroy?
            = button_to(user_block_path(user), method: :delete, class: 'btn btn-link p-0 text-decoration-none ms-2') do
              %i.fas.fa-user-lock
              Unblock
        - else
          - if policy(BlockedUser.new(blocker: User.session, blocked: user)).create?
            = button_to(user_block_path(user), method: :post, class: 'btn btn-link p-0 text-decoration-none ms-2') do
              %i.fas.fa-user-lock
              Block
      - if User.possibly_nobody.admin? && user.state != 'deleted'
        = link_to('#', title: 'Delete user', class: 'ms-2', data: { 'bs-toggle': 'modal', 'bs-target': '#delete-user-modal' }) do
          %i.fas.fa-times-circle.text-danger
          %span.nav-item-name.text-danger Delete
        = render DeleteConfirmationDialogComponent.new(modal_id: 'delete-user-modal', method: :delete,
                                                      options: { modal_title: 'Delete user?', remote: false,
                                                                  confirmation_text: "Please confirm deletion of '#{user.login}'",
                                                                  action: user_path(user) }) do |component|
          - component.with_text_area do
            = label_tag('Adminnote', 'Admin note:', for: 'adminnote')
            = text_area_tag(:adminnote, '', placeholder: 'Please explain the reason for the deletion...', class: 'form-control')
      - if policy(user).update?
        = link_to('#', id: 'toggle-in-place-editing', title: 'Edit Your Account') do
          %i.fas.fa-user-edit
          %span.nav-item-name Edit
    - if policy(user).update?
      .dropdown
        = link_to('#', class: 'dropdown-toggle', id: 'top-navigation-color-theme-dropdown', role: 'button',
                  'data-bs-toggle': 'dropdown', aria: { haspopup: true, expanded: false }) do
          %i.fas.fa-palette{ title: 'Color Theme' }
          %span.nav-item-name Theme
        = form_for(User.session, url: update_color_theme_user_path(User.session), method: :post, id: 'color-theme-form') do |f|
          = f.hidden_field(:login, id: 'user')
          %ul.dropdown-menu.dropdown-menu-start{ 'aria-labelledby': 'top-navigation-color-theme-dropdown' }
            - User.color_themes.keys.each do |color_theme|
              %li.dropdown-item{ class: "#{'active' if User.session.color_theme == color_theme}" }
                %input.nav-link.p-0.text-start{ name: 'color_theme', value: color_theme, type: 'submit', text: color_theme.titleize }
  .row.mb-3
    .col-4.col-sm-2.col-md-12.text-center
      = render(AvatarComponent.new(name: user.name, email: user.email, size: 200))
      - if User.possibly_nobody.admin? && user.state != 'confirmed'
        .border.rounded-2.my-2.px-1
          = user.state.camelcase
    .col-8.col-sm-10.col-md-12
      %h4#home-realname
        = user.realname
      %h5.text-reset#home-login
        = user.login

  - role_titles.each do |title|
    %span.badge.text-bg-secondary
      = title.upcase
  %p= render_as_markdown(user.biography)

  .mt-4
    - if User.session
      - if user.email.present?
        = mail_to(user.email, title: "Send mail to #{user.name}", class: 'd-block') do
          %i.fas.fa-envelope.me-1
          = user.email
      - else
        .d-block
          %i.fas.fa-envelope.me-1
          %em.small No email address

  - if user != User.possibly_nobody && Flipper.enabled?(:content_moderation, User.possibly_nobody)
    = render partial: 'webui/shared/report_modal'
    - if User.possibly_nobody.admin? || User.possibly_nobody.moderator?
      = form_with(url: censor_user_path(user), method: :put, remote: true) do |_form|
        .form-check.form-switch.mt-3
          = hidden_field_tag("user[censored]", !user.censored, id: nil)
          = check_box_tag("user[censored]", !user.censored, user.censored,
                          class: 'form-check-input', onChange: 'this.form.submit()')
          = label_tag("user[censored]", 'Comment Block', class: 'form-check-label')

:javascript
  $('#toggle-in-place-editing, #cancel-in-place-editing').on('click', function () {
    $('.in-place-editing .basic-info').toggleClass('d-none');
    $('.in-place-editing .editing-form').toggleClass('d-none');
    return false;
  });
