import { Pipe, PipeTransform } from '@angular/core';
import { Autolinker, AutolinkerConfig } from 'autolinker';

@Pipe({ name: 'linky' })
export class LinkyPipe implements PipeTransform {
  transform(value: string, options?: AutolinkerConfig): string {
    options = {
      email: false,
      phone: false,
      stripPrefix: false,
      // newWindow: false,
      replaceFn: match => {
        if (match.getType() === 'url') {
          return '<a>' + match.getAnchorHref() + '</a>';
          // return true;
        }
      },
      ...options
    };
    return Autolinker.link(value, options);
  }
}
