import { Component, HostListener, inject } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import {NavMenuComponent} from './components/nav-menu/nav-menu.component'
import { TransferService } from './services/button/transfer.service';
import { UpdateService } from './services/button/update.service';
import { RefreshService } from './services/button/refresh.service';
import { DeletionService } from './services/button/deletion.service';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [RouterOutlet, NavMenuComponent],
  templateUrl: './app.component.html',
  styleUrl: './app.component.scss'
})
export class AppComponent {
  title = 'app';
  protected transferService: TransferService = inject(TransferService)
  protected updateService: UpdateService = inject(UpdateService)
  protected refreshService: RefreshService = inject(RefreshService)
  protected deletionService: DeletionService = inject(DeletionService)

  @HostListener('window:keydown.control.s', ['$event'])
  protected handleCtrlS(event: KeyboardEvent) {
    event.preventDefault();
    this.updateService.executeAllAsync().then(() => this.refreshService.executeAll());
  }

  @HostListener('window:keydown.control.r', ['$event'])
  protected handleCtrlR(event: KeyboardEvent) {
    event.preventDefault();
    this.refreshService.executeAll();
  }

  @HostListener('window:keydown.delete', ['$event'])
  protected handleDelete(event: KeyboardEvent) {
    event.preventDefault();
    this.deletionService.executeAll();
  }

  @HostListener('window:keydown.control.space', ['$event'])
  protected handleCtrlSpace(event: KeyboardEvent) {
    event.preventDefault();
    this.transferService.executeAll();
  }

  @HostListener('window:keydown.control.l', ['$event'])
  protected handleCtrlL(event: KeyboardEvent) {
    event.preventDefault();
    this.updateService.toggleEditability()
  }
}
