<rd-header>
  <rd-header-title title-text="Teams">
    <a data-toggle="tooltip" title="Refresh" ui-sref="portainer.teams" ui-sref-opts="{reload: true}">
      <i class="fa fa-sync" aria-hidden="true"></i>
    </a>
  </rd-header-title>
  <rd-header-content>Teams management</rd-header-content>
</rd-header>

<div class="row" ng-if="isAdmin">
  <div class="col-lg-12 col-md-12 col-xs-12">
    <rd-widget>
      <rd-widget-header icon="fa-plus" title-text="Add a new team"> </rd-widget-header>
      <rd-widget-body>
        <form class="form-horizontal" name="teamCreationForm" ng-submit="addTeam()">
          <!-- name-input -->
          <div class="form-group">
            <label for="team_name" class="col-sm-2 control-label text-left">Name</label>
            <div class="col-sm-10">
              <input
                type="text"
                class="form-control"
                id="team_name"
                name="team_name"
                ng-model="formValues.Name"
                ng-change="checkNameValidity(teamCreationForm)"
                placeholder="e.g. development"
                auto-focus
                required
                data-cy="team-teamNameInput"
              />
            </div>
          </div>
          <div class="form-group" ng-show="teamCreationForm.team_name.$invalid">
            <div class="col-sm-12 small text-warning">
              <div ng-messages="teamCreationForm.team_name.$error">
                <p ng-message="required"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> This field is required.</p>
                <p ng-message="validName"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> This team already exists.</p>
              </div>
            </div>
          </div>
          <!-- !name-input -->
          <!-- team-leaders -->
          <div class="form-group" ng-if="users.length > 0">
            <div class="col-sm-12">
              <label class="control-label text-left">
                Select team leader(s)
                <portainer-tooltip
                  position="bottom"
                  message="You can assign one or more leaders to this team. Team leaders can manage their teams users and resources."
                ></portainer-tooltip>
              </label>
              <span
                isteven-multi-select
                ng-if="users.length > 0"
                input-model="users"
                output-model="formValues.Leaders"
                button-label="Username"
                item-label="Username"
                tick-property="ticked"
                helper-elements="filter"
                search-property="Username"
                translation="{nothingSelected: 'Select one or more team leaders', search: 'Search...'}"
                style="margin-left: 20px;"
                data-cy="team-teamLeaderSelect"
              >
              </span>
            </div>
          </div>
          <!-- !team-leaders -->
          <div class="form-group">
            <div class="col-sm-12">
              <button
                type="button"
                class="btn btn-primary btn-sm"
                ng-disabled="state.actionInProgress || !teamCreationForm.$valid"
                ng-click="addTeam()"
                button-spinner="state.actionInProgress"
                data-cy="team-createTeamButton"
              >
                <span ng-hide="state.actionInProgress"><i class="fa fa-plus" aria-hidden="true"></i> Create team</span>
                <span ng-show="state.actionInProgress">Creating team...</span>
              </button>
            </div>
          </div>
        </form>
      </rd-widget-body>
    </rd-widget>
  </div>
</div>

<div class="row">
  <div class="col-sm-12">
    <teams-datatable title-text="Teams" title-icon="fa-users" dataset="teams" table-key="teams" order-by="Name" remove-action="removeAction"></teams-datatable>
  </div>
</div>
