import { autoinject, useView } from "aurelia-framework";
import { EntityTypeNames, RolesMode } from "./../../../constants/constants";
import { User } from "./../../../model/common-model";
import { UserListBase } from "./user-list-base";
import { ServiceBase } from '../../../data/service-base';

@autoinject
@useView("./../../../vm/security/users/user-list.html")
export class UserList extends UserListBase<User> {

  constructor(rolesMode: RolesMode) {
    super(rolesMode?.length > 0 ? rolesMode : 'single', EntityTypeNames.User);
  }

  public async activate(params) {
    this.languageCategory = 0;
    await super.activate(params);
  }

  public async attached() {
    // Get ressource from route
    let routeRessource: string | null = this.router.currentInstruction.config.settings?.resource;
    if (routeRessource?.length > 0 && routeRessource != EntityTypeNames.User) {
      this.ressourceName = routeRessource;
      let expands = this.service.gridDataSource.expands;
      this.service = new ServiceBase<User>(routeRessource);
      this.service.gridDataSource.expands = expands;
    }
  }
}