.content-box.flex.full-width.with-form
  solid-router(default-route='admin-circle-list', hidden)
    solid-route(name='admin-circle-list')
    solid-route(name='admin-circle-create')
    solid-route(name='circle-left')

  div.content-box__header.flex.space-between
    h1.without-margin Administration
    button.mobile-sidebar-button.jsMobileSidebarOpenButton.icon-arrow-left-circle MENU

  include ../circle/page-circle-left.pug

  #admin-circle-list.content-box__height(hidden)
    include ../../templates/hubl-user-avatar.pug

    solid-widget(name='hubl-circle-owner')
      template
        solid-display.user-thumb.is-spaced(
          data-src='${await value}'
          fields='account.picture, sup(name), sub(username)'

          class-account.picture='avatar user-thumb__picture'
          class-name='user-thumb__name'
          class-username='user-thumb__username'

          widget-account.picture='hubl-user-avatar'
        )


    div.content-box__info.flex

      div.admin-header.flex

        h3 Cercles

        solid-link(
          class='button text-bold text-uppercase reversed button-primary bordered with-icon icon-plus'
          next='admin-circle-create'
        ) Créer un cercle

      .table-wrapper
        .table

          div.table-header.grey-color
            div.w280 Nom
            div.w280 Administrateurs
            div.w280 Rejoindre

          solid-widget(name='hubl-admin-circle-leave-button')
            template
              solid-delete(
                class='circle-leave button text-bold text-uppercase reversed button-secondary bordered with-icon icon-close'
                data-src="${src}"
                data-label='Quitter'
              )
              hubl-reactivity(data-src=`${endpoints.circles || endpoints.get.circles}` target-src='${src}')
              hubl-reactivity(data-src=`${endpoints.circles || endpoints.get.circles}joinable/` target-src='${src}')
              hubl-reactivity(bind-user nested-field="circles" target-src='${src}')
              if (endpoints.post && endpoints.post.circles) && (endpoints.get && endpoints.get.circles)
                hubl-reactivity(data-src=`${endpoints.post.circles}joinable/` target-src=`${src}`)
                hubl-reactivity(data-src=`${endpoints.post.circles}` target-src=`${src}`)

          solid-display(
            class='table-body'

            bind-user
            nested-field='circles'
            fields='circle.name, circle.owner, leaveButton'
            loader-id='loader-admin-circles'

            class-circle.name='w280 border cell-with-name'
            class-circle.owner='w280 border cell-with-id-card'
            class-leaveButton='w280 border cell-with-buttons'

            action-leaveButton="joinButton"
            widget-leaveButton="hubl-admin-circle-leave-button"
            widget-circle.owner='hubl-circle-owner'

            order-by="circle.name"
          )

          solid-widget(name='hubl-admin-circle-join-button')
            template
              solid-form.circle-join.button.text-bold.text-uppercase.reversed.button-primary.bordered.with-icon.icon-arrow-right-circle.flex(
                data-src='${value}'

                fields='user.username'
                value-user.username='hubl-workaround-493'
                widget-user.username='solid-form-hidden'

                submit-button='Rejoindre'
              )
              hubl-reactivity(data-src=`${endpoints.circles || endpoints.get.circles}` target-src='${value}')
              hubl-reactivity(data-src=`${endpoints.circles || endpoints.get.circles}joinable/` target-src='${value}')
              hubl-reactivity(bind-user nested-field="circles" target-src='${value}')
              if (endpoints.post && endpoints.post.circles) && (endpoints.get && endpoints.get.circles)
                hubl-reactivity(data-src=`${endpoints.post.circles}joinable/` target-src=`${value}`)
                hubl-reactivity(data-src=`${endpoints.post.circles}` target-src=`${value}`)

          solid-display(
            class='table-body'

            data-src=`${endpoints.circles || endpoints.get.circles}joinable/`
            fields='name, owner, members'
            loader-id='loader-admin-circles'

            class-name='w280 border cell-with-name'
            class-owner='w280 border cell-with-id-card'
            widget-owner='hubl-circle-owner'

            class-members='w280 border cell-with-buttons'
            widget-members="hubl-admin-circle-join-button"

            order-by="name"
          )

      div#loader-admin-circles.loader.loader-top
        div
        div
        div
        div

  #admin-circle-create.content-box__height(hidden)
    include page-admin-circles-create.pug
