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

@Pipe({
  name: 'frameStyle'
})
export class FrameStylePipe implements PipeTransform {

  constructor(private sanitizer: DomSanitizer) {

  }

  transform(value: boolean, values: any): any {
    if (values.length === 0) {
      return '';
    }
    if (values.length === 1) {
      values[1] = [];
    }

    if (values[1].length === 0) {
      values[1][0] = 'text-success';
    }
    if (values[1].length === 1) {
      values[1][1] = 'text-danger';
    }

    let v = '';
    if (value) {
      v = '<span class="' + values[1][0] + '">' + values[0][0] + '</span>';
    } else {
      v = '<span class="' + values[1][1] + '">' + values[0][1] + '</span>';
    }
    return this.sanitizer.bypassSecurityTrustHtml(v);


  }

}
