import { Component, ElementRef, EventEmitter, Inject, Input, NgZone, Output, PLATFORM_ID, Renderer2 } from '@angular/core';
import { ControlValueAccessor, Validator, AbstractControl, ValidationErrors } from '@angular/forms';
import { EditorComponent } from '@tinymce/tinymce-angular';
import { HtmlEditorSettings } from './html-editor.model';

@Component({
  selector: 'my-html-editor',
  templateUrl: './html-editor.component.html',
  styleUrl: './html-editor.component.scss'
})
export class HtmlEditorComponent extends EditorComponent implements ControlValueAccessor {
  private _elementRef2: ElementRef;

  writeValue(value: string | null): void {

    super.writeValue(value);
  }

  registerOnChange(fn: (value: string) => void): void {
    super.registerOnChange(fn);
  }
  registerOnTouched(fn: any): void {
    super.registerOnTouched(fn);
  }
  setDisabledState(isDisabled: boolean): void {
    super.setDisabledState(isDisabled);
  }
  constructor(elementRef: ElementRef, ngZone: NgZone, @Inject(PLATFORM_ID) platformId: Object) {
    super(elementRef, ngZone, platformId);
    // this.elementRef is private. Need a duplicate
    this._elementRef2 = elementRef;
  }

  checkDomAttachment(): boolean {
    // check if component has been attached to DOM yet
    return document.body.contains(this._elementRef2.nativeElement);
  }
  ngAfterViewInit() {
    this.init = new HtmlEditorSettings({});
    super.ngAfterViewInit();
  }
  initialise: () => {}

  private InitializeEditor() {
    this.init = new HtmlEditorSettings({});
    //super.initialise();
  }
}
