import {Component, Input, OnDestroy, OnInit} from '@angular/core';
import {ImageWidget} from "../models/ImageWidget";
import {DomSanitizer} from "@angular/platform-browser";

@Component({
  selector: 'image-widget',
  templateUrl: './image-widget.component.html',
  styleUrls: ['./image-widget.component.css']
})
export class ImageWidgetComponent implements OnInit, OnDestroy {
  @Input() widget?: ImageWidget;

  // IMPORTANT: Avoid url untrusted error
  get src(): any {
    return this.widget && this.widget.src ? this.domSanitizer.bypassSecurityTrustUrl(this.widget?.src) : null;
  }

  constructor(
      private domSanitizer: DomSanitizer
  ) { }

  ngOnInit(): void {
  }

  ngOnDestroy(): void {
  }
}
