elixir:
  route = fn p -> ~p"/commissions?#{p}" end
  pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @commissions, route: route, conn: @conn, params: [commission: @conn.params["commission"]]

.block
  .block__header.page__header
    span.page__title Open Commissions
    .page__pagination = pagination
    .page__info
      = cond do
        - not is_nil(@conn.assigns.current_user) and not is_nil(@conn.assigns.current_user.commission) ->
          = link "View my listing", to: ~p"/profiles/#{@conn.assigns.current_user}/commission"

        - not is_nil(@conn.assigns.current_user) ->
          = link "Create my listing", to: ~p"/profiles/#{@conn.assigns.current_user}/commission/new"

        - true ->

  .block__content
    = cond do
      - Enum.any?(@commissions) ->
        = for c <- @commissions do
          .block.commission
            .block__content.flex.flex--no-wrap
              .flex__fixed.spacing--right
                = render PhilomenaWeb.UserAttributionView, "_user_avatar.html", object: c, conn: @conn

              .flex__grow.commission__listing_body
                span.commission__listing_artist
                  = render PhilomenaWeb.UserAttributionView, "_user.html", object: c, badges: true, conn: @conn

                .commission__listing__body_text
                  - {min, max} = Enum.min_max_by(c.items, &Decimal.to_float(&1.base_price))

                  p
                    strong> Price Range:
                    | $
                    => Decimal.round(min.base_price, 2) |> Decimal.to_string()
                    | - $
                    => Decimal.round(max.base_price, 2) |> Decimal.to_string()
                    ' USD

                  p
                    strong> Categories:
                    = Enum.join(c.categories, ", ")

                  p
                    strong> Offers:
                    = Enum.map(c.items, & &1.item_type) |> Enum.join(", ")

                  p
                    strong> Example Artwork:

                    br

                    = for item <- Enum.take_random(c.items, 5), not is_nil(item.example_image) do
                      = render PhilomenaWeb.ImageView, "_image_container.html", image: item.example_image, size: :thumb_small, conn: @conn

                  p
                    strong
                      = link "More information", to: ~p"/profiles/#{c.user}/commission"

      - true ->
        p We couldn't find any commission listings to display. Sorry!
