import { Component, computed, inject } from '@angular/core';
import { Router, RouterLink } from '@angular/router';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatIconModule } from '@angular/material/icon';
import { AuthStore } from '../../../core/auth/auth-store';
import { HelpAccessService } from '../../../core/help/help-access';
import { TeamPermissionsService } from '../../../core/team/team-permissions';
import { TeamStore } from '../../../core/team/team-store';

@Component({
  selector: 'app-more',
  imports: [RouterLink, MatButtonModule, MatCardModule, MatIconModule],
  templateUrl: './more.html',
  styleUrl: './more.scss',
})
export class More {
  private readonly authStore = inject(AuthStore);
  private readonly helpAccess = inject(HelpAccessService);
  private readonly permissions = inject(TeamPermissionsService);
  private readonly router = inject(Router);
  private readonly teamStore = inject(TeamStore);
  protected readonly user = this.authStore.currentUser;
  protected readonly canOpenGuide = this.helpAccess.canOpenGuide;
  protected readonly canManagePermissions = computed(() =>
    this.permissions.canDo(this.teamStore.team(), 'memberManage'),
  );

  protected logout(): void {
    this.authStore.clearSession();
    void this.router.navigateByUrl('/auth/login');
  }
}
