import { EntityDetailViewModelBase } from "../detail-view-model-base";
import { Country, Locality, Various } from "../../model/common-model";
import { autoinject, computedFrom } from "aurelia-framework";
import { Router } from "aurelia-router";
import { CustomLogger } from "../../modules/custom-logger";
import { EditingModeEnum } from "../editing-mode-enum";
import { ServiceBase } from "../../data/service-base";
import { FilterQueryOp, Predicate } from "breeze-client";
import { EntityTypeNames } from "../../constants/constants";

@autoinject
export class CountryDetail extends EntityDetailViewModelBase<Country>{
  @computedFrom("entity", "isCreationMode")
  public get documentTitle() {
    if (this.isCreationMode) {
      return this.i18n.tr("common:country.addCountry");
    }
    return this.entity.name._translation;
  }
  public ressourceName = "";

  constructor(router: Router, logger: CustomLogger) {
    super(router, logger);
    super.initialize(new ServiceBase<Country>(EntityTypeNames.Country));
  }

  public async activate(params: any): Promise<void> {
    await super.activate(params);
    let id = params.param1;
    if (id == Various.NewId) {
      this.editingMode = EditingModeEnum.Create;
      this.entity = await this.service.createEntity();
    } else {
      this.editingMode = EditingModeEnum.Update;
      this.entity = await this.service.getEntityById(id);
    }
  }
}