import { Component, EventEmitter, Input, Output } from '@angular/core';
import { CurrentLocationConnection, CurrentTravel } from '../../core/api/game-api.models';

@Component({
  selector: 'app-travel-panel',
  templateUrl: './travel-panel.component.html',
  styleUrl: './travel-panel.component.scss',
})
export class TravelPanelComponent {
  @Input() selectedConnection: CurrentLocationConnection | null = null;
  @Input() currentTravel: CurrentTravel | null = null;
  @Input() remainingSeconds: number | null = null;
  @Input() busy = false;
  @Output() readonly travelStart = new EventEmitter<void>();

  protected get travellingTravel(): Extract<CurrentTravel, { status: 'TRAVELLING' }> | null {
    return this.currentTravel?.status === 'TRAVELLING' ? this.currentTravel : null;
  }

  protected formatDuration(seconds: number): string {
    const clampedSeconds = Math.max(0, seconds);
    const hours = Math.floor(clampedSeconds / 3_600);
    const minutes = Math.floor((clampedSeconds % 3_600) / 60);
    const remainder = clampedSeconds % 60;

    return [hours, minutes, remainder].map((value) => value.toString().padStart(2, '0')).join(':');
  }

  protected dangerLabel(danger: CurrentLocationConnection['danger']): string {
    return danger === 'LOW' ? 'Niedrig' : 'Hoch';
  }
}
