.profile-top
  .profile-top__avatar
    - avatar = render PhilomenaWeb.UserAttributionView, "_user_avatar.html", object: %{user: @user}, class: "avatar--large"
    = if current?(@user, @conn.assigns.current_user) do
      = link avatar, to: ~p"/avatar/edit?#{[profile: true]}", title: "Change avatar"
    - else
      = avatar
  .profile-top__name-and-links
    div
      h1.profile-top__name-header
        = @user.name
        | 's profile
      = render PhilomenaWeb.UserAttributionView, "_user_title.html", object: %{user: @user}, large: true
      br

      = if can?(@conn, :edit_description, @user) do
        = link "Edit Personal Title", to: ~p"/profiles/#{@user}/description/edit"
        br

      span
        ' Member since
        = pretty_time(@user.created_at)

    .profile-top__options
      ul.profile-top__options__column
        li = link("Send message", to: ~p"/conversations/new?#{[recipient: @user.name]}")
        li = link("Our conversations", to: ~p"/conversations?#{[with: @user.id]}")
        li = link("Report this user", to: ~p"/profiles/#{@user}/reports/new")

      ul.profile-top__options__column
        li = link("Uploads", to: ~p"/search?#{[q: "uploader_id:#{@user.id}"]}")
        li = link("Comments", to: ~p"/comments?#{[cq: "user_id:#{@user.id}"]}")
        li = link("Posts", to: ~p"/posts?#{[pq: "user_id:#{@user.id}"]}")
        = if current?(@user, @conn.assigns.current_user) do
          li = link "My reports", to: ~p"/reports"

      ul.profile-top__options__column
        li = link("Favorites", to: ~p"/search?#{[q: "faved_by_id:#{@user.id}"]}")
        li = link("Tag changes", to: ~p"/profiles/#{@user}/tag_changes")
        li = link("Source changes", to: ~p"/profiles/#{@user}/source_changes")

= if can_index_user?(@conn) do
  .js-staff-action
    = render PhilomenaWeb.ProfileView, "_admin_block.html", assigns

= if @forced && (current?(@user, @conn.assigns.current_user) or can_index_user?(@conn)) do
  .block
    i.fa.icon--padded.small.fa-filter>
    strong.comment_deleted> Forced Filter:
    = link @forced.name, to: ~p"/filters/#{@forced}"

= if (current?(@user, @conn.assigns.current_user) or can?(@conn, :index, Philomena.Bans.User)) and Enum.any?(@bans) do
  .block.block--warning
    .block__header
      i.fa.fa-ban
      | Ban History
    .block__content
      = render PhilomenaWeb.BanView, "_bans.html", bans: @bans, conn: @conn

.column-layout
  .column-layout__left
    .block
      .block__header
        i.fa.fa-briefcase
        | Commissions
      = render PhilomenaWeb.ProfileView, "_commission.html", user: @user, commission_information: @commission_information, conn: @conn

    .block
      .block__header.flex
        span
          i.fa.fa-link
          | Artist Links
        = if current?(@user, @conn.assigns.current_user) or manages_links?(@conn, @user) do
          .block__header__buttons
            a.button href=~p"/profiles/#{@user}/artist_links/new"
              i.fa.fa-link>
              | Create

      = for link <- @user.verified_links, should_see_link?(@conn, @user, link) do
        - watchers = if link.tag, do: @watcher_counts[link.tag.id] || 0, else: 0

        .block__content.alternating-color.break-word class=link_block_class(link)
          .center
            = if link.tag do
              .tag_list = render PhilomenaWeb.TagView, "_tag.html", tag: link.tag, conn: @conn
            = link(link.uri, to: link.uri)

            = if current?(@user, @conn.assigns.current_user) or manages_links?(@conn, @user) do
              br
              ' Watched by
              => watchers
              = pluralize("user", "users", watchers)

            = if manages_links?(@conn, @user) do
              br
              => if link.public do
                ' Public
              - else
                ' Hidden
              ' &bull;
              a href=~p"/profiles/#{@user}/artist_links/#{link}/edit"
                ' Edit
              ' &bull;
              a href=~p"/admin/artist_links/#{link}/reject" data-method="post"
                ' Reject
            - else
              => unless link.public do
                br
                ' Hidden
      = if Enum.count(@user.verified_links) == 0 do
        .block__content
          p
            span: i.fa.icon--padded--right.fa-info-circle
            | No artist links associated

    .block
      .block__header.flex
        span
          i.fa.fa-award
          | Badges
        = if manages_awards?(@conn) and not hide_staff_tools?(@conn) do
          .block__header__buttons
            a.button href=~p"/profiles/#{@user}/awards/new"
              i.fa.fa-trophy>
              | Award
      = for award <- award_order(@user.awards) do
        .block__content.flex.flex--centered.flex--center-distributed.alternating-color.no-overflow title=award.label
          .flex__grow.center
            .badge = badge_image(award.badge, alt: award.label, width: "32", height: "32")
            br
            = award_title(award)
          .flex__grow.center
            => pretty_time(award.awarded_on)
            = if manages_awards?(@conn) do
              = user_abbrv(award.awarded_by)

          = if manages_awards?(@conn) do
            .flex__grow.center
              a href=~p"/profiles/#{@user}/awards/#{award}" data-method="delete" data-confirm="Are you really, really sure?"
                ' Remove
              br
              a href=~p"/profiles/#{@user}/awards/#{award}/edit"
                ' Edit
      = if Enum.count(@user.awards) == 0 do
        .block__content
          p 
            span: i.fa.icon--padded--right.fa-info-circle
            | No badge awards received
    .block
      .block__header.flex
        span
          i.fa.fa-question
          | About Me
        = if can?(@conn, :edit_description, @user) do
          .block__header__buttons
            a.button href=~p"/profiles/#{@user}/description/edit"
              i.fa.fa-edit>
              | Edit

      = render PhilomenaWeb.ProfileView, "_about_me.html", user: @user, about_me: @about_me, conn: @conn

    = if can_read_mod_notes?(@conn) and not hide_staff_tools?(@conn) do
      .block.block--warning
        .block__header.flex
          span
            i.fa.fa-sticky-note
            | Mod Notes
          .block__header__buttons
            a.button href=~p"/profiles/#{@user}/details"
              i.fa.fa-plus>
              | Add / Edit
        .block__content
          = if Enum.count(@mod_notes) > 0 do
            table.table
              thead
                tr
                  th Note
                  th Created
              tbody
                = for {body, mod_note} <- @mod_notes do
                  tr
                    td = body
                    td = pretty_time(mod_note.created_at)
          - else
            p 
              span: i.fa.icon--padded--right.fa-info-circle
              | No mod notes
    = if can_index_user?(@conn) do
      .block.block--warning
        .block__header.flex
          span
            i.fa.fa-clipboard
            | Moderation Scratchpad
          .block__header__buttons
            a.button href=~p"/profiles/#{@user}/scratchpad/edit"
              i.fa.fa-edit>
              | Edit
        .block__content.profile-about
          - {_, contents} = @scratchpad
          = if String.trim(contents) != "" do
            = @scratchpad
          - else
            p 
              span: i.fa.icon--padded--right.fa-info-circle
              | No information present

  .column-layout__main
    = render PhilomenaWeb.ProfileView, "_statistics.html", user: @user, statistics: @statistics, conn: @conn
    = render PhilomenaWeb.ProfileView, "_recent_images.html", title: "Recent Artwork", images: @recent_artwork, view_all_path: ~p"/search?#{[q: tag_disjunction(@tags)]}", conn: @conn
    = render PhilomenaWeb.ProfileView, "_recent_images.html", title: "Recent Uploads", images: @recent_uploads, view_all_path: ~p"/search?#{[q: "uploader_id:#{@user.id}"]}", conn: @conn
    = render PhilomenaWeb.ProfileView, "_recent_images.html", title: "Recent Favorites", images: @recent_faves, view_all_path: ~p"/search?#{[q: "faved_by_id:#{@user.id}"]}", conn: @conn
    = render PhilomenaWeb.ProfileView, "_recent_galleries.html", galleries: @recent_galleries, user: @user, conn: @conn
    = render PhilomenaWeb.ProfileView, "_recent_comments.html", comments: @recent_comments, user: @user, conn: @conn
    = render PhilomenaWeb.ProfileView, "_recent_posts.html", posts: @recent_posts, user: @user, conn: @conn
