import { CommonModule } from '@angular/common';
import { Component, inject } from '@angular/core';
import { GameService } from '../../../service/game.service';
import { Ship } from '../../../model/ships/ship.model';
import { TradeInstance } from '../../../model/planet.model';
import { CdkDragHandle } from '@angular/cdk/drag-drop';

@Component({
  selector: 'app-ship-dialog',
  imports: [CommonModule, CdkDragHandle],
  templateUrl: './ship-dialog.component.html',
  styleUrl: './ship-dialog.component.scss'
})
export class ShipDialogComponent {
  public gameService: GameService = inject(GameService);

  get ship(): Ship {
    return this.gameService.showShipInfo!;
  }


  close() {
    this.gameService.showShipInfo = undefined;
  }

  get cargo(): TradeInstance[] {
    return this.ship.cargoSpace.filter(c => c.amount);
  }

  get destination(): string {
    if (this.ship.route) {
      return this.ship.route.nextPlanetName;
    }
    return ''
  }

  onClick(event: MouseEvent) {
    event.stopPropagation();
    console.log(event)
  }

  get activeRoute(): string[] {
    return this.ship.route?.planetNames ?? []
  }

  sell() {
    this.gameService.sellShip(this.ship);
    this.close();
  }
}
