<div>

  <section class="heading b-b">
    <div class="row no-gutter">
      <div class="col-md-1 hidden-xs">
        <section class="heading-btn">
          <a ng-click="backPrevLocation($event)"><i class="fas fa-long-arrow-alt-left"></i></a>
        </section>
      </div>
      <div class="col-md-8 b-l b-r">
        <section class="heading-title">
          <h1 class="inline">{{ 'app.shared.user_admin.user' | translate }} {{ user.name }}</h1>
          <span class="label label-danger text-white" ng-show="user.need_completion" translate>{{ 'app.shared.user_admin.incomplete_profile' }}</span>
          <div ng-if="enableUserValidationRequired">
            <user-validation member="user"
             on-error="onError"
             on-success="onValidateMemberSuccess" />
          </div>
        </section>
      </div>

      <div class="col-md-3">
        <section class="heading-actions wrapper">
         <div class="btn btn-lg btn-block btn-default promote-member m-t-xs" ng-click="toggleChangeRoleModal()" ng-show="isAuthorized('admin')">
           <img src="/rank-icon.svg" alt="role icon" /><span class="m-l" translate>{{ 'app.admin.members_edit.change_role' }}</span>
         </div>
          <change-role-modal is-open="isOpenChangeRoleModal" toggle-modal="toggleChangeRoleModal" user="user" on-success="onSuccess" onError="onError" />
        </section>

      </div>

    </div>

  </section>


  <div class="row no-gutter ">
    <div class="col-sm-12 col-md-12 b-r">

      <uib-tabset justified="true" class="m-t">

        <uib-tab heading="{{ 'app.shared.user_admin.user_profile' | translate }}">

          <section class="panel panel-danger m-lg" ng-show="user.need_completion && activeProvider.providable_type !== 'DatabaseProvider'">
            <div class="panel-body m-r" translate>
              {{ 'app.shared.user_admin.warning_incomplete_user_profile_probably_imported_from_sso' }}
            </div>
          </section>

          <section class="panel panel-default bg-light m-lg">
            <div class="panel-body m-r">
              <user-profile-form user="user"
                                 operator="currentUser"
                                 action="'update'"
                                 on-error="onError"
                                 on-success="onUserSuccess"
                                 show-group-input="true"
                                 show-tags-input="true"
                                 show-trainings-input="true" />
            </div>
          </section>

        </uib-tab>

        <uib-tab heading="{{ 'app.admin.members_edit.reservations' | translate }}">
          <reservations-dashboard user="user" current-user="currentUser" on-error="onError" />
        </uib-tab>

        <uib-tab heading="{{ 'app.shared.user_admin.children' | translate }}" ng-if="$root.settings.familyAccount">
          <children-dashboard user="user" operator="currentUser" admin-panel="true" on-success="onSuccess" on-error="onError" />
        </uib-tab>

        <uib-tab heading="{{ 'app.admin.members_edit.supporting_documents' | translate }}" ng-show="hasProofOfIdentityTypes">
          <supporting-documents-validation
            operator="currentUser"
            member="user"
            document-type="User"
            on-error="onError"
            on-success="onSuccess" />
        </uib-tab>

        <uib-tab heading="{{ 'app.admin.members_edit.subscription' | translate }}" ng-if="$root.modules.plans">


            <section class="panel panel-default bg-light m-lg">
              <div class="panel-body m-r">
                <div class="" ng-if="subscription">
                  <h3>{{ subscription.plan | humanReadablePlanName }}</h3>
                  <p>
                    {{ 'app.admin.members_edit.duration' | translate }} {{ subscription.plan.interval | planIntervalFilter: subscription.plan.interval_count }}
                  </p>
                  <p>
                    {{ 'app.admin.members_edit.expires_at' | translate }} {{ subscription.expired_at | amDateFormat: 'L' }}
                  </p>
                  <p>
                    {{ 'app.admin.members_edit.price_' | translate }} {{ subscription.plan.amount | currency}}
                  </p>
                  <div ng-hide="user.id === currentUser.id">
                    <button class="btn btn-default" ng-click="toggleFreeExtendModal()" translate>{{ 'app.admin.members_edit.offer_free_days' }}</button>
                    <button class="btn btn-default" ng-click="toggleRenewModal()" translate>{{ 'app.admin.members_edit.renew_subscription' }}</button>
                    <button class="btn btn-default" ng-click="toggleCancelModal()" translate>{{ 'app.admin.members_edit.cancel_subscription' }}</button>
                    <free-extend-modal is-open="isOpenFreeExtendModal"
                                       ng-if="isOpenFreeExtendModal"
                                       toggle-modal="toggleFreeExtendModal"
                                       subscription="subscription"
                                       customer-id="user.id"
                                       on-error="onError"
                                       on-success="onExtendSuccess">
                    </free-extend-modal>
                    <renew-modal is-open="isOpenRenewModal"
                                 ng-if="isOpenRenewModal"
                                 toggle-modal="toggleRenewModal"
                                 subscription="subscription"
                                 customer="user"
                                 operator="currentUser"
                                 on-error="onError"
                                 on-success="onExtendSuccess">
                    </renew-modal>
                    <cancel-subscription-modal is-open="isOpenCancelModal"
                                               ng-if="isOpenCancelModal"
                                               toggle-modal="toggleCancelModal"
                                               subscription="subscription"
                                               customer="user"
                                               operator="currentUser"
                                               on-error="onError"
                                               on-success="onCancelSuccess">
                    </cancel-subscription-modal>
                  </div>
                  <p class="alert alert-info" ng-show="user.id === currentUser.id" translate>
                    {{ 'app.admin.members_edit.cannot_extend_own_subscription' }}
                  </p>
                </div>


                <div class="" ng-hide="subscription">
                  <p translate>
                    {{ 'app.admin.members_edit.user_has_no_current_subscription' }}
                  </p>
                  <button class="btn btn-default" ng-click="toggleSubscribeModal()" translate>{{ 'app.admin.members_edit.subscribe_to_a_plan' }}</button>
                  <subscribe-modal is-open="isOpenSubscribeModal"
                                   toggle-modal="toggleSubscribeModal"
                                   customer="user"
                                   operator="currentUser"
                                   on-error="onError"
                                   on-success="onSubscribeSuccess">
                  </subscribe-modal>
                </div>

              </div>

            </section>
        </uib-tab>

        <uib-tab heading="{{ 'app.admin.members_edit.trainings' | translate }}" ng-show="$root.modules.trainings">
          <div class="col-md-4">
            <div class="widget panel b-a m-t-lg">
              <div class="panel-heading b-b ">
                <h4 class="text-u-c"><i class="fa fa-tag m-r-xs"></i> {{ 'app.admin.members_edit.next_trainings' | translate }}</h4>
              </div>
              <div class="widget-content bg-light wrapper r-b">
                <ul class="list-unstyled" ng-if="user.training_reservations.length > 0">
                  <li class="m-b" ng-repeat="r in user.training_reservations | trainingReservationsFilter:'future'" data-label="{{ 'app.admin.event_reservations.canceled' | translate}}" ng-class="{'reservation-canceled':r.canceled_at}">
                    <span class="font-sbold">{{r.reservable.name}}</span> - <span class="label label-warning wrapper-sm">{{ r.start_at | amDateFormat:'LLL' }} - {{ r.end_at | amDateFormat:'LT' }}</span>
                  </li>
                </ul>
                <div ng-if="user.training_reservations.length == 0" translate>{{ 'app.admin.members_edit.no_trainings' }}</div>
              </div>
            </div>
          </div>
          <div class="col-md-4">
            <div class="widget panel b-a m-t-lg">
              <div class="panel-heading b-b">
                <h4 class="text-u-c"><i class="fa fa-tag m-r-xs"></i> {{ 'app.admin.members_edit.passed_trainings' | translate }}</h4>
              </div>
              <div class="widget-content bg-light wrapper r-b">
                <ul class="list-unstyled" ng-if="user.training_reservations.length > 0">
                  <li class="m-b" ng-repeat="r in user.training_reservations | trainingReservationsFilter:'passed'">
                    <span class="font-sbold">{{r.reservable.name}}</span> - <span class="label label-info text-white wrapper-sm">{{ r.start_at | amDateFormat:'LLL' }} - {{ r.end_at | amDateFormat:'LT' }}</span>
                    <!-- TODO  actions validate or refuse the passed training -->
