import {DomSanitizer} from '@angular/platform-browser';
import {PipeTransform, Pipe, Input} from "@angular/core";

@Pipe({ name: 'safeHtml'})
export class SafeHtmlPipe implements PipeTransform  {

    @Input('type') type

    constructor(private sanitized: DomSanitizer) {}
    transform(value, ...args) {

        switch(args[0]) {

            case 'url':
                return this.sanitized.bypassSecurityTrustUrl(value);
            case 'resource':
                return this.sanitized.bypassSecurityTrustResourceUrl(value);
            case 'html':
            default:
                return this.sanitized.bypassSecurityTrustHtml(value);
        }
    }
}