<template>
  <div class="row justify-content-center">
    <div class="col-8">
      <form name="editForm" novalidate @submit.prevent="save()">
        <h2 id="sasiedziApp.userAccount.home.createOrEditLabel" data-cy="UserAccountCreateUpdateHeading">Create or edit a User Account</h2>
        <div>
          <div class="form-group" v-if="userAccount.id">
            <label for="id">ID</label>
            <input type="text" class="form-control" id="id" name="id" v-model="userAccount.id" readonly />
          </div>
          <div class="form-group">
            <label class="form-control-label" for="user-account-name">Name</label>
            <input
              type="text"
              class="form-control"
              name="name"
              id="user-account-name"
              data-cy="name"
              :class="{ valid: !v$.name.$invalid, invalid: v$.name.$invalid }"
              v-model="v$.name.$model"
            />
          </div>
          <div class="form-group">
            <label for="user-account-user">User</label>
            <select
              class="form-control"
              id="user-account-users"
              data-cy="user"
              multiple
              name="user"
              v-if="userAccount.users !== undefined"
              v-model="userAccount.users"
            >
              <option :value="getSelected(userAccount.users, userOption, 'id')" v-for="userOption in users" :key="userOption.id">
                {{ userOption.login }}
              </option>
            </select>
          </div>
        </div>
        <div>
          <button type="button" id="cancel-save" data-cy="entityCreateCancelButton" class="btn btn-secondary" @click="previousState()">
            <font-awesome-icon icon="ban"></font-awesome-icon>&nbsp;<span>Cancel</span>
          </button>
          <button
            type="submit"
            id="save-entity"
            data-cy="entityCreateSaveButton"
            :disabled="v$.$invalid || isSaving"
            class="btn btn-primary"
          >
            <font-awesome-icon icon="save"></font-awesome-icon>&nbsp;<span>Save</span>
          </button>
        </div>
      </form>
    </div>
  </div>
</template>
<script lang="ts" src="./user-account-update.component.ts"></script>