<!--                     <div class="btn-group">
                      <button type="button" class="btn btn-success btn-sm">Validate</button>
                      <button type="button" class="btn btn-warning btn-sm">Refuse</button>
                    </div> -->
                  </li>
                </ul>
                <div ng-if="user.training_reservations.length == 0" translate>{{ 'app.admin.members_edit.no_trainings' }}</div>
              </div>
            </div>
          </div>
          <div class="col-md-4">
            <div class="widget panel b-a m-t-lg">
              <div class="panel-heading b-b">
                <h4 class="text-u-c"><i class="fa fa-tag m-r-xs"></i> {{ 'app.admin.members_edit.validated_trainings' | translate }}</h4>
              </div>
              <div class="widget-content bg-light wrapper r-b">
                <ul class="list-unstyled" ng-if="user.trainings.length > 0">
                  <li class="m-b" ng-repeat="t in user.trainings">
                    <span class="font-sbold">{{t.name}}</span>
                  </li>
                </ul>
                <div ng-if="user.trainings.length == 0" translate>{{ 'app.admin.members_edit.no_trainings' }}</div>
              </div>
            </div>
          </div>
        </uib-tab>

        <uib-tab heading="{{ 'app.admin.members_edit.events' | translate }}">
          <div class="col-md-6">
            <div class="widget panel b-a m m-t-lg">
              <div class="panel-heading b-b">
                <h4 class="text-u-c"><i class="fa fa-tag m-r-xs"></i> {{ 'app.admin.members_edit.next_events' | translate }}</h4>
              </div>
              <div class="widget-content bg-light wrapper r-b">
                <div class="list-unstyled" ng-if="user.events_reservations.length > 0">
                  <div ng-repeat="r in user.events_reservations | eventsReservationsFilter:'future'" class="m-b">
                    <event-reservation-item reservation="r"></event-reservation-item>
                  </div>
                </div>
                <div ng-if="(user.events_reservations | eventsReservationsFilter:'future').length == 0" translate>{{ 'app.admin.members_edit.no_upcoming_events' }}</div>
              </div>
            </div>
          </div>
          <div class="col-md-6">
            <div class="widget panel b-a m m-t-lg">
              <div class="panel-heading b-b">
                <h4 class="text-u-c"><i class="fa fa-tag m-r-xs"></i> {{ 'app.admin.members_edit.passed_events' | translate }}</h4>
              </div>
              <div class="widget-content bg-light auto wrapper r-b">
                <div class="list-unstyled" ng-if="user.events_reservations.length > 0">
                  <div ng-repeat="r in user.events_reservations | eventsReservationsFilter:'passed'" class="m-b">
                    <event-reservation-item reservation="r"></event-reservation-item>
                  </div>
                </div>
                <div ng-if="(user.events_reservations | eventsReservationsFilter:'passed').length == 0" translate>{{ 'app.admin.members_edit.no_passed_events' }}</div>
              </div>
            </div>
          </div>
        </uib-tab>

        <uib-tab heading="{{ 'app.admin.members_edit.invoices' | translate }}" ng-show="$root.modules.invoicing">
          <div class="col-md-12 m m-t-lg">


            <table class="table" ng-if="user.invoices.length > 0">
              <thead>
              <tr>
                <th style="width:25%" translate>{{ 'app.admin.members_edit.invoice_num' }}</th>
                <th style="width:25%" translate>{{ 'app.admin.members_edit.date' }}</th>
                <th style="width:25%" translate>{{ 'app.admin.members_edit.price' }}</th>
                <th style="width:25%"></th>
              </tr>
              </thead>
              <tbody>
              <tr ng-repeat="invoice in user.invoices">
                <td>{{ invoice.reference }}</td>
                <td ng-if="!invoice.is_avoir">{{ invoice.date | amDateFormat:'L LTS' }}</td>
                <td ng-if="invoice.is_avoir">{{ invoice.date | amDateFormat:'L' }}</td>
                <td>{{ invoice.total | currency }}</td>
                <td>
                  <div class="buttons">
                    <a class="btn btn-default" ng-href="api/invoices/{{invoice.id}}/download" target="_blank" ng-if="!invoice.is_avoir">
                      <i class="fa fa-file-pdf-o"></i> {{ 'app.admin.members_edit.download_the_invoice' | translate }}
                    </a>
                    <a class="btn btn-default" ng-href="api/invoices/{{invoice.id}}/download" target="_blank" ng-if="invoice.is_avoir">
                      <i class="fa fa-file-pdf-o"></i> {{ 'app.admin.members_edit.download_the_refund_invoice' | translate }}
                    </a>
                  </div>
                </td>
              </tr>
              </tbody>
            </table>
            <p ng-if="user.invoices.length == 0" translate>{{ 'app.admin.members_edit.no_invoices_for_now' }}</p>

          </div>
        </uib-tab>

        <uib-tab heading="{{ 'app.admin.members_edit.wallet' | translate }}" ng-show="$root.modules.wallet">
          <div class="col-md-12 m m-t-lg">
            <ng-include src="'/wallet/show.html'"></ng-include>

            <div class="clearfix"></div>
            <div class="col-sm-4 text-center" ng-hide="user.id === currentUser.id">
              <button type="button" class="btn btn-warning m-t m-b" ng-click="createWalletCreditModal(user, wallet)" translate>{{ 'app.admin.members_edit.to_credit' }}</button>
            </div>
            <p class="col-sm-4 alert alert-info" ng-show="user.id === currentUser.id" translate>
              {{ 'app.admin.members_edit.cannot_credit_own_wallet' }}
            </p>

          </div>

          <div class="col-md-12 m m-t-lg">
            <ng-include src="'/wallet/transactions.html'"></ng-include>
          </div>
        </uib-tab>
      </uib-tabset>

    </div>
  </div>
</div>
