import { Directive, forwardRef } from '@angular/core';
import { NG_VALIDATORS, Validator, AbstractControl } from '@angular/forms';

import { textinput } from './index';

const TEXT_VALIDATOR: any = {
  provide: NG_VALIDATORS,
  useExisting: forwardRef(() => TextValidator),
  multi: true
};

@Directive({
  selector: '[textinput][formControlName],[textinput][formControl],[textinput][ngModel]',
  providers: [TEXT_VALIDATOR]
})
export class TextValidator implements Validator {
  validate(c: AbstractControl): {[key: string]: any} {
    return textinput(c);
  }
}
