import { Injectable } from '@angular/core';
import { DomainType, PastoralDomain } from '../entity/PastoralDomain';
import { AuthService } from './auth.service';
import { HeaderService } from './header.service';
import { LoginUserService } from './login-user.service';

@Injectable({
  providedIn: 'root'
})
export class StateService {

  constructor(
    private headerService: HeaderService,
    private authService: AuthService,
    public loginUserService: LoginUserService
  ) { }

  domains: PastoralDomain[] = [];

  public get myCellGroup(): PastoralDomain {
    return this.domains.find(d => d.type == DomainType.CellGroup);
  }

  public get isCellGroupLeader(): boolean {
    return this.myCellGroup && this.myCellGroup.leaderMemberId == this.loginUserService.userAccess.memberId;
  }

  public get isAdministrator(): boolean {
    return !!this.domains.find(d => d.type == DomainType.Administrator);
  }

  public SetPageTitle(title: string) {
    this.headerService.setHeader(title);
  }
}
