import { HttpClient } from '@angular/common/http';
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';

@Component({
    selector: 'app-plane-svg',
    templateUrl: './plane-svg.component.html',
    styleUrl: './plane-svg.component.css',
    standalone: false
})
export class PlaneSvgComponent implements OnChanges {
  @Input() plane?: string;
  public svgPlane: any;

  constructor(
    private httpClient: HttpClient,
    private sanitizer: DomSanitizer,
  ) {}

  public ngOnChanges(changes: SimpleChanges): void {
    if(!this.plane) {
      this.svgPlane = '';
      return;
    }

    this.httpClient.get(this.plane, {responseType: 'text'})
    .subscribe(value => {
      this.svgPlane = this.sanitizer.bypassSecurityTrustHtml(value);
    })
  }
}
